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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Terminal
5
+ class Flyweight
6
+ def initialize
7
+ @objects = {}
8
+ end
9
+
10
+ def fetch(key)
11
+ @objects.clear if @objects.size > LIMIT
12
+ @objects[key] ||= yield
13
+ end
14
+
15
+ LIMIT = 1024
16
+ private_constant :LIMIT
17
+ end
18
+ end
19
+ end
@@ -43,12 +43,11 @@ module Hostty
43
43
  end
44
44
 
45
45
  def self.shared(attributes)
46
- styles.clear if styles.size > SHARED_LIMIT
47
- styles[attributes.values] ||= new(**attributes)
46
+ styles.fetch(attributes.values) { new(**attributes) }
48
47
  end
49
48
 
50
49
  def self.styles
51
- @styles ||= {plain.to_h.values => plain}
50
+ @styles ||= Flyweight.new.tap { |styles| styles.fetch(plain.to_h.values) { plain } }
52
51
  end
53
52
  private_class_method :styles
54
53
 
@@ -65,8 +64,7 @@ module Hostty
65
64
  strikethrough: 9,
66
65
  overline: 53
67
66
  }.freeze
68
- SHARED_LIMIT = 1024
69
- private_constant :FLAG_CODES, :SHARED_LIMIT
67
+ private_constant :FLAG_CODES
70
68
 
71
69
  def color_codes(color, base:, extended:)
72
70
  case color
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Activity
6
+ def initialize(tabs:, canvas:, controls:)
7
+ @tabs = tabs
8
+ @canvas = canvas
9
+ @controls = controls
10
+ end
11
+
12
+ def output(pane)
13
+ canvas.invalidate if tabs.selected?(pane)
14
+ end
15
+
16
+ def bell
17
+ controls.ring
18
+ canvas.invalidate
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :tabs, :canvas, :controls
24
+ end
25
+ end
26
+ end
@@ -7,301 +7,90 @@ module Hostty
7
7
  @stdin = stdin
8
8
  @stdout = stdout
9
9
  @desktop = desktop
10
- @rows, @cols = stdout.winsize
11
- @panes = []
12
- @selected = 0
13
- @input = Input.new
14
- @renderer = Renderer.new(io: stdout)
15
- @outer_modes = {}
16
- @focused = true
10
+ rows, cols = stdout.winsize
11
+ @layout = Layout.new(rows:, cols:)
12
+ @tabs = Tabs.new
13
+ @clock = Clock.new
17
14
  end
18
15
 
19
16
  def launch_for(process)
20
- Pane.new(name: process.name, url: process.url, rows: rows - 2, cols:).tap { |pane| panes << pane }
17
+ Pane.new(name: process.name, url: process.url, rows: layout.pane_rows, cols: layout.cols).tap { |pane| tabs.add(pane) }
21
18
  end
22
19
 
23
20
  def wait(manager)
24
- with_terminal do
25
- until @exit_code
26
- wait_for_io(manager)
27
- autoscroll_when_due
28
- blink_when_due
29
- check_size
30
- render_when_due
31
- end
32
- end
33
-
34
- @exit_code
21
+ @manager = manager
22
+ tabs.each { |pane| pane.subscribe(activity) }
23
+ with_terminal { cycle until outcome.decided? }
24
+ outcome.exit_code
35
25
  end
36
26
 
37
27
  private
38
28
 
39
- FRAME_SECONDS = 0.016
40
- IDLE_SECONDS = 0.25
41
- DOUBLE_PRESS_SECONDS = 0.5
42
- SCROLL_LINES = 3
43
- AUTOSCROLL_SECONDS = 0.025
44
- AUTOSCROLL_SPEEDUP_SECONDS = 0.5
45
- AUTOSCROLL_MAX_LINES = 10
46
- BLINK_SECONDS = 0.5
47
29
  ENTER = "\e[?1049h\e[?1002h\e[?1006h\e[?1004h\e[?25l\e[2J"
48
30
  LEAVE = "\e[?1004l\e[?1006l\e[?1002l\e[?2004l\e[?1l\e[0m\e[?25h\e[?1049l"
49
- OUTER_MODES = {application_cursor_keys?: 1, bracketed_paste?: 2004}.freeze
50
- private_constant :FRAME_SECONDS, :IDLE_SECONDS, :DOUBLE_PRESS_SECONDS, :SCROLL_LINES, :AUTOSCROLL_SECONDS, :AUTOSCROLL_SPEEDUP_SECONDS, :AUTOSCROLL_MAX_LINES, :BLINK_SECONDS, :ENTER, :LEAVE, :OUTER_MODES
51
-
52
- attr_reader :stdin, :stdout, :desktop, :rows, :cols, :panes, :input, :renderer
31
+ private_constant :ENTER, :LEAVE
53
32
 
54
- def selected = panes[@selected]
55
-
56
- def bell? = panes.any?(&:bell?)
57
-
58
- def layout
59
- @layout ||= Layout.new(names: panes.map(&:name), rows:, cols:)
60
- end
33
+ attr_reader :stdin, :stdout, :desktop, :layout, :tabs, :clock, :manager
61
34
 
62
35
  def with_terminal
63
36
  stdin.raw do
64
37
  stdout.write(ENTER)
65
- @dirty = true
66
38
  yield
67
39
  ensure
68
40
  stdout.write(LEAVE)
69
41
  end
70
42
  end
71
43
 
72
- def wait_for_io(manager)
73
- readable, = IO.select([stdin, manager.wakeup_io, *panes.filter_map(&:io)], nil, nil, select_timeout)
74
- Array(readable).each { |io| handle(io, manager) }
75
- end
76
-
77
- def handle(io, manager)
78
- if io == stdin
79
- read_input(manager)
80
- elsif io == manager.wakeup_io
81
- read_events(manager)
82
- else
83
- read_output(panes.find { |pane| pane.io == io })
84
- end
44
+ def cycle
45
+ reactor.react(timeout: duties.filter_map(&:wait).min)
46
+ duties.each(&:tick)
85
47
  end
86
48
 
87
- def read_input(manager)
88
- data = stdin.read_nonblock(4096, exception: false)
89
- return if data == :wait_readable
90
- return quit unless data
91
-
92
- input.parse(data).each { |event| apply(event, manager) }
93
- @dirty = true
49
+ def outcome
50
+ @outcome ||= Outcome.new
94
51
  end
95
52
 
96
- def apply(event, manager)
97
- case event
98
- in [:interrupt, bytes]
99
- interrupt(bytes)
100
- in [:next_tab]
101
- @selected = (@selected + 1) % panes.size
102
- in [:focus, focused]
103
- @focused = focused
104
- selected.send_focus(focused)
105
- in [:keys, bytes]
106
- selected.write(bytes)
107
- in [:mouse, mouse]
108
- handle_mouse(mouse, manager)
109
- end
53
+ def tab_bar
54
+ @tab_bar ||= Regions::TabBar.new(tabs:, layout:, desktop:)
110
55
  end
111
56
 
112
- def handle_mouse(mouse, manager)
113
- return selected.send_mouse(mouse.at(row: mouse.row - 1)) if program_mouse?(mouse)
114
- return wheel(mouse) if mouse.wheel?
115
- return unless mouse.button == :left
116
-
117
- case mouse.action
118
- when :press
119
- click(mouse.row, mouse.col, manager)
120
- when :motion
121
- drag(mouse) if @selecting
122
- when :release
123
- finish_selection(mouse.row, mouse.col) if @selecting
124
- end
57
+ def display
58
+ @display ||= Display.new(tab_bar:, tabs:, layout:, manager:)
125
59
  end
126
60
 
127
- def program_mouse?(mouse)
128
- !@selecting && !mouse.shift? && pane_row?(mouse.row) && selected.screen.mouse_tracking?
61
+ def canvas
62
+ @canvas ||= Canvas.new(io: stdout, tabs:, display:, clock:)
129
63
  end
130
64
 
131
- def pane_row?(row) = (1..layout.pane_rows).cover?(row)
132
-
133
- def drag(mouse)
134
- @pointer = pane_point(mouse.row, mouse.col)
135
- direction = autoscroll_direction(mouse.row)
136
- @autoscroll_started_at = clock unless direction == @autoscroll
137
- @autoscroll = direction
138
- selected.select_to(**@pointer)
65
+ def pointer
66
+ @pointer ||= Mouse::Pointer.new(target: Mouse::Target.new(tabs:, layout:, desktop:, display:), canvas:, clock:)
139
67
  end
140
68
 
141
- def autoscroll_direction(row)
142
- if row < 1
143
- 1
144
- elsif row > layout.pane_rows
145
- -1
146
- end
69
+ def controls
70
+ @controls ||= Controls.new(tabs:, desktop:, pointer:, clock:)
147
71
  end
148
72
 
149
- def autoscroll_when_due
150
- return unless @selecting && @autoscroll && clock - @autoscrolled_at.to_f >= AUTOSCROLL_SECONDS
151
-
152
- @autoscrolled_at = clock
153
- selected.scroll(@autoscroll * autoscroll_lines)
154
- selected.select_to(**@pointer)
155
- @dirty = true
73
+ def activity
74
+ @activity ||= Activity.new(tabs:, canvas:, controls:)
156
75
  end
157
76
 
158
- def blink_when_due
159
- return unless bell? && clock - @blinked_at.to_f >= BLINK_SECONDS
160
-
161
- @blinked_at = clock
162
- renderer.blink
163
- @dirty = true
164
- end
165
-
166
- def blink_wait
167
- (@blinked_at.to_f + BLINK_SECONDS - clock).clamp(0, BLINK_SECONDS)
168
- end
169
-
170
- def autoscroll_lines
171
- (1 + ((clock - @autoscroll_started_at) / AUTOSCROLL_SPEEDUP_SECONDS).floor).clamp(1, AUTOSCROLL_MAX_LINES)
172
- end
173
-
174
- def wheel(mouse)
175
- up = mouse.button == :wheel_up
176
- return selected.write(arrow_key(up) * SCROLL_LINES) if selected.screen.alternate_screen?
177
-
178
- selected.scroll(up ? SCROLL_LINES : -SCROLL_LINES)
179
- selected.select_to(**@pointer) if @selecting && @pointer
180
- end
181
-
182
- def arrow_key(up)
183
- prefix = selected.screen.application_cursor_keys? ? "\eO" : "\e["
184
- "#{prefix}#{up ? "A" : "B"}"
185
- end
186
-
187
- def finish_selection(row, col)
188
- @selecting = false
189
- @autoscroll = nil
190
- selected.select_to(**pane_point(row, col))
191
- copy_selection
192
- end
193
-
194
- def pane_point(row, col)
195
- {row: (row - 1).clamp(0, layout.pane_rows - 1), col: col.clamp(0, cols - 1)}
196
- end
197
-
198
- def copy_selection
199
- text = selected.selected_text
200
- desktop.copy(text) if text
201
- end
202
-
203
- def interrupt(bytes)
204
- return quit if @interrupted_at && clock - @interrupted_at <= DOUBLE_PRESS_SECONDS
205
-
206
- @interrupted_at = clock
207
- selected.write(bytes)
208
- end
209
-
210
- def click(row, col, manager)
211
- index = layout.tab_at(row:, col:)
212
- return @selected = index if index
213
- return desktop.open(selected.url) if layout.url_at?(row:, col:, url: selected.url)
214
- return restart(selected, manager) if layout.restart_at?(row:, col:, offset: selected.offset)
215
-
216
- return unless pane_row?(row)
217
-
218
- @selecting = true
219
- @pointer = pane_point(row, col)
220
- selected.select_from(**@pointer)
221
- end
222
-
223
- def restart(pane, manager)
224
- return manager.start(pane.name) unless pane.running?
225
-
226
- pane.request_restart
227
- manager.terminate(pane.name)
228
- end
229
-
230
- def read_events(manager)
231
- while (event = manager.next_event(timeout: 0))
232
- return @exit_code = event.exit_code if event.interrupt?
233
-
234
- pane = panes.find { |candidate| candidate.name == event.name }
235
- pane.exited(event.exit_code)
236
- relay_bell(pane)
237
- manager.start(pane.name) if pane.take_restart_request
238
- @dirty = true
239
- end
240
- end
241
-
242
- def read_output(pane)
243
- return unless pane
244
-
245
- @dirty = true if pane.read && pane.equal?(selected)
246
- relay_bell(pane)
247
- end
248
-
249
- def relay_bell(pane)
250
- return unless pane.take_ring
251
-
252
- desktop.ring unless @focused
253
- @dirty = true
254
- end
255
-
256
- def quit
257
- @exit_code = 0
258
- end
259
-
260
- def check_size
261
- size = stdout.winsize
262
- return if size == [rows, cols]
263
-
264
- @rows, @cols = size
265
- @layout = nil
266
- panes.each { |pane| pane.resize(rows: rows - 2, cols:) }
267
- renderer.reset
268
- @dirty = true
269
- end
270
-
271
- def render_when_due
272
- return unless @dirty && frame_due?
273
-
274
- sync_outer_modes
275
- selected.clear_bell
276
- renderer.render(layout:, panes:, selected:)
277
- @dirty = false
278
- @rendered_at = clock
279
- end
280
-
281
- def frame_due?
282
- @rendered_at.nil? || clock - @rendered_at >= FRAME_SECONDS
283
- end
284
-
285
- def select_timeout
286
- return AUTOSCROLL_SECONDS if @selecting && @autoscroll && !@dirty
287
- return blink_wait if bell? && !@dirty
288
- return IDLE_SECONDS unless @dirty
289
-
290
- [FRAME_SECONDS - (clock - (@rendered_at || 0)), 0].max
291
- end
292
-
293
- def sync_outer_modes
294
- OUTER_MODES.each do |query, mode|
295
- enabled = selected.screen.public_send(query)
296
- next if @outer_modes[mode] == enabled
297
-
298
- stdout.write("\e[?#{mode}#{enabled ? "h" : "l"}")
299
- @outer_modes[mode] = enabled
300
- end
77
+ def duties
78
+ @duties ||= [
79
+ pointer,
80
+ Blink.new(tabs:, tab_bar:, canvas:, clock:),
81
+ Window.new(io: stdout, layout:, tabs:, canvas:),
82
+ canvas
83
+ ]
301
84
  end
302
85
 
303
- def clock
304
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
86
+ def reactor
87
+ @reactor ||= Reactor.new(
88
+ sources: [
89
+ Sources::Stdin.new(io: stdin, controls:, canvas:, outcome:),
90
+ Sources::ManagerEvents.new(manager:, tabs:, canvas:, outcome:),
91
+ *tabs
92
+ ]
93
+ )
305
94
  end
306
95
  end
307
96
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Bell
6
+ def initialize
7
+ @ringing = false
8
+ @rang = false
9
+ end
10
+
11
+ def ringing? = @ringing
12
+
13
+ def call
14
+ @ringing = true
15
+ @rang = true
16
+ end
17
+
18
+ def relay(listener)
19
+ return unless @rang
20
+
21
+ @rang = false
22
+ listener.bell
23
+ end
24
+
25
+ def silence
26
+ @ringing = false
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Blink
6
+ def initialize(tabs:, tab_bar:, canvas:, clock:)
7
+ @tabs = tabs
8
+ @tab_bar = tab_bar
9
+ @canvas = canvas
10
+ @timer = Timer.new(seconds: SECONDS, clock:)
11
+ end
12
+
13
+ def wait
14
+ timer.wait if ringing?
15
+ end
16
+
17
+ def tick
18
+ timer.fire { flash } if ringing?
19
+ end
20
+
21
+ private
22
+
23
+ SECONDS = 0.5
24
+ private_constant :SECONDS
25
+
26
+ attr_reader :tabs, :tab_bar, :canvas, :timer
27
+
28
+ def ringing? = tabs.any?(&:bell?)
29
+
30
+ def flash
31
+ tab_bar.blink
32
+ canvas.invalidate
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Canvas
6
+ def initialize(io:, tabs:, display:, clock:)
7
+ @tabs = tabs
8
+ @display = display
9
+ @renderer = Renderer.new(io:)
10
+ @outer_modes = OuterModes.new(io:)
11
+ @frame = Timer.new(seconds: FRAME_SECONDS, clock:)
12
+ @dirty = true
13
+ end
14
+
15
+ def invalidate
16
+ @dirty = true
17
+ end
18
+
19
+ def reset
20
+ renderer.reset
21
+ invalidate
22
+ end
23
+
24
+ def wait
25
+ frame.wait if dirty?
26
+ end
27
+
28
+ def tick
29
+ frame.fire { draw } if dirty?
30
+ end
31
+
32
+ private
33
+
34
+ FRAME_SECONDS = 0.016
35
+ private_constant :FRAME_SECONDS
36
+
37
+ attr_reader :tabs, :display, :renderer, :outer_modes, :frame
38
+
39
+ def dirty? = @dirty
40
+
41
+ def selected = tabs.selected
42
+
43
+ def draw
44
+ outer_modes.sync(selected.screen)
45
+ selected.clear_bell
46
+ renderer.render(display)
47
+ @dirty = false
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Clock
6
+ def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Controls
6
+ def initialize(tabs:, desktop:, pointer:, clock:)
7
+ @tabs = tabs
8
+ @desktop = desktop
9
+ @pointer = pointer
10
+ @clock = clock
11
+ @focused = true
12
+ @quit = false
13
+ end
14
+
15
+ def quit? = @quit
16
+
17
+ def type(bytes)
18
+ selected.write(bytes)
19
+ end
20
+
21
+ def interrupt(bytes)
22
+ return @quit = true if double_press?
23
+
24
+ @interrupted_at = clock.now
25
+ selected.write(bytes)
26
+ end
27
+
28
+ def select_next
29
+ tabs.select_next
30
+ end
31
+
32
+ def focus(focused)
33
+ @focused = focused
34
+ selected.send_focus(focused)
35
+ end
36
+
37
+ def mouse(event)
38
+ pointer.handle(event)
39
+ end
40
+
41
+ def ring
42
+ desktop.ring unless @focused
43
+ end
44
+
45
+ private
46
+
47
+ DOUBLE_PRESS_SECONDS = 0.5
48
+ private_constant :DOUBLE_PRESS_SECONDS
49
+
50
+ attr_reader :tabs, :desktop, :pointer, :clock
51
+
52
+ def selected = tabs.selected
53
+
54
+ def double_press?
55
+ !@interrupted_at.nil? && clock.now - @interrupted_at <= DOUBLE_PRESS_SECONDS
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ class Display
6
+ def initialize(tab_bar:, tabs:, layout:, manager:)
7
+ @regions = [
8
+ tab_bar,
9
+ Regions::PaneView.new(tabs:, layout:),
10
+ Regions::HelpBar.new(tabs:, layout:, manager:)
11
+ ]
12
+ end
13
+
14
+ def rows = regions.flat_map(&:rows)
15
+
16
+ def cursor = regions.lazy.filter_map(&:cursor).first
17
+
18
+ def press(row:, col:, &)
19
+ regions.any? { |region| region.press(row:, col:, &) }
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :regions
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ module Events
6
+ class Focus
7
+ def initialize(focused:)
8
+ @focused = focused
9
+ end
10
+
11
+ def apply(controls) = controls.focus(focused)
12
+
13
+ private
14
+
15
+ attr_reader :focused
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ module Events
6
+ class Interrupt
7
+ def initialize(bytes:)
8
+ @bytes = bytes
9
+ end
10
+
11
+ def apply(controls) = controls.interrupt(bytes)
12
+
13
+ private
14
+
15
+ attr_reader :bytes
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hostty
4
+ module Tui
5
+ module Events
6
+ class Keys
7
+ def initialize(bytes:)
8
+ @bytes = bytes
9
+ end
10
+
11
+ def apply(controls) = controls.type(bytes)
12
+
13
+ private
14
+
15
+ attr_reader :bytes
16
+ end
17
+ end
18
+ end
19
+ end