14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/tui_td/cli.rb', line 14
def run(argv)
global_opts = {}
nil
command_opts = {}
OptionParser.new do |opts|
opts.banner = "Usage: tui-td <command> [options]"
opts.separator ""
opts.separator "Commands:"
opts.separator " serve Start MCP server (JSON-RPC over stdio)"
opts.separator " capture <command> Run once, capture and display state"
opts.separator " drive <command> Drive a TUI interactively"
opts.separator " run <command> Run a TUI app and show live output"
opts.separator " test <file.json> Run JSON test file"
opts.separator " help [topic] Show this help, or help test / help rspec"
opts.separator ""
opts.separator "Examples:"
opts.separator " tui-td capture \"ls -la\""
opts.separator " tui-td --screenshot out.png capture \"htop\" --timeout 5"
opts.separator " tui-td --html out.html capture \"glow README.md\""
opts.separator " tui-td -C /my/project capture \"make test\""
opts.separator " tui-td drive \"vim file.txt\" --rows 24 --cols 80"
opts.separator " tui-td test examples/echo_test.json"
opts.separator " tui-td -vl test examples/vim_hello_world.json"
opts.separator " tui-td serve"
opts.separator ""
opts.separator "Interactive commands (drive mode):"
opts.separator " state Show terminal state as pretty JSON"
opts.separator " raw Show raw ANSI output"
opts.separator " elements Show detected UI elements (buttons, dialogs, etc.)"
opts.separator " snapshot <name> Save current state as named snapshot to disk"
opts.separator " snapshot Save current state in-memory (legacy)"
opts.separator " diff <name> Compare current state against named snapshot on disk"
opts.separator " diff Compare against in-memory snapshot (legacy)"
opts.separator " key <name> Send keystroke (enter, tab, escape, up, down, left, right,"
opts.separator " backspace, ctrl_c, ctrl_d)"
opts.separator " <text> Send text to the TUI"
opts.separator " exitstatus Show process exit status (nil if running)"
opts.separator " exit Quit drive mode"
opts.separator ""
opts.separator "Global options:"
opts.on("-r", "--rows N", Integer, "Terminal rows (default: 40)") do |r|
global_opts[:rows] = r
end
opts.on("-c", "--cols N", Integer, "Terminal cols (default: 120)") do |c|
global_opts[:cols] = c
end
opts.on("-t", "--timeout SECONDS", Integer, "Timeout in seconds (default: 30)") do |t|
global_opts[:timeout] = t
end
opts.on("-C", "--chdir PATH", "Working directory for the command") do |d|
global_opts[:chdir] = d
end
opts.on("--screenshot PATH", "Save screenshot (e.g., output.png)") do |p|
global_opts[:screenshot] = p
end
opts.on("--html PATH", "Save HTML render (e.g., output.html)") do |p|
global_opts[:html] = p
end
opts.on("--json", "Output state as compact JSON") do |_|
global_opts[:format] = :json
end
opts.on("--pretty", "Output state as pretty JSON") do |_|
global_opts[:format] = :pretty_json
end
opts.on("--text", "Output state as plain text table") do |_|
global_opts[:format] = :text
end
opts.on("-v", "--verbose", "Show each test step as it runs") do |_|
global_opts[:verbose] = true
end
opts.on("-l", "--live", "Show terminal state after each step (screen-refresh)") do |_|
global_opts[:live] = true
end
opts.on("-s", "--step", "Pause after each test step for confirmation") do |_|
global_opts[:step_mode] = true
end
opts.on("--version", "Show version") do
puts "tui-td #{TUITD::VERSION}"
exit 0
end
opts.on("-h", "--help", "Show help") do
puts opts
exit 0
end
end.permute!(argv)
command = argv.shift
command_opts[:args] = argv
case command
when "serve"
cmd_serve(global_opts)
when "run"
cmd_run(command_opts, global_opts)
when "drive"
cmd_drive(command_opts, global_opts)
when "capture"
cmd_capture(command_opts, global_opts)
when "test"
cmd_test(command_opts, global_opts)
when "help"
topic = argv.shift
case topic
when "test"
_help_test
when "rspec"
_help_rspec
when nil
_help_main
else
abort "Unknown help topic: #{topic.inspect}\nTry: tui-td help test, tui-td help rspec"
end
when nil
_help_main
else
abort "Unknown command: #{command.inspect}\nUse tui-td --help for usage"
end
end
|