hostty 0.1.2.alpha-aarch64-linux-gnu → 1.0.0-aarch64-linux-gnu

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/docs/assets/demo.svg +68 -13
  3. data/docs/development/README.md +2 -1
  4. data/docs/development/architecture.md +15 -11
  5. data/lib/hostty/cli.rb +1 -1
  6. data/lib/hostty/config/loader/process_definition.rb +56 -0
  7. data/lib/hostty/config/loader.rb +78 -0
  8. data/lib/hostty/config/rules/command.rb +22 -0
  9. data/lib/hostty/config/rules/domain.rb +24 -0
  10. data/lib/hostty/config/rules/env.rb +22 -0
  11. data/lib/hostty/config/rules/known_settings.rb +27 -0
  12. data/lib/hostty/config/rules/path_settings.rb +29 -0
  13. data/lib/hostty/config/rules/port_setting.rb +27 -0
  14. data/lib/hostty/config/rules/process_list.rb +24 -0
  15. data/lib/hostty/config/rules/process_settings.rb +22 -0
  16. data/lib/hostty/config/rules/settings_list.rb +22 -0
  17. data/lib/hostty/config/rules/skip_used_ports.rb +21 -0
  18. data/lib/hostty/config/rules/text.rb +21 -0
  19. data/lib/hostty/config/rules/unique_domains.rb +30 -0
  20. data/lib/hostty/config/validator.rb +22 -0
  21. data/lib/hostty/config.rb +4 -67
  22. data/lib/hostty/domains/nginx_options.rb +37 -0
  23. data/lib/hostty/domains.rb +1 -1
  24. data/lib/hostty/ghostty/cell_reader.rb +68 -0
  25. data/lib/hostty/ghostty/frame.rb +7 -149
  26. data/lib/hostty/ghostty/raw_cell.rb +43 -0
  27. data/lib/hostty/ghostty/screen.rb +3 -0
  28. data/lib/hostty/ghostty/style_decoder.rb +44 -0
  29. data/lib/hostty/process_config.rb +15 -67
  30. data/lib/hostty/terminal/cell.rb +2 -2
  31. data/lib/hostty/terminal/flyweight.rb +19 -0
  32. data/lib/hostty/terminal/style.rb +3 -5
  33. data/lib/hostty/tui/activity.rb +26 -0
  34. data/lib/hostty/tui/app.rb +43 -254
  35. data/lib/hostty/tui/bell.rb +30 -0
  36. data/lib/hostty/tui/blink.rb +36 -0
  37. data/lib/hostty/tui/canvas.rb +51 -0
  38. data/lib/hostty/tui/clock.rb +9 -0
  39. data/lib/hostty/tui/controls.rb +59 -0
  40. data/lib/hostty/tui/display.rb +27 -0
  41. data/lib/hostty/tui/events/focus.rb +19 -0
  42. data/lib/hostty/tui/events/interrupt.rb +19 -0
  43. data/lib/hostty/tui/events/keys.rb +19 -0
  44. data/lib/hostty/tui/events/mouse_report.rb +19 -0
  45. data/lib/hostty/tui/events/next_tab.rb +11 -0
  46. data/lib/hostty/tui/input.rb +7 -7
  47. data/lib/hostty/tui/layout.rb +8 -49
  48. data/lib/hostty/tui/lifecycle/exited.rb +20 -0
  49. data/lib/hostty/tui/lifecycle/pending.rb +17 -0
  50. data/lib/hostty/tui/lifecycle/restarting.rb +20 -0
  51. data/lib/hostty/tui/lifecycle/running.rb +20 -0
  52. data/lib/hostty/tui/lifecycle.rb +38 -0
  53. data/lib/hostty/tui/mouse/idle.rb +37 -0
  54. data/lib/hostty/tui/mouse/pointer.rb +45 -0
  55. data/lib/hostty/tui/mouse/selecting.rb +67 -0
  56. data/lib/hostty/tui/mouse/target.rb +78 -0
  57. data/lib/hostty/tui/outcome.rb +15 -0
  58. data/lib/hostty/tui/outer_modes.rb +29 -0
  59. data/lib/hostty/tui/pane.rb +30 -42
  60. data/lib/hostty/tui/reactor.rb +20 -0
  61. data/lib/hostty/tui/regions/help_bar.rb +48 -0
  62. data/lib/hostty/tui/regions/palette.rb +12 -0
  63. data/lib/hostty/tui/regions/pane_view.rb +60 -0
  64. data/lib/hostty/tui/regions/tab_bar.rb +100 -0
  65. data/lib/hostty/tui/renderer.rb +6 -67
  66. data/lib/hostty/tui/sources/manager_events.rb +31 -0
  67. data/lib/hostty/tui/sources/stdin.rb +33 -0
  68. data/lib/hostty/tui/tabs.rb +40 -0
  69. data/lib/hostty/tui/timer.rb +33 -0
  70. data/lib/hostty/tui/window.rb +32 -0
  71. data/lib/hostty/version.rb +1 -1
  72. data/lib/hostty.rb +50 -0
  73. metadata +54 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21279f6e43aa617aa759c9659f061baacf1bbbf3ba50729c5daaf5d08b472164
4
- data.tar.gz: 933de8ee4f9cd7d4563a0792228ea0d4f8cd6d4b88428cfcec0abf627167fc4a
3
+ metadata.gz: b46294d863fd558c60d027d6caa69fa9983cbaf2ad92e031990c31a9f5e7f764
4
+ data.tar.gz: d48aa790bd5bd5e127304389f1c385e52a893ab9f30b3c8a1695276b8da90b13
5
5
  SHA512:
6
- metadata.gz: d67f7ec4f8c82d48eea7df3b7aa31db880c3ee80f9413b972bd90a7e3c252d9e43dd1ada96aa8d59fb24e05251fdc0c818d92cde909707c7fdabaa1b36d99072
7
- data.tar.gz: b8809036eedcebfc1d8332f4ae9ea7eb5b32f8bcd258b510112597954a4a8228750b6f23ce55ffc7e55758657d5293f41aae2b800b8abdfb6119e6f412fa65a8
6
+ metadata.gz: ba9a07180896b181442bc0f642e6498d0a6cfec6af081dcee5cc5be64af2a8b36741fbdca9bdda80a9c732561ad6ab04f1461727bca253bd271093a7d9e0e882
7
+ data.tar.gz: 4b48bc765d06353f26b1415eb9d28176549e74c681d83b29bad6994dc6cb87409cf14b0af5ea38b54f738845ddc73ef94c83682275e30cd17b1663f16e011826
data/docs/assets/demo.svg CHANGED
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="760" height="420" viewBox="0 0 760 420" role="img" aria-label="Hostty adds a domain, then shows a Rails server, a Jekyll site, and Solid Queue in tabs, with the URL of each domain in the tab bar and a line of output selected for copying">
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="760" height="420" viewBox="0 0 760 420" role="img" aria-label="Hostty adds a domain, then shows a Rails server, a Jekyll site, and Solid Queue in tabs, with the URL of each domain in the tab bar and a line of output selected for copying, then the web tab blinks yellow when a debugger call rings the bell">
2
2
  <style>
3
3
  text { font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace; font-size: 13px; fill: #c0caf5; white-space: pre; }
4
4
  .dim { fill: #565f89; }
@@ -16,20 +16,26 @@
16
16
  </style>
17
17
 
18
18
  <rect width="0" height="0" opacity="0">
19
- <animate id="loop" attributeName="opacity" values="0;0" dur="14s" begin="0s;loop.end"/>
19
+ <animate id="loop" attributeName="opacity" values="0;0" dur="20s" begin="0s;loop.end"/>
20
20
  </rect>
21
21
 
22
22
  <defs>
23
23
  <clipPath id="typing">
24
24
  <rect x="40" y="70" width="0" height="24">
25
25
  <set attributeName="width" to="0" begin="loop.begin" dur="0.3s"/>
26
- <animate attributeName="width" from="0" to="70" begin="loop.begin+0.3s" dur="0.7s" fill="freeze"/>
26
+ <animate attributeName="width" values="0;7.5;15.3;23.1;30.9;38.7;70" keyTimes="0;0.14;0.3;0.42;0.6;0.74;0.88" calcMode="discrete" begin="loop.begin+0.3s" dur="0.7s" fill="freeze"/>
27
27
  </rect>
28
28
  </clipPath>
29
29
  <clipPath id="dragging">
30
30
  <rect x="18" y="166" width="0" height="20">
31
31
  <set attributeName="width" to="0" begin="loop.begin" dur="6.5s"/>
32
- <animate attributeName="width" from="0" to="286" begin="loop.begin+6.5s" dur="0.6s" fill="freeze"/>
32
+ <animate attributeName="width" values="0;9.8;17.7;25.5;33.3;41.2;49;56.8;64.6;72.5;80.3;88.1;96;103.8;111.6;119.5;127.3;135.1;142.9;150.8;158.6;166.4;174.3;182.1;189.9;197.8;205.6;213.4;221.2;229.1;236.9;244.7;252.6;260.4;268.2;276.1;286" calcMode="discrete" begin="loop.begin+6.5s" dur="0.6s" fill="freeze"/>
33
+ </rect>
34
+ </clipPath>
35
+ <clipPath id="debugging">
36
+ <rect x="72" y="298" width="0" height="24">
37
+ <set attributeName="width" to="0" begin="loop.begin" dur="16.6s"/>
38
+ <animate attributeName="width" values="0;10.3;18.2;26;33.8;41.7;49.5;57.3;65.1;73;80.8;88.6;96.5;104.3;112.1;125" keyTimes="0;0.06;0.12;0.17;0.24;0.31;0.36;0.42;0.5;0.55;0.62;0.68;0.75;0.81;0.88;0.94" calcMode="discrete" begin="loop.begin+16.6s" dur="1.2s" fill="freeze"/>
33
39
  </rect>
34
40
  </clipPath>
35
41
  </defs>
@@ -57,9 +63,9 @@
57
63
  </g>
58
64
  </g>
59
65
 
60
- <!-- Tab view: help bar for scenes 2 to 4 -->
66
+ <!-- Tab view: help bar for scenes 2 to 5 -->
61
67
  <g opacity="0">
62
- <set attributeName="opacity" to="1" begin="loop.begin+3.5s" dur="10.5s"/>
68
+ <set attributeName="opacity" to="1" begin="loop.begin+3.5s" dur="16.5s"/>
63
69
  <rect x="1" y="386" width="758" height="24" fill="#303030"/>
64
70
  <text x="14" y="403"><tspan class="dim">Switch: click or Shift+Tab | Scroll: history | </tspan><tspan class="white bold">[restart]</tspan><tspan class="dim"> | Quit: Ctrl-C twice</tspan></text>
65
71
  </g>
@@ -123,21 +129,57 @@
123
129
 
124
130
  <!-- Scene 4: Shift+Tab to the jobs tab, with Solid Queue -->
125
131
  <g opacity="0">
126
- <set attributeName="opacity" to="1" begin="loop.begin+10.5s" dur="3.5s"/>
132
+ <set attributeName="opacity" to="1" begin="loop.begin+10.5s" dur="4.5s"/>
127
133
  <rect x="1" y="40" width="758" height="24" fill="#303030"/>
128
134
  <rect x="168" y="40" width="76" height="24" fill="#005f87"/>
129
- <text x="22" y="57"><tspan class="green">●</tspan> web</text>
135
+ <g>
136
+ <set attributeName="opacity" to="0" begin="loop.begin+13.2s" dur="1.8s"/>
137
+ <text x="22" y="57"><tspan class="green">●</tspan> web</text>
138
+ </g>
139
+ <g opacity="0">
140
+ <set attributeName="opacity" to="1" begin="loop.begin+13.2s" dur="1.8s"/>
141
+ <text x="22" y="57"><tspan class="yellow">●</tspan> web</text>
142
+ <rect x="20" y="43" width="12" height="18" fill="#303030" opacity="0">
143
+ <animate attributeName="opacity" values="0;1" calcMode="discrete" begin="loop.begin+13.2s" dur="1s" repeatCount="2"/>
144
+ </rect>
145
+ </g>
130
146
  <text x="96" y="57"><tspan class="green">●</tspan> docs</text>
131
147
  <text x="178" y="57"><tspan class="green">●</tspan> <tspan class="white bold">jobs</tspan></text>
132
148
 
133
149
  <text x="20" y="92"><tspan class="magenta">SolidQueue-1.1.0</tspan> Started Supervisor (12.1ms) pid: 48213</text>
134
150
  <text x="20" y="114"><tspan class="magenta">SolidQueue-1.1.0</tspan> Started Dispatcher (4.2ms) pid: 48220, batch_size: 500</text>
135
151
  <text x="20" y="136"><tspan class="magenta">SolidQueue-1.1.0</tspan> Started Worker (3.9ms) pid: 48221, queues: *</text>
136
- <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+11.3s" dur="2.7s"/><text x="20" y="158">Performing <tspan class="yellow">WelcomeEmailJob</tspan> (Job ID: 7f3c9a) from SolidQueue(default)</text></g>
137
- <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+11.7s" dur="2.3s"/><text x="20" y="180"> Delivered mail to customer@shop.test (21.6ms)</text></g>
138
- <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.0s" dur="2.0s"/><text x="20" y="202">Performed <tspan class="yellow">WelcomeEmailJob</tspan> (Job ID: 7f3c9a) in <tspan class="green">38.2ms</tspan></text></g>
139
- <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.6s" dur="1.4s"/><text x="20" y="224">Performing <tspan class="yellow">OrderReceiptJob</tspan> (Job ID: 2b81d4) from SolidQueue(default)</text></g>
140
- <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.9s" dur="1.1s"/><text x="20" y="246">Performed <tspan class="yellow">OrderReceiptJob</tspan> (Job ID: 2b81d4) in <tspan class="green">22.7ms</tspan></text></g>
152
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+11.3s" dur="3.7s"/><text x="20" y="158">Performing <tspan class="yellow">WelcomeEmailJob</tspan> (Job ID: 7f3c9a) from SolidQueue(default)</text></g>
153
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+11.7s" dur="3.3s"/><text x="20" y="180"> Delivered mail to customer@shop.test (21.6ms)</text></g>
154
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.0s" dur="3.0s"/><text x="20" y="202">Performed <tspan class="yellow">WelcomeEmailJob</tspan> (Job ID: 7f3c9a) in <tspan class="green">38.2ms</tspan></text></g>
155
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.6s" dur="2.4s"/><text x="20" y="224">Performing <tspan class="yellow">OrderReceiptJob</tspan> (Job ID: 2b81d4) from SolidQueue(default)</text></g>
156
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+12.9s" dur="2.1s"/><text x="20" y="246">Performed <tspan class="yellow">OrderReceiptJob</tspan> (Job ID: 2b81d4) in <tspan class="green">22.7ms</tspan></text></g>
157
+ </g>
158
+
159
+ <!-- Scene 5: a click on the web tab, stopped at a debugger call -->
160
+ <g opacity="0">
161
+ <set attributeName="opacity" to="1" begin="loop.begin+15s" dur="5s"/>
162
+ <rect x="1" y="40" width="758" height="24" fill="#303030"/>
163
+ <rect x="12" y="40" width="70" height="24" fill="#005f87"/>
164
+ <text x="22" y="57"><tspan class="green">●</tspan> <tspan class="white bold">web</tspan></text>
165
+ <text x="96" y="57"><tspan class="green">●</tspan> docs</text>
166
+ <text x="178" y="57"><tspan class="green">●</tspan> jobs</text>
167
+ <text x="746" y="57" text-anchor="end" class="bar">https://shop.test</text>
168
+
169
+ <text x="20" y="92">Started <tspan class="cyan">POST</tspan> "/orders" for 127.0.0.1</text>
170
+ <text x="20" y="114">Processing by OrdersController#create as HTML</text>
171
+ <text x="20" y="136"> Parameters: {"order" =&gt; {"product_id" =&gt; "3", "quantity" =&gt; "2"}}</text>
172
+ <text x="20" y="158">[14, 18] in <tspan class="blue">~/shop/app/controllers/orders_controller.rb</tspan></text>
173
+ <text x="20" y="180"><tspan class="dim"> 14|</tspan> def create</text>
174
+ <text x="20" y="202"><tspan class="dim"> 15|</tspan> @order = Order.new(order_params)</text>
175
+ <text x="20" y="224"><tspan class="yellow">=&gt; 16|</tspan> <tspan class="magenta">debugger</tspan></text>
176
+ <text x="20" y="246"><tspan class="dim"> 17|</tspan> if @order.save</text>
177
+ <text x="20" y="268"><tspan class="dim"> 18|</tspan> redirect_to @order</text>
178
+ <text x="20" y="290"><tspan class="yellow">=&gt;#0</tspan> OrdersController#create at <tspan class="blue">~/shop/app/controllers/orders_controller.rb:16</tspan></text>
179
+ <text x="20" y="312"><tspan class="cyan">(rdbg)</tspan></text>
180
+ <text x="20" y="312" clip-path="url(#debugging)"> @order.quantity</text>
181
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+18s" dur="2s"/><text x="20" y="334">2</text></g>
182
+ <g opacity="0"><set attributeName="opacity" to="1" begin="loop.begin+18.2s" dur="1.8s"/><text x="20" y="356"><tspan class="cyan">(rdbg)</tspan></text></g>
141
183
  </g>
142
184
 
143
185
  <!-- Click ripple on the docs tab -->
@@ -146,6 +188,12 @@
146
188
  <animate attributeName="r" from="4" to="18" begin="loop.begin+7.3s" dur="0.6s"/>
147
189
  </circle>
148
190
 
191
+ <!-- Click ripple on the web tab -->
192
+ <circle cx="47" cy="52" r="4" fill="none" stroke="#ffffff" stroke-width="2" opacity="0">
193
+ <animate attributeName="opacity" values="0.9;0" begin="loop.begin+14.8s" dur="0.6s"/>
194
+ <animate attributeName="r" from="4" to="18" begin="loop.begin+14.8s" dur="0.6s"/>
195
+ </circle>
196
+
149
197
  <!-- Click ripple at the start of the drag -->
150
198
  <circle cx="20" cy="176" r="4" fill="none" stroke="#ffffff" stroke-width="2" opacity="0">
151
199
  <animate attributeName="opacity" values="0.9;0" begin="loop.begin+6.4s" dur="0.6s"/>
@@ -165,4 +213,11 @@
165
213
  <rect x="618" y="340" width="112" height="32" rx="7" fill="#c0caf5" stroke="#7aa2f7" stroke-width="2"/>
166
214
  <text x="674" y="361" text-anchor="middle" class="badge">Shift + Tab</text>
167
215
  </g>
216
+
217
+ <!-- Bell badge -->
218
+ <g opacity="0">
219
+ <set attributeName="opacity" to="1" begin="loop.begin+13.2s" dur="1.8s"/>
220
+ <rect x="574" y="340" width="156" height="32" rx="7" fill="#c0caf5" stroke="#e0af68" stroke-width="2"/>
221
+ <text x="652" y="361" text-anchor="middle" class="badge">Bell from debugger</text>
222
+ </g>
168
223
  </svg>
@@ -73,11 +73,12 @@ processes:
73
73
  bundle exec rake test
74
74
  ```
75
75
 
76
- The tests use Minitest and run hostty through `Hostty::CLI`, the same entry point as `exe/hostty`:
76
+ The tests use Minitest. Most run hostty through `Hostty::CLI`, the same entry point as `exe/hostty`:
77
77
 
78
78
  | Directory | What it tests |
79
79
  | --- | --- |
80
80
  | `test/cli/` | Hostty end to end: the config, the domains, plain output, the tabs, and stopping. |
81
+ | `test/contracts/` | The [front end and launcher contract](./architecture.md#front-ends), once for each front end and each launcher. A new one gets the same checks when its test class includes the contract module from `test/support/`. |
81
82
  | `test/ghostty/` | The screen of each tab, which Hostty reads from libghostty-vt. |
82
83
  | `test/support/` | Helpers for the tests above. |
83
84
 
@@ -35,9 +35,9 @@ flowchart TD
35
35
  | Namespace | Job |
36
36
  | --- | --- |
37
37
  | `Hostty::CLI` | Parses the options, picks the front end, and runs the steps in order. |
38
- | `Hostty::Config` | Reads `.hostty.yml`, checks every setting, and gives each process its environment. |
38
+ | `Hostty::Config` | Holds the processes and the startup notices. `Hostty::Config::Loader` reads `.hostty.yml`, checks every setting through the rules in `Hostty::Config::Rules`, and picks the ports. |
39
39
  | `Hostty::PortChooser` | Picks the port of each process, checks that it can open the port, and stops or moves on a clash. |
40
- | `Hostty::Domains` | Adds each domain through ruby-nginx. |
40
+ | `Hostty::Domains` | Builds the ruby-nginx options of each process with a domain, and adds the domain through ruby-nginx. |
41
41
  | `Hostty::Manager` | Starts the processes, waits for exit events, and runs the [stop sequence](../features/stopping.md). |
42
42
  | `Hostty::Plain` | The front end for [plain output](../features/plain-output.md). It runs each process on a pipe and prints its lines. |
43
43
  | `Hostty::Tui` | The front end for [tabs](../features/tabs.md). It runs each process in a pseudo-terminal and draws the tabs. |
@@ -77,15 +77,17 @@ Hostty adds the domains before the manager starts, so a prompt from ruby-nginx a
77
77
 
78
78
  `Hostty::Manager` does not know how a process shows its output. It asks the front end for two things:
79
79
 
80
- - A launcher for each process. The launcher starts the process and returns its process ID.
81
- - A wait, which returns when hostty should stop, with the exit code.
80
+ - A launcher for each process, from `launch_for(process)`:
81
+ - `start(process)` runs the process with its environment, including `PORT`, as the leader of its own process group, and returns its process ID. A signal to the group also reaches the children of the process.
82
+ - `finish` releases what the launcher holds, after the process exits.
83
+ - A wait, `wait(manager)`, which returns when hostty should stop, with the exit code of the stop event.
82
84
 
83
85
  | Front end | Launcher | Wait |
84
86
  | --- | --- | --- |
85
87
  | `Hostty::Plain` | Runs the process on a pipe, in its own process group, with stdin from `/dev/null`. A thread reads each line and prints it with the process name. | Returns at the first exit event or signal. |
86
88
  | `Hostty::Tui` | Runs the process in a pseudo-terminal, as the leader of its own session. | Runs the [tab event loop](#the-tab-event-loop) until you quit or a signal comes in. |
87
89
 
88
- Both launchers make the process the leader of its own process group, so a signal to the group also reaches its children.
90
+ The [contract tests](./README.md#tests) check this contract for each front end and launcher.
89
91
 
90
92
  ## Process Lifecycle
91
93
 
@@ -126,10 +128,10 @@ flowchart TD
126
128
  ```
127
129
 
128
130
  - One thread runs the loop. Only the exit waiters run on other threads.
129
- - The loop redraws at most about 60 times a second. A redraw writes only the rows that changed since the last frame, in one write.
131
+ - The loop redraws at most about 60 times a second. The screen is three regions in `Tui::Regions`: the tab bar, the pane view, and the help bar. Each region draws its rows and takes the clicks inside it. `Tui::Renderer` writes only the rows that changed since the last frame, in one write.
130
132
  - On start, the loop switches your terminal to raw mode, the alternate screen, and mouse reporting with drags. On exit, it restores all three, even after an error.
131
- - `Tui::Input` turns each mouse report into a `Tui::MouseEvent`. When the program in the selected tab turned on mouse reporting, events inside the tab go to the program. `Ghostty::Mouse` encodes them with the libghostty-vt mouse encoder, which follows the mouse mode and format that the program asked for. Without mouse reporting, a wheel step on the alternate screen becomes arrow keys, and on the main screen it scrolls the history.
132
- - A drag in the output makes a `Tui::Selection` on the selected pane. On release, `Tui::Desktop` copies the text. A click on the URL in the tab bar also goes to `Tui::Desktop`, which opens the URL in the browser. The CLI takes the desktop as an argument, so the tests pass a fake one.
133
+ - `Tui::Input` turns the bytes from stdin into events in `Tui::Events`, and the loop applies each one to `Tui::Controls`. Each mouse report becomes a `Tui::MouseEvent`. When the program in the selected tab turned on mouse reporting, events inside the tab go to the program. `Ghostty::Mouse` encodes them with the libghostty-vt mouse encoder, which follows the mouse mode and format that the program asked for. Without mouse reporting, a wheel step on the alternate screen becomes arrow keys, and on the main screen it scrolls the history.
134
+ - A drag in the output makes a `Tui::Selection` on the selected pane. `Tui::Mouse` tracks the drag in two states, idle and selecting. On release, `Tui::Desktop` copies the text. A click on the URL in the tab bar also goes to `Tui::Desktop`, which opens the URL in the browser. The CLI takes the desktop as an argument, so the tests pass a fake one.
133
135
  - The loop copies the application cursor keys mode and the bracketed paste mode of the selected tab to your terminal, so keys reach the process in the form it expects.
134
136
  - The loop checks the window size on each pass, at least 4 times a second. On a change, it resizes every emulator and every pseudo-terminal, and each process gets SIGWINCH.
135
137
 
@@ -142,18 +144,20 @@ flowchart LR
142
144
  lib -- "replies such as the cursor position" --> pty["Pseudo-terminal"]
143
145
  lib --> frame["Ghostty::Frame"]
144
146
  frame --> cells["Rows of Terminal::Cell"]
145
- cells --> renderer["Tui::Renderer"]
147
+ cells --> regions["Tui::Regions"]
148
+ regions --> renderer["Tui::Renderer"]
146
149
  ```
147
150
 
148
151
  | Part | Job |
149
152
  | --- | --- |
150
153
  | `Ghostty::Library` | The `ffi` bindings for the libghostty-vt functions that hostty calls. It loads the library from the gem first, then from `vendor/libghostty`, then from the system. |
151
154
  | `Ghostty::Screen` | Owns one libghostty-vt terminal per tab. It writes the process output into the terminal, and reads the cursor, the modes, and the scrollback size. It scrolls the terminal to the offset that the tab asks for. |
152
- | `Ghostty::Frame` | Reads the visible rows from a libghostty-vt render state into rows of `Terminal::Cell`. It skips a frame when nothing changed. |
155
+ | `Ghostty::Frame` | Keeps the libghostty-vt render state and the rows it read last. It skips a frame when nothing changed, and reads again only the rows that changed. |
156
+ | `Ghostty::CellReader` and `Ghostty::StyleDecoder` | Build each `Terminal::Cell` and its `Terminal::Style` from the render state. |
153
157
  | `Terminal::Cell` and `Terminal::Style` | A character with its width and its style. A style is a value that compares by its colors and attributes. |
154
158
 
155
159
  - libghostty-vt has no drawing and no pseudo-terminal. Hostty owns both.
156
- - `Ghostty::Frame` keeps one `Style` object for each set of colors and attributes, so `Tui::Renderer` writes a new SGR code only where the style changes.
160
+ - Styles and cells come from `Terminal::Flyweight` caches, so each set of colors and attributes has one `Style` object. The pane view writes a new SGR code only where that object changes.
157
161
  - Reading a frame costs about 1 ms at 80 by 24 and about 8 ms at 200 by 50, when every row changed. Hostty reads a frame only for the selected tab, at most about 60 times a second.
158
162
 
159
163
  The [terminal emulator](../features/terminal-emulator.md) page lists what works inside a tab.
data/lib/hostty/cli.rb CHANGED
@@ -54,7 +54,7 @@ module Hostty
54
54
  end
55
55
 
56
56
  def config
57
- @config ||= Config.new(path: options[:file], base_port: options[:port])
57
+ @config ||= Config::Loader.call(path: options[:file], base_port: options[:port])
58
58
  end
59
59
 
60
60
  def output
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ class Loader
6
+ class ProcessDefinition
7
+ def initialize(name:, settings:, default_port:, root_path:)
8
+ @name = name
9
+ @settings = settings
10
+ @default_port = default_port
11
+ @root_path = root_path
12
+ end
13
+
14
+ def fixed_port? = settings["port"].is_a?(Integer)
15
+
16
+ def validate!
17
+ Validator.call(Rules::ProcessSettings.new(name:, settings:))
18
+ Validator.call(
19
+ Rules::KnownSettings.new(owner: name, settings:, allowed: KEYS),
20
+ Rules::Command.new(name:, command: settings["command"]),
21
+ Rules::PortSetting.new(name:, port: preferred_port),
22
+ Rules::Domain.new(name:, domain: settings["domain"]),
23
+ Rules::PathSettings.new(name:, settings:),
24
+ Rules::Env.new(name:, env: settings.fetch("env", {}))
25
+ )
26
+ end
27
+
28
+ def choose_port(port_chooser)
29
+ port_chooser.choose(name:, preferred: preferred_port, movable: !fixed_port?)
30
+ end
31
+
32
+ def build(port:)
33
+ ProcessConfig.new(name:, settings:, port:, root_path:)
34
+ end
35
+
36
+ def self.parse(name:, settings:, default_port:, root_path:)
37
+ new(
38
+ name:,
39
+ settings: settings.is_a?(String) ? {"command" => settings} : settings,
40
+ default_port:,
41
+ root_path:
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ KEYS = %w[command domain port ssl log host root template env].freeze
48
+ private_constant :KEYS
49
+
50
+ attr_reader :name, :settings, :default_port, :root_path
51
+
52
+ def preferred_port = settings.fetch("port", default_port)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ class Loader
6
+ def initialize(path:, base_port:)
7
+ @path = File.expand_path(path)
8
+ @base_port = base_port
9
+ end
10
+
11
+ def call
12
+ validate_file!
13
+ definitions.each(&:validate!)
14
+ Validator.call(Rules::UniqueDomains.new(processes:))
15
+ Config.new(processes:, notices: port_chooser.notices)
16
+ end
17
+
18
+ def self.call(...) = new(...).call
19
+
20
+ private
21
+
22
+ PORT_STEP = 100
23
+ KEYS = %w[processes skip_used_ports].freeze
24
+ private_constant :PORT_STEP, :KEYS
25
+
26
+ attr_reader :path, :base_port
27
+
28
+ def process_data = data["processes"]
29
+
30
+ def skip_used_ports = data.fetch("skip_used_ports", false)
31
+
32
+ def data
33
+ @data ||= YAML.safe_load_file(path)
34
+ rescue Errno::ENOENT
35
+ raise ConfigError, "No config file at #{path}."
36
+ rescue Psych::Exception => e
37
+ raise ConfigError, "The config file at #{path} is not valid YAML: #{e.message}"
38
+ end
39
+
40
+ def validate_file!
41
+ Validator.call(Rules::SettingsList.new(data:, path:))
42
+ Validator.call(
43
+ Rules::ProcessList.new(processes: process_data, path:),
44
+ Rules::KnownSettings.new(owner: "The config file at #{path}", settings: data, allowed: KEYS)
45
+ )
46
+ Validator.call(Rules::SkipUsedPorts.new(skip_used_ports:))
47
+ end
48
+
49
+ def definitions
50
+ @definitions ||=
51
+ process_data.each_with_index.map do |(name, settings), index|
52
+ ProcessDefinition.parse(
53
+ name: name.to_s,
54
+ settings:,
55
+ default_port: base_port + (index * PORT_STEP),
56
+ root_path: File.dirname(path)
57
+ )
58
+ end
59
+ end
60
+
61
+ def port_chooser
62
+ @port_chooser ||= PortChooser.new(skip_used_ports:)
63
+ end
64
+
65
+ def ports
66
+ @ports ||=
67
+ definitions
68
+ .partition(&:fixed_port?)
69
+ .flatten
70
+ .to_h { |definition| [definition, definition.choose_port(port_chooser)] }
71
+ end
72
+
73
+ def processes
74
+ @processes ||= definitions.map { |definition| definition.build(port: ports.fetch(definition)) }
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class Command
7
+ def initialize(name:, command:)
8
+ @name = name
9
+ @command = command
10
+ end
11
+
12
+ def valid? = Text.new(command).present?
13
+
14
+ def message = "#{name} needs a command."
15
+
16
+ private
17
+
18
+ attr_reader :name, :command
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class Domain
7
+ def initialize(name:, domain:)
8
+ @name = name
9
+ @domain = domain
10
+ end
11
+
12
+ def valid?
13
+ domain.nil? || Text.new(domain).present?
14
+ end
15
+
16
+ def message = "#{name} needs a text value for its domain."
17
+
18
+ private
19
+
20
+ attr_reader :name, :domain
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class Env
7
+ def initialize(name:, env:)
8
+ @name = name
9
+ @env = env
10
+ end
11
+
12
+ def valid? = env.is_a?(Hash)
13
+
14
+ def message = "#{name} needs a list of names and values for its env."
15
+
16
+ private
17
+
18
+ attr_reader :name, :env
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class KnownSettings
7
+ def initialize(owner:, settings:, allowed:)
8
+ @owner = owner
9
+ @settings = settings
10
+ @allowed = allowed
11
+ end
12
+
13
+ def valid? = unknown_keys.empty?
14
+
15
+ def message = "#{owner} has unknown settings: #{unknown_keys.join(", ")}."
16
+
17
+ private
18
+
19
+ attr_reader :owner, :settings, :allowed
20
+
21
+ def unknown_keys
22
+ @unknown_keys ||= settings.keys.map(&:to_s) - allowed
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class PathSettings
7
+ def initialize(name:, settings:)
8
+ @name = name
9
+ @settings = settings
10
+ end
11
+
12
+ def valid? = invalid_keys.empty?
13
+
14
+ def message = "#{name} needs a text value for its #{invalid_keys.join(" and ")}."
15
+
16
+ private
17
+
18
+ KEYS = %w[root template].freeze
19
+ private_constant :KEYS
20
+
21
+ attr_reader :name, :settings
22
+
23
+ def invalid_keys
24
+ @invalid_keys ||= KEYS.select { |key| settings.key?(key) && !Text.new(settings[key]).present? }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class PortSetting
7
+ def initialize(name:, port:)
8
+ @name = name
9
+ @port = port
10
+ end
11
+
12
+ def valid?
13
+ port == "random" || (port.is_a?(Integer) && PORTS.cover?(port))
14
+ end
15
+
16
+ def message = "#{name} needs a port from 1 to 65535, or \"random\"."
17
+
18
+ private
19
+
20
+ PORTS = 1..65_535
21
+ private_constant :PORTS
22
+
23
+ attr_reader :name, :port
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class ProcessList
7
+ def initialize(processes:, path:)
8
+ @processes = processes
9
+ @path = path
10
+ end
11
+
12
+ def valid?
13
+ processes.is_a?(Hash) && processes.any?
14
+ end
15
+
16
+ def message = "The config file at #{path} must list at least one process under processes."
17
+
18
+ private
19
+
20
+ attr_reader :processes, :path
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class ProcessSettings
7
+ def initialize(name:, settings:)
8
+ @name = name
9
+ @settings = settings
10
+ end
11
+
12
+ def valid? = settings.is_a?(Hash)
13
+
14
+ def message = "#{name} must be a command or a list of settings."
15
+
16
+ private
17
+
18
+ attr_reader :name, :settings
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class SettingsList
7
+ def initialize(data:, path:)
8
+ @data = data
9
+ @path = path
10
+ end
11
+
12
+ def valid? = data.is_a?(Hash)
13
+
14
+ def message = "The config file at #{path} must be a list of settings."
15
+
16
+ private
17
+
18
+ attr_reader :data, :path
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ class Config
5
+ module Rules
6
+ class SkipUsedPorts
7
+ def initialize(skip_used_ports:)
8
+ @skip_used_ports = skip_used_ports
9
+ end
10
+
11
+ def valid? = [true, false].include?(skip_used_ports)
12
+
13
+ def message = "skip_used_ports must be true or false."
14
+
15
+ private
16
+
17
+ attr_reader :skip_used_ports
18
+ end
19
+ end
20
+ end
21
+ end