vimamsa 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
data/run_tests_vm.rb ADDED
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+ # Run the vimamsa test suite inside the VirtualBox VM named by $VM_NAME, on its
3
+ # real logged-in desktop (so the GTK window actually appears in the VM).
4
+ #
5
+ # Reaches the guest via VBoxManage guestcontrol (Guest Additions): no SSH or
6
+ # shared folder needed. Syncs the current working tree (incl. uncommitted
7
+ # changes), provisions the guest on first run, builds the native extension,
8
+ # then runs exe/run_tests.rb on DISPLAY :0 (vm_guest_run.sh, in the guest).
9
+ # Exits with the suite's exit code (0 pass / 1 fail).
10
+ #
11
+ # Usage (VM_NAME, VM_USER and VM_PASS exported, e.g. in ~/.bashrc):
12
+ # ./run_tests_vm.rb [test filter args...]
13
+ # Examples:
14
+ # ./run_tests_vm.rb # full suite
15
+ # ./run_tests_vm.rb undo # tests/test_undo.rb only
16
+ # FORCE_PROVISION=1 ./run_tests_vm.rb # re-run apt provisioning
17
+ # VMA_UPDATE_DOC=1 ./run_tests_vm.rb vim_conflicts # also copy back generated docs
18
+ #
19
+ # Env:
20
+ # VM_NAME (required) VirtualBox VM name
21
+ # VM_USER (required) guest login username
22
+ # VM_PASS (required) guest login/sudo password for user $VM_USER
23
+ # VM_DISPLAY guest desktop X display (default: :0)
24
+ # FORCE_PROVISION set to 1 to force guest re-provisioning
25
+ # VMA_UPDATE_DOC set to 1 to copy regenerated docs back (GENERATED_DOCS)
26
+ # VMA_E2E_INTERACTIVE passed on to the guest (run_e2e_vm.sh sets it)
27
+ #
28
+ # Exit codes: the suite's 0 / 1; 2 required variable not set; 4 Guest
29
+ # Additions not answering; 5 the guest never reached the test phase; 6 packing
30
+ # the working tree failed.
31
+ require "tempfile"
32
+ require "tmpdir"
33
+ require "fileutils"
34
+ require_relative "scripts/lib/script_helpers"
35
+ include ScriptHelpers
36
+
37
+ # Tracked docs that tests regenerate in the guest with VMA_UPDATE_DOC=1
38
+ GENERATED_DOCS = ["doc/vimlike_vim_conflicts.md"]
39
+
40
+ # Left out of the copy sent to the guest (tar --exclude patterns)
41
+ TAR_EXCLUDES = %w[
42
+ ./.git/hooks *_vma_autosave .*_vma_autosave *.gem *.o *.so *.tar.xz
43
+ __pycache__ *.log claude-log.* dot_git_old ./build 2del_* bug*.txt *.mp3 *.wav
44
+ ]
45
+
46
+ missing = missing_env("VM_NAME", "VM_USER", "VM_PASS")
47
+ if missing.any?
48
+ fail!("Not set: #{missing.join(" ")}. Export VM_NAME (VirtualBox VM), VM_USER (guest user)\n" \
49
+ "and VM_PASS (guest password), e.g. in ~/.bashrc.", 2)
50
+ end
51
+
52
+ vm = ENV["VM_NAME"]
53
+ user = ENV["VM_USER"]
54
+ display = ENV["VM_DISPLAY"].to_s.empty? ? ":0" : ENV["VM_DISPLAY"]
55
+ guest_home = "/home/#{user}"
56
+ repo, ok = Open3.capture2("git", "-C", __dir__, "rev-parse", "--show-toplevel")
57
+ repo = ok.success? ? repo.strip : __dir__
58
+
59
+ # The password goes to VBoxManage in a chmod-600 file, so it isn't visible in
60
+ # `ps` (the guest script gets it as SUDO_PASS through --putenv, as before).
61
+ pwfile = Tempfile.new("vma_vm_pw")
62
+ tarball = Tempfile.new(["vimamsa_src", ".tgz"])
63
+ begin
64
+ File.chmod(0o600, pwfile.path)
65
+ pwfile.write(ENV["VM_PASS"])
66
+ pwfile.flush
67
+
68
+ # In VBoxManage 7.x the credentials/options belong to the run/copyto
69
+ # subcommand (after it), and use --opt=value syntax.
70
+ gc = ["VBoxManage", "guestcontrol", vm]
71
+ cred = ["--username=#{user}", "--passwordfile=#{pwfile.path}"]
72
+
73
+ # 1. Ensure the VM is running and Guest Additions answer.
74
+ running, = Open3.capture2("VBoxManage", "list", "runningvms")
75
+ if !running.include?("\"#{vm}\"")
76
+ step "Starting VM #{vm}"
77
+ run!("VBoxManage", "startvm", vm, "--type", "gui", label: "VBoxManage startvm")
78
+ end
79
+ step "Waiting for Guest Additions in #{vm}"
80
+ answered = 60.times.any? { |i|
81
+ sleep 2 if i > 0
82
+ system(*gc, "run", *cred, "--exe=/bin/true", "--", "true", out: File::NULL, err: File::NULL)
83
+ }
84
+ fail!("Guest Additions not responding after 2 min. Is the guest booted and logged in?", 4) if !answered
85
+
86
+ # 2. Tarball the working tree (with .git, for `gem build`; without heavy
87
+ # junk). tar exits with 1 for "file changed as we read it" (e.g. .git
88
+ # churning during the read): only a fatal error (2 and up) aborts.
89
+ step "Packing working tree"
90
+ system("tar", "czf", tarball.path, "-C", repo, "--warning=no-file-changed",
91
+ *TAR_EXCLUDES.map { |e| "--exclude=#{e}" }, ".")
92
+ fail!("tar failed (exit #{$?.exitstatus})", 6) if $?.exitstatus.to_i > 1
93
+
94
+ # 3. Copy the tarball and the guest runner into the VM (copyto overwrites).
95
+ step "Copying source + runner into guest"
96
+ run!(*gc, "copyto", *cred, tarball.path, "#{guest_home}/vimamsa_src.tgz", label: "VBoxManage copyto")
97
+ run!(*gc, "copyto", *cred, File.join(repo, "vm_guest_run.sh"), "#{guest_home}/vm_guest_run.sh",
98
+ label: "VBoxManage copyto")
99
+
100
+ # 4. Run the guest script, streaming its output. VBoxManage doesn't pass on
101
+ # the guest's exit code, so pass/fail comes from the VMA_SUITE_EXIT sentinel
102
+ # the guest prints, not from VBoxManage's own exit status.
103
+ step "Running test suite in guest (DISPLAY #{display})"
104
+ putenv = {
105
+ "SUDO_PASS" => ENV["VM_PASS"], "VMA_DISPLAY" => display, "VMA_TEST_ARGS" => ARGV.join(" "),
106
+ "FORCE_PROVISION" => ENV["FORCE_PROVISION"].to_s, "VMA_E2E_INTERACTIVE" => ENV["VMA_E2E_INTERACTIVE"].to_s,
107
+ "VMA_UPDATE_DOC" => ENV["VMA_UPDATE_DOC"].to_s,
108
+ }.map { |k, v| "--putenv=#{k}=#{v}" }
109
+ out, = run_streaming(*gc, "run", *cred, "--exe=/bin/bash", "--wait-stdout", "--wait-stderr",
110
+ *putenv, "--", "#{guest_home}/vm_guest_run.sh")
111
+
112
+ sentinel = out.scan(/VMA_SUITE_EXIT=(\d+)/).last&.first
113
+ if sentinel.nil?
114
+ fail!("Did not receive a VMA_SUITE_EXIT sentinel from the guest: the run did not\n" \
115
+ "reach the test phase (provisioning/build failure above).", 5)
116
+ end
117
+ step "Suite exit code (from guest): #{sentinel}"
118
+
119
+ # VMA_UPDATE_DOC=1: tests that generate a tracked doc wrote it in the guest;
120
+ # copy it back into this working tree. copyfrom doesn't truncate an existing
121
+ # file, so copy into an empty directory first.
122
+ if ENV["VMA_UPDATE_DOC"] == "1"
123
+ Dir.mktmpdir { |tmp|
124
+ GENERATED_DOCS.each { |f|
125
+ step "Copying regenerated #{f} from guest"
126
+ if system(*gc, "copyfrom", *cred, "--target-directory=#{tmp}/", "#{guest_home}/vimamsa/#{f}")
127
+ FileUtils.mv(File.join(tmp, File.basename(f)), File.join(repo, f), force: true)
128
+ else
129
+ warn "!! could not copy #{f} back"
130
+ end
131
+ }
132
+ }
133
+ end
134
+ exit sentinel.to_i
135
+ ensure
136
+ pwfile.close!
137
+ tarball.close!
138
+ end
@@ -0,0 +1,60 @@
1
+ # Easy jump demo, played inside the editor by Help ▸ Demos ▸ Easy jump
2
+ # (lib/vimamsa/demo_player.rb), on scripts/demo/shapes.rb. The commands are
3
+ # those of demo_steps.txt; "target line N" names line N (1-based).
4
+ # The key log panel on the right shows each key and the action it ran.
5
+ #
6
+ # It moves the to_s method of Shape above area: the range is selected with
7
+ # v and easy jump, cut, and pasted where easy jump goes.
8
+
9
+ delay 0.45
10
+ wait 1.5
11
+
12
+ # Easy jump (s): every line start and many word starts get a label; type
13
+ # one to jump there
14
+ target def to_s
15
+ keys s
16
+ wait 1.6
17
+ keys @JUMP_LABEL@
18
+ wait 0.8
19
+ target shapes.each
20
+ keys s
21
+ wait 1.2
22
+ keys @JUMP_LABEL@
23
+ wait 0.8
24
+ target class Shape
25
+ keys s
26
+ wait 1.2
27
+ keys @JUMP_LABEL@
28
+ wait 1.0
29
+
30
+ # Select a range: go to the empty line above to_s, start the selection with
31
+ # v, and let easy jump extend it to the line where to_s ends
32
+ target line 10
33
+ keys s
34
+ wait 1.2
35
+ keys @JUMP_LABEL@
36
+ wait 0.6
37
+ keys v
38
+ wait 0.6
39
+ target line 13
40
+ keys s
41
+ wait 1.4
42
+ keys @JUMP_LABEL@
43
+ wait 0.6
44
+ keys $
45
+ wait 1.0
46
+
47
+ # Cut it, jump to the empty line below initialize and paste it there
48
+ keys x
49
+ wait 1.0
50
+ target line 6
51
+ keys s
52
+ wait 1.2
53
+ keys @JUMP_LABEL@
54
+ wait 0.6
55
+ keys P
56
+ wait 1.5
57
+
58
+ # Back to the top
59
+ keys g g
60
+ wait 2.0
@@ -0,0 +1,52 @@
1
+ # File switching demo, played inside the editor by Help ▸ Demos ▸ Switching
2
+ # files (lib/vimamsa/demo_player.rb), on scripts/demo/shapes.rb, report.rb
3
+ # and notes.txt (opened in that order of age: shapes.rb is current and the
4
+ # newest in the buffer history). The commands are those of demo_steps.txt.
5
+ # The key log panel on the right shows each key and the action it ran.
6
+
7
+ delay 0.45
8
+ wait 1.5
9
+
10
+ # tab: back to the file used before; tab again: back here
11
+ keys tab
12
+ wait 1.5
13
+ keys tab
14
+ wait 1.5
15
+
16
+ # Browse mode (z): h goes back in the buffer history, l forward; j leaves
17
+ # browse mode in the file shown
18
+ keys z
19
+ wait 1.0
20
+ keys h
21
+ wait 1.2
22
+ keys h
23
+ wait 1.2
24
+ keys l
25
+ wait 1.2
26
+ keys j
27
+ wait 1.2
28
+
29
+ # , f: the file explorer, on the current file's folder with the cursor on
30
+ # its line. k / j move to another file; l (or enter) opens it
31
+ keys , f
32
+ wait 1.4
33
+ keys k
34
+ wait 1.0
35
+ keys l
36
+ wait 1.5
37
+
38
+ # tab: back to the file before
39
+ keys tab
40
+ wait 1.5
41
+
42
+ # The explorer again, to shapes.rb (below report.rb)
43
+ keys , f
44
+ wait 1.2
45
+ keys j
46
+ wait 1.0
47
+ keys l
48
+ wait 1.0
49
+
50
+ # Back to the top
51
+ keys g g
52
+ wait 2.0
@@ -1,4 +1,5 @@
1
- # Key presses for the README demo, run by scripts/demo/record_demo.rb.
1
+ # Key presses for the README demo, run by scripts/demo/record_demo.rb, and
2
+ # played inside the editor by Help ▸ Play demo (lib/vimamsa/demo_player.rb).
2
3
  # Times are at --speed 1; the script divides them by its --speed.
3
4
  # keys K K ... press keys one at a time (editor key names: esc, enter,
4
5
  # space, ctrl (alone), ctrl-r, or xdotool keysyms), with the
@@ -6,6 +7,12 @@
6
7
  # type TEXT type TEXT character by character (Insert mode)
7
8
  # wait SECONDS pause
8
9
  # delay SECONDS time between keys from now on
10
+ # target TEXT where easy jump goes: the start of the first line holding
11
+ # TEXT; or "line N" (its start), or "line N col C" (1-based,
12
+ # the exact character; written by the demo recorder).
13
+ # The player in the editor types that line's label (labels
14
+ # depend on the window size); the recording types
15
+ # JUMP_LABEL from record_demo.rb.
9
16
  # The key log panel on the right shows each key and the action it ran.
10
17
 
11
18
  delay 0.45
@@ -49,6 +56,7 @@ keys y
49
56
  wait 0.8
50
57
 
51
58
  # Easy jump (s): every word start gets a label; type one to jump there
59
+ target class Circle
52
60
  keys s
53
61
  wait 1.6
54
62
  keys @JUMP_LABEL@
@@ -0,0 +1,6 @@
1
+ Example file for the file switching demo.
2
+
3
+ Notes
4
+ - shapes.rb: the Shape classes
5
+ - report.rb: prints a table of shapes
6
+ - add a Square shape
@@ -1,17 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
- # Records the README demo animation (img/demo.gif) on this machine:
3
- # runs the editor from this checkout on a hidden X display (Xvfb, so the
4
- # desktop isn't disturbed), types the keys in demo_steps.txt with xdotool
5
- # (real key events, so the key log panel shows them), records the window with
6
- # ffmpeg and converts the video to an optimized GIF.
2
+ # Records a demo as an animation (default: the README's img/demo.gif) on
3
+ # this machine: runs the editor from this checkout on a hidden X display
4
+ # (Xvfb, so the desktop isn't disturbed), lets the editor's own demo player
5
+ # (lib/vimamsa/demo_player.rb) play the steps file, records the window with
6
+ # ffmpeg and converts the video to an optimized GIF. The player feeds the
7
+ # keys to the key bindings as if typed (the key log panel shows them), finds
8
+ # easy jump labels for this window, and types into forms and list windows.
7
9
  #
8
- # ruby scripts/demo/record_demo.rb [--speed 0.7] [--out img/demo.gif] [--keep] [--frame]
9
- # --speed playback speed: every delay and wait in demo_steps.txt is
10
+ # ruby scripts/demo/record_demo.rb [STEPS] [--speed 0.7] [--out img/demo.gif] [--keep]
11
+ # STEPS the steps file (default scripts/demo/demo_steps.txt), e.g.
12
+ # scripts/demo/square/steps.txt or a recorded demo in
13
+ # ~/.config/vimamsa/demos/<name>/steps.txt. Its files ("file"
14
+ # lines, default shapes.rb) are taken from its folder.
15
+ # --speed playback speed: every delay and wait in the steps file is
10
16
  # divided by it (1 = as written, 0.5 = twice as slow).
11
- # Default 0.7.
17
+ # Default 0.7, as the editor's Help > Demos at 1x.
18
+ # --size the editor window's size, WIDTHxHEIGHT (default 960x600). A
19
+ # smaller window shows fewer lines: easy jump targets off
20
+ # screen are reached without a label.
12
21
  # --keep also keep the lossless video (build/demo/demo.mkv)
13
- # --frame run the steps up to the easy jump label without recording and
14
- # save that moment as build/demo/frame.png, to pick the label
15
22
  #
16
23
  # Needs: Xvfb, xdotool, ffmpeg, gifsicle.
17
24
  require "fileutils"
@@ -20,21 +27,25 @@ require "optparse"
20
27
 
21
28
  ROOT = File.expand_path("../..", __dir__)
22
29
  DIR = __dir__
23
- WIDTH, HEIGHT = 960, 600
24
30
  FPS = 15
25
31
  GIF_FPS = 12
26
- # The label easy jump gives the line to jump to (find it with --frame)
27
- JUMP_LABEL = %w[f s]
28
-
29
- opts = { out: File.join(ROOT, "img/demo.gif"), keep: false, frame: false, speed: 0.7 }
32
+ opts = { out: File.join(ROOT, "img/demo.gif"), keep: false, speed: 0.7, size: "960x600" }
30
33
  OptionParser.new { |o|
31
34
  o.on("--speed FACTOR", Float) { |v| opts[:speed] = v }
35
+ o.on("--size WxH") { |v| opts[:size] = v }
32
36
  o.on("--out PATH") { |v| opts[:out] = File.expand_path(v) }
33
37
  o.on("--keep") { opts[:keep] = true }
34
- o.on("--frame") { opts[:frame] = true }
35
38
  }.parse!
36
39
  abort "--speed must be > 0" unless opts[:speed] > 0
37
40
  SPEED = opts[:speed]
41
+ WIDTH, HEIGHT = opts[:size].split("x").map(&:to_i)
42
+ abort "--size must be WIDTHxHEIGHT, e.g. 960x600" unless WIDTH.to_i > 0 && HEIGHT.to_i > 0
43
+ STEPS = File.expand_path(ARGV[0] || File.join(DIR, "demo_steps.txt"))
44
+ abort "steps file not found: #{STEPS}" unless File.file?(STEPS)
45
+ SRC = File.dirname(STEPS)
46
+ FILES = File.readlines(STEPS, chomp: true).filter_map { |l| l[/\Afile\s+(\S+)/, 1] }
47
+ FILES << "shapes.rb" if FILES.empty?
48
+ FILES.each { |f| abort "#{f} (a file of the demo) not found in #{SRC}" unless File.file?(File.join(SRC, f)) }
38
49
 
39
50
  %w[Xvfb xdotool ffmpeg gifsicle].each { |t|
40
51
  abort "#{t} not found (sudo apt install xvfb xdotool ffmpeg gifsicle)" unless system("which #{t} >/dev/null")
@@ -60,25 +71,36 @@ sleep 0.2 until File.exist?("/tmp/.X11-unix/X#{display}")
60
71
  env = { "DISPLAY" => disp, "GDK_BACKEND" => "x11", "WAYLAND_DISPLAY" => nil,
61
72
  "GTK_THEME" => nil, "NO_AT_BRIDGE" => "1" }
62
73
 
63
- # ── The editor, with a throwaway config dir: default settings plus the key
64
- # log panel, and nothing read from or written to the user's own config ──
74
+ # ── The editor, with a throwaway config dir: default settings, no intro
75
+ # page, nothing read from or written to the user's own config. Its
76
+ # custom.rb plays the demo once ready + go (files in the config dir), then
77
+ # writes done and quits. ──
65
78
  ud = Dir.mktmpdir("vma-demo")
66
79
  at_exit { FileUtils.rm_rf(ud) }
80
+ ready, go, done = %w[ready go done].map { |f| File.join(ud, f) }
81
+ demo = { steps: STEPS, files: FILES, src: SRC }
67
82
  File.write(File.join(ud, "custom.rb"), <<~RUBY)
68
83
  cnf.lsp.enabled = false
84
+ cnf.intro.show_on_startup = false
69
85
  def hook_custom_after_init
70
- vma.gui.toggle_keylog_panel
86
+ vma.gui.show_keylog_panel
87
+ File.write(#{ready.inspect}, "1")
88
+ GLib::Timeout.add(100) {
89
+ next true if !File.exist?(#{go.inspect})
90
+ DemoPlayer.new(:recording, demo: #{demo.inspect}, speed: #{SPEED}, rate: 1, loop: false, controls: false,
91
+ on_finish: proc { |msg|
92
+ # written whole, then renamed: the script never reads it half done
93
+ File.write(#{(done + ".tmp").inspect}, msg.to_s)
94
+ File.rename(#{(done + ".tmp").inspect}, #{done.inspect})
95
+ GLib::Timeout.add(1000) { vma.shutdown; false }
96
+ }).start
97
+ false
98
+ }
71
99
  end
72
100
  RUBY
73
- # A short path for the title bar
74
- demo_dir = "/tmp/vimamsa-demo"
75
- FileUtils.rm_rf(demo_dir)
76
- FileUtils.mkdir_p(demo_dir)
77
- at_exit { FileUtils.rm_rf(demo_dir) }
78
- file = File.join(demo_dir, "shapes.rb")
79
- FileUtils.cp(File.join(DIR, "shapes.rb"), file)
80
- pids << spawn(env, RbConfig.ruby, File.join(ROOT, "exe/vimamsa"), "--user-dir", ud, file,
81
- chdir: demo_dir, out: File.join(WORK, "editor.log"), err: [:child, :out])
101
+ editor = spawn(env, RbConfig.ruby, File.join(ROOT, "exe/vimamsa"), "--user-dir", ud,
102
+ chdir: "/tmp", out: File.join(WORK, "editor.log"), err: [:child, :out])
103
+ pids << editor
82
104
 
83
105
  def xdo(env, *args)
84
106
  out = IO.popen(env, ["xdotool", *args], err: File::NULL, &:read)
@@ -88,64 +110,16 @@ end
88
110
  win = nil
89
111
  60.times {
90
112
  win = xdo(env, "search", "--onlyvisible", "--name", "^Vimamsa")&.split&.last
91
- break if win
113
+ break if win && File.exist?(ready)
92
114
  sleep 0.5
93
115
  }
94
- abort "editor window did not appear (log: #{WORK}/editor.log)" unless win
95
- sleep 3 # first layout, highlighting, key log panel
116
+ abort "editor window did not appear (log: #{WORK}/editor.log)" unless win && File.exist?(ready)
117
+ sleep 2 # first layout, highlighting, key log panel
96
118
  xdo(env, "windowfocus", "--sync", win)
97
119
  geo = xdo(env, "getwindowgeometry", "--shell", win).scan(/(\w+)=(\d+)/).to_h.transform_values(&:to_i)
98
120
  x, y = geo["X"], geo["Y"]
99
121
  w, h = geo["WIDTH"] & ~1, geo["HEIGHT"] & ~1 # even sizes for the encoder
100
- puts "window #{w}x#{h} at #{x},#{y}"
101
-
102
- # Editor key names to xdotool keysyms
103
- KEYSYMS = { "ctrl" => "Control_L", "esc" => "Escape", "enter" => "Return", "space" => "space", "tab" => "Tab",
104
- "backspace" => "BackSpace", "$" => "dollar", "0" => "0" }
105
- def press(env, key)
106
- k = key.sub(/\Actrl-/, "ctrl+").sub(/\Ashift-/, "shift+")
107
- k = KEYSYMS.fetch(k, k)
108
- xdo(env, "key", "--clearmodifiers", k) or abort "xdotool key #{k} failed"
109
- end
110
-
111
- def grab_png(disp, x, y, w, h, png)
112
- sh!("ffmpeg", "-loglevel", "error", "-y", "-f", "x11grab", "-video_size", "#{w}x#{h}",
113
- "-draw_mouse", "0", "-i", "#{disp}+#{x},#{y}", "-frames:v", "1", png)
114
- end
115
-
116
- # Runs demo_steps.txt. With stop_at_label, returns just before the easy
117
- # jump label would be typed.
118
- def run_steps(env, stop_at_label: false)
119
- delay = 0.4 / SPEED
120
- File.readlines(File.join(DIR, "demo_steps.txt"), chomp: true).each { |line|
121
- line = line.sub(/\s+#\s.*\z/, "") unless line.start_with?("type ")
122
- next if line.strip.empty? || line.start_with?("#")
123
- cmd, arg = line.split(" ", 2)
124
- case cmd
125
- when "wait" then sleep arg.to_f / SPEED
126
- when "delay" then delay = arg.to_f / SPEED
127
- when "keys"
128
- keys = arg.split
129
- return if stop_at_label && keys.include?("@JUMP_LABEL@")
130
- keys = keys.flat_map { |k| k == "@JUMP_LABEL@" ? JUMP_LABEL : [k] }
131
- keys.each { |k| press(env, k); sleep delay }
132
- when "type"
133
- arg.each_char { |c|
134
- xdo(env, "type", "--delay", "0", c) or abort "xdotool type failed"
135
- sleep delay
136
- }
137
- else abort "demo_steps.txt: unknown command #{line.inspect}"
138
- end
139
- }
140
- end
141
-
142
- if opts[:frame]
143
- run_steps(env, stop_at_label: true)
144
- png = File.join(WORK, "frame.png")
145
- grab_png(disp, x, y, w, h, png)
146
- puts "saved #{png}"
147
- exit
148
- end
122
+ puts "window #{w}x#{h} at #{x},#{y}; playing #{STEPS}"
149
123
 
150
124
  # ── Record ──
151
125
  video = File.join(WORK, "demo.mkv")
@@ -153,9 +127,14 @@ rec = spawn("ffmpeg", "-loglevel", "warning", "-nostdin", "-y", "-f", "x11grab",
153
127
  "-video_size", "#{w}x#{h}", "-draw_mouse", "0", "-i", "#{disp}+#{x},#{y}",
154
128
  "-c:v", "libx264rgb", "-crf", "0", "-preset", "ultrafast", video)
155
129
  sleep 0.5
156
- run_steps(env)
130
+ File.write(go, "1")
131
+ t = Time.now
132
+ sleep 0.2 until File.exist?(done) || Process.waitpid(editor, Process::WNOHANG) || Time.now - t > 1800
133
+ msg = File.exist?(done) ? File.read(done) : "editor quit or timed out (log: #{WORK}/editor.log)"
134
+ sleep 0.8 # the end state on screen for a moment
157
135
  Process.kill("INT", rec)
158
136
  Process.wait(rec)
137
+ abort "the demo didn't finish: #{msg}" unless msg == "Demo finished"
159
138
  # ffmpeg exits 255 when stopped with INT; anything else is an error
160
139
  abort "recording failed (ffmpeg exit #{$?.exitstatus})" unless [0, 255].include?($?.exitstatus)
161
140
  system("ffmpeg", "-v", "error", "-i", video, "-f", "null", "-", err: File.join(WORK, "decode.log"))
@@ -0,0 +1,7 @@
1
+ # Example file for the file switching demo: prints the shapes as a table
2
+ require_relative "shapes"
3
+
4
+ def report(shapes)
5
+ puts format("%-8s %8s", "shape", "area")
6
+ shapes.each { |s| puts format("%-8s %8.2f", s.class.name.downcase, s.area) }
7
+ end
@@ -26,3 +26,4 @@ end
26
26
 
27
27
  shapes = [Circle.new(1), Circle.new(2.5)]
28
28
  shapes.each { |s| puts s }
29
+
@@ -0,0 +1,29 @@
1
+ # Example file for the README demo
2
+ class Shape
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ def area
8
+ 0
9
+ end
10
+
11
+ def to_s
12
+ "#{@name}: #{area.round(2)}"
13
+ end
14
+ end
15
+
16
+ class Circle < Shape
17
+ def initialize(radius)
18
+ super("circle")
19
+ @radius = radius
20
+ end
21
+
22
+ def area
23
+ Math::PI * @radius**2
24
+ end
25
+ end
26
+
27
+ shapes = [Circle.new(1), Circle.new(2.5)]
28
+ shapes.each { |s| puts s }
29
+