Skip to content

Commit cfb8bdd

Browse files
chore(demo): use vhs and minimal init to record demos
1 parent ebfea32 commit cfb8bdd

File tree

6 files changed

+181
-92
lines changed

6 files changed

+181
-92
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Plugin to improve viewing Markdown files in Neovim
66

77
| | |
88
| --------- | ------- |
9-
| ![Heading](https://github.com/user-attachments/assets/663a34c5-0438-4688-8204-332065f65835) | ![Table](https://github.com/user-attachments/assets/162986e1-91f0-4e13-a83f-6183d58b0fcb) |
10-
| ![Quote](https://github.com/user-attachments/assets/5343ca45-d5e1-4de0-9065-46499e1ed919) | ![LaTeX](https://github.com/user-attachments/assets/9e8909e4-7256-45fc-b481-4aba8850ebc3) |
11-
| ![Callout](https://github.com/user-attachments/assets/4324ea72-a017-4175-9f9d-363da5e5f6ba) | |
9+
| ![Heading](https://github.com/user-attachments/assets/6d5ca2d3-3263-4ccd-beaf-b5795167d776) | ![Table](https://github.com/user-attachments/assets/7c7e6351-baff-4e72-b668-2e4fac76e276) |
10+
| ![Quote](https://github.com/user-attachments/assets/dba88e99-bff5-4b33-9017-ab55c1058d21) | ![LaTeX](https://github.com/user-attachments/assets/85bac8f1-c7df-4078-9e9c-374de9b08e03) |
11+
| ![Callout](https://github.com/user-attachments/assets/bea7e1b9-d77f-4c3f-abf8-f6262b05fad2) | |
1212

1313
<!-- panvimdoc-ignore-end -->
1414

demo/format.tape

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Output OUTPUT
2+
3+
Set FontSize 14
4+
Set FontFamily "JetBrainsMono Nerd Font"
5+
Set Width WIDTH
6+
Set Height HEIGHT
7+
Set Padding 0
8+
Set Framerate 60
9+
Set TypingSpeed 0.1
10+
11+
# Setup
12+
Hide
13+
Type "nvim -u demo/minit.lua INPUT" Enter
14+
Show
15+
16+
Sleep 2s
17+
18+
WRITE
19+
20+
Type "i" Sleep 1s
21+
Escape Sleep 1s
22+
23+
MOVE
24+
25+
Type "i" Sleep 1s
26+
Escape Sleep 1s
27+
28+
# Close without editing
29+
Type ":q!"
30+
Hide
31+
Enter
32+
Sleep 100ms

demo/minit.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- Color settings
2+
vim.opt.termguicolors = true
3+
vim.opt.cursorline = true
4+
5+
-- Line number settings
6+
vim.opt.number = true
7+
vim.opt.relativenumber = true
8+
vim.opt.statuscolumn = '%s%=%{v:relnum?v:relnum:v:lnum} '
9+
10+
-- Mode is already in status line plugin
11+
vim.opt.showmode = false
12+
13+
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
14+
if not vim.uv.fs_stat(lazypath) then
15+
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
16+
vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath })
17+
end
18+
vim.opt.rtp:prepend(lazypath)
19+
20+
require('lazy').setup({
21+
dev = { path = '~/dev/repos/personal' },
22+
spec = {
23+
{
24+
'folke/tokyonight.nvim',
25+
config = function()
26+
---@diagnostic disable-next-line: missing-fields
27+
require('tokyonight').setup({ style = 'night' })
28+
vim.cmd.colorscheme('tokyonight')
29+
end,
30+
},
31+
{
32+
'nvim-treesitter/nvim-treesitter',
33+
build = ':TSUpdate',
34+
config = function()
35+
---@diagnostic disable-next-line: missing-fields
36+
require('nvim-treesitter.configs').setup({
37+
ensure_installed = { 'markdown', 'markdown_inline', 'latex' },
38+
highlight = { enable = true },
39+
})
40+
end,
41+
},
42+
{
43+
'nvim-lualine/lualine.nvim',
44+
dependencies = { 'nvim-tree/nvim-web-devicons' },
45+
config = function()
46+
require('lualine').setup({
47+
sections = {
48+
lualine_a = { 'mode' },
49+
lualine_b = { { 'filename', path = 1 } },
50+
lualine_c = {},
51+
lualine_x = {},
52+
lualine_y = {},
53+
lualine_z = { 'location' },
54+
},
55+
})
56+
end,
57+
},
58+
{
59+
'MeanderingProgrammer/render-markdown.nvim',
60+
dev = true,
61+
dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.nvim' },
62+
config = function()
63+
require('render-markdown').setup({})
64+
end,
65+
},
66+
},
67+
})

demo/record.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

demo/run.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import subprocess
2+
from argparse import ArgumentParser
3+
from pathlib import Path
4+
5+
6+
def main(name: str, height: int, content: str):
7+
in_file = Path(f"demo/{name}.md")
8+
assert in_file.exists()
9+
10+
out_file = Path(f"demo/{name}.gif")
11+
if out_file.exists():
12+
out_file.unlink()
13+
14+
tape = Path("demo/demo.tape")
15+
tape.write_text(tape_content(in_file, out_file, height, content))
16+
result = subprocess.run(["vhs", tape])
17+
assert result.returncode == 0
18+
tape.unlink()
19+
20+
21+
def tape_content(in_file: Path, out_file: Path, height: int, to_write: str) -> str:
22+
content = Path("demo/format.tape").read_text()
23+
content = content.replace("INPUT", str(in_file))
24+
content = content.replace("OUTPUT", str(out_file))
25+
content = content.replace("WIDTH", str(550))
26+
content = content.replace("HEIGHT", str(height))
27+
content = content.replace("WRITE", get_write(to_write))
28+
content = content.replace("MOVE", get_move(in_file))
29+
return content
30+
31+
32+
def get_write(content: str) -> str:
33+
write: list[str] = []
34+
if len(content) > 0:
35+
write.append('Type "o"')
36+
write.append("Enter")
37+
write.append(f'Type "{content}" Escape')
38+
write.append('Type "0" Sleep 2s')
39+
return "\n".join(write)
40+
41+
42+
def get_move(in_file: Path) -> str:
43+
move: list[str] = []
44+
# Get lines so we know how to scroll down, account for starting on first line
45+
lines: list[str] = Path(in_file).read_text().splitlines()[1:]
46+
for line in lines:
47+
skip = (" ", "def", "if")
48+
duration = 0.1 if line == "" or line.startswith(skip) else 0.75
49+
move.append(f"Down@{duration}s")
50+
return "\n".join(move)
51+
52+
53+
if __name__ == "__main__":
54+
parser = ArgumentParser(description="Generate a demo recording using vhs")
55+
parser.add_argument("--name", type=str, required=True)
56+
parser.add_argument("--height", type=int, required=True)
57+
parser.add_argument("--content", type=str, required=True)
58+
args = parser.parse_args()
59+
main(args.name, args.height, args.content)

justfile

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,34 @@ health:
2020
demo: demo-heading demo-list demo-box demo-latex demo-callout
2121

2222
demo-heading:
23-
just demo-file "heading_code" "30" "## Heading 2"
23+
python demo/run.py \
24+
--name "heading_code" \
25+
--height "550" \
26+
--content "## Heading 2"
2427

2528
demo-list:
26-
just demo-file "list_table" "30" ""
29+
python demo/run.py \
30+
--name "list_table" \
31+
--height "550" \
32+
--content ""
2733

2834
demo-box:
29-
just demo-file "box_dash_quote" "15" ""
35+
python demo/run.py \
36+
--name "box_dash_quote" \
37+
--height "250" \
38+
--content ""
3039

3140
demo-latex:
32-
just demo-file "latex" "15" ""
41+
python demo/run.py \
42+
--name "latex" \
43+
--height "250" \
44+
--content ""
3345

3446
demo-callout:
35-
just demo-file "callout" "40" ""
36-
37-
demo-file file rows content:
38-
rm -f demo/{{file}}.gif
39-
python demo/record.py \
40-
--cols "60" \
41-
--rows {{rows}} \
42-
--file demo/{{file}}.md \
43-
--cast {{file}}.cast \
44-
--content "{{content}}"
45-
# https://github.com/MeanderingProgrammer/cli/tree/main/agg
46-
agg {{file}}.cast demo/{{file}}.gif
47-
rm {{file}}.cast
47+
python demo/run.py \
48+
--name "callout" \
49+
--height "750" \
50+
--content ""
4851

4952
update:
5053
# Updates types.lua & README.md

0 commit comments

Comments
 (0)