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 <noreply@anthropic.com>
This commit is contained in:
39
README.md
Normal file
39
README.md
Normal file
@@ -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.
|
||||
29
SPEC.md
Normal file
29
SPEC.md
Normal file
@@ -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.
|
||||
93
bin/slider
Executable file
93
bin/slider
Executable file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# slider — terminal markdown slideshow
|
||||
# Usage: slider <file.md>
|
||||
|
||||
usage() {
|
||||
echo "Usage: slider <file.md>" >&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
|
||||
56
examples/presentation.md
Normal file
56
examples/presentation.md
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user