From d9e1e26601798fbee396e02cdf687e08140e66d7 Mon Sep 17 00:00:00 2001 From: flo-eberle Date: Sun, 1 Mar 2026 17:33:54 +0100 Subject: [PATCH] Initial implementation of slider Single-file markdown slideshow for the terminal. Parses slides split by `---`, renders each with glow, and navigates with n/p/q or arrow keys. Co-Authored-By: Claude Sonnet 4.6 --- README.md | 39 +++++++++++++++++ SPEC.md | 29 +++++++++++++ bin/slider | 93 ++++++++++++++++++++++++++++++++++++++++ examples/presentation.md | 56 ++++++++++++++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 README.md create mode 100644 SPEC.md create mode 100755 bin/slider create mode 100644 examples/presentation.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..905753d --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# slider + +Terminal markdown slideshow. Write slides in a single `.md` file, split them with `---`, and navigate with keyboard shortcuts. + +## Requirements + +- [glow](https://github.com/charmbracelet/glow) v2+ + +## Usage + +```bash +./bin/slider presentation.md +``` + +## Controls + +| Key | Action | +|-----|--------| +| `n` / right arrow | Next slide | +| `p` / left arrow | Previous slide | +| `q` | Quit | + +## Writing slides + +Separate slides with a `---` on its own line: + +```markdown +# Slide one + +Some content here. + +--- + +# Slide two + +More content. +``` + +See `examples/presentation.md` for a full example. diff --git a/SPEC.md b/SPEC.md new file mode 100644 index 0000000..170045e --- /dev/null +++ b/SPEC.md @@ -0,0 +1,29 @@ +# Terminal Slide Presentation Tool (slider) + +## 🎯 Purpose + +Create a standalone terminal-based slide presentation tool using `glow` as the markdown renderer. This tool will allow users to navigate slides via keyboard shortcuts (`n`, `p`, `q`) +and showcase `glow`'s features like syntax highlighting, tables, and code blocks. + +## ✅ Features + +- Slide navigation (`n`, `p`, `q`) +- Markdown rendering using `glow` +- Support for `glow`-friendly features (code blocks, tables, syntax highlighting) +- Modular structure for future expansion + +## 📁 Project Structure + +- `/SPEC.md`: Project specification and roadmap +- `/examples/`: Test files showcasing `glow` features + +## 🚀 Next Steps + +1. Implement the navigation script +2. Add support for slide timing or auto-advance +3. Integrate with a markdown editor for live preview +4. Add slide transitions or visual effects + +## 📌 Notes + +- This project is a lightweight tool for terminal use. For advanced features, consider using `reveal.js` or `remark` in a browser. diff --git a/bin/slider b/bin/slider new file mode 100755 index 0000000..0ce6418 --- /dev/null +++ b/bin/slider @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -euo pipefail + +# slider — terminal markdown slideshow +# Usage: slider + +usage() { + echo "Usage: slider " >&2 + exit 1 +} + +[[ $# -ne 1 ]] && usage +file="$1" +[[ ! -f "$file" || ! -r "$file" ]] && { echo "Error: cannot read '$file'" >&2; exit 1; } + +# Parse slides split on "---" +slides=() +current="" +while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" == "---" ]]; then + [[ -n "${current// }" ]] && slides+=("$current") + current="" + else + current+="$line"$'\n' + fi +done < "$file" +[[ -n "${current// }" ]] && slides+=("$current") + +total=${#slides[@]} +[[ $total -eq 0 ]] && { echo "No slides found in '$file'" >&2; exit 1; } + +# Temp file for glow rendering; cleaned up on exit +tmpfile=$(mktemp /tmp/slider.XXXXXX.md) +trap 'rm -f "$tmpfile"' EXIT + +idx=0 + +show_slide() { + tput clear + printf " Slide %d/%d [n] next [p] prev [q] quit\n\n" $((idx + 1)) "$total" + printf '%s' "${slides[$idx]}" > "$tmpfile" + glow - < "$tmpfile" +} + +show_slide + +while true; do + read -rsn1 key < /dev/tty + case "$key" in + n) + if (( idx < total - 1 )); then + idx=$(( idx + 1 )) + show_slide + else + tput clear + printf " Slide %d/%d [n] next [p] prev [q] quit\n\n" $((idx + 1)) "$total" + printf '%s' "${slides[$idx]}" > "$tmpfile" + glow - < "$tmpfile" + printf "\n End of presentation — press q to quit\n" + fi + ;; + p) + if (( idx > 0 )); then + idx=$(( idx - 1 )) + show_slide + fi + ;; + $'\x1b') + read -rsn2 -t 0.1 rest < /dev/tty || true + if [[ "$rest" == "[C" ]]; then # right arrow → next + if (( idx < total - 1 )); then + idx=$(( idx + 1 )) + show_slide + else + tput clear + printf " Slide %d/%d [n] next [p] prev [q] quit\n\n" $((idx + 1)) "$total" + printf '%s' "${slides[$idx]}" > "$tmpfile" + glow - < "$tmpfile" + printf "\n End of presentation — press q to quit\n" + fi + elif [[ "$rest" == "[D" ]]; then # left arrow → prev + if (( idx > 0 )); then + idx=$(( idx - 1 )) + show_slide + fi + fi + ;; + q) + tput clear + break + ;; + esac +done diff --git a/examples/presentation.md b/examples/presentation.md new file mode 100644 index 0000000..31cc014 --- /dev/null +++ b/examples/presentation.md @@ -0,0 +1,56 @@ +# Welcome to the Presentation + +## Slide 1: Introduction + +This is a simple slide to demonstrate `glow`'s capabilities. + +### Features Showcase + +- **Code Blocks**: + + ```python + def greet(name): + print(f"Hello, {name}!") + ``` + +- **Tables**: + + | Feature | Description | + |----------------|---------------------| + | Syntax Highlighting | Supports Python, JavaScript, etc. | + | Tables | Easy to read and format | + | Markdown | Full markdown support | + +- **Inline Code**: + `glow` supports inline code like `print("Hello")`. + +--- + +# Slide 2: Advanced Features + +## Code Blocks with Line Numbers + +```bash +#!/bin/bash +echo "This is a bash script." +``` + +## Tables with Markdown + +| Column 1 | Column 2 | +|----------|----------| +| Data 1 | Data 2 | +| Data 3 | Data 4 | + +## Emoji and Formatting + +:smile: This is a smiley! +**Bold text** and *italic text* are supported. + +--- + +# Slide 3: Conclusion + +## Thank You + +This is the final slide. Press `q` to exit.