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.
- checksums.yaml +4 -4
- data/docs/assets/demo.svg +68 -13
- data/docs/development/README.md +2 -1
- data/docs/development/architecture.md +15 -11
- data/lib/hostty/cli.rb +1 -1
- data/lib/hostty/config/loader/process_definition.rb +56 -0
- data/lib/hostty/config/loader.rb +78 -0
- data/lib/hostty/config/rules/command.rb +22 -0
- data/lib/hostty/config/rules/domain.rb +24 -0
- data/lib/hostty/config/rules/env.rb +22 -0
- data/lib/hostty/config/rules/known_settings.rb +27 -0
- data/lib/hostty/config/rules/path_settings.rb +29 -0
- data/lib/hostty/config/rules/port_setting.rb +27 -0
- data/lib/hostty/config/rules/process_list.rb +24 -0
- data/lib/hostty/config/rules/process_settings.rb +22 -0
- data/lib/hostty/config/rules/settings_list.rb +22 -0
- data/lib/hostty/config/rules/skip_used_ports.rb +21 -0
- data/lib/hostty/config/rules/text.rb +21 -0
- data/lib/hostty/config/rules/unique_domains.rb +30 -0
- data/lib/hostty/config/validator.rb +22 -0
- data/lib/hostty/config.rb +4 -67
- data/lib/hostty/domains/nginx_options.rb +37 -0
- data/lib/hostty/domains.rb +1 -1
- data/lib/hostty/ghostty/cell_reader.rb +68 -0
- data/lib/hostty/ghostty/frame.rb +7 -149
- data/lib/hostty/ghostty/raw_cell.rb +43 -0
- data/lib/hostty/ghostty/screen.rb +3 -0
- data/lib/hostty/ghostty/style_decoder.rb +44 -0
- data/lib/hostty/process_config.rb +15 -67
- data/lib/hostty/terminal/cell.rb +2 -2
- data/lib/hostty/terminal/flyweight.rb +19 -0
- data/lib/hostty/terminal/style.rb +3 -5
- data/lib/hostty/tui/activity.rb +26 -0
- data/lib/hostty/tui/app.rb +43 -254
- data/lib/hostty/tui/bell.rb +30 -0
- data/lib/hostty/tui/blink.rb +36 -0
- data/lib/hostty/tui/canvas.rb +51 -0
- data/lib/hostty/tui/clock.rb +9 -0
- data/lib/hostty/tui/controls.rb +59 -0
- data/lib/hostty/tui/display.rb +27 -0
- data/lib/hostty/tui/events/focus.rb +19 -0
- data/lib/hostty/tui/events/interrupt.rb +19 -0
- data/lib/hostty/tui/events/keys.rb +19 -0
- data/lib/hostty/tui/events/mouse_report.rb +19 -0
- data/lib/hostty/tui/events/next_tab.rb +11 -0
- data/lib/hostty/tui/input.rb +7 -7
- data/lib/hostty/tui/layout.rb +8 -49
- data/lib/hostty/tui/lifecycle/exited.rb +20 -0
- data/lib/hostty/tui/lifecycle/pending.rb +17 -0
- data/lib/hostty/tui/lifecycle/restarting.rb +20 -0
- data/lib/hostty/tui/lifecycle/running.rb +20 -0
- data/lib/hostty/tui/lifecycle.rb +38 -0
- data/lib/hostty/tui/mouse/idle.rb +37 -0
- data/lib/hostty/tui/mouse/pointer.rb +45 -0
- data/lib/hostty/tui/mouse/selecting.rb +67 -0
- data/lib/hostty/tui/mouse/target.rb +78 -0
- data/lib/hostty/tui/outcome.rb +15 -0
- data/lib/hostty/tui/outer_modes.rb +29 -0
- data/lib/hostty/tui/pane.rb +30 -42
- data/lib/hostty/tui/reactor.rb +20 -0
- data/lib/hostty/tui/regions/help_bar.rb +48 -0
- data/lib/hostty/tui/regions/palette.rb +12 -0
- data/lib/hostty/tui/regions/pane_view.rb +60 -0
- data/lib/hostty/tui/regions/tab_bar.rb +100 -0
- data/lib/hostty/tui/renderer.rb +6 -67
- data/lib/hostty/tui/sources/manager_events.rb +31 -0
- data/lib/hostty/tui/sources/stdin.rb +33 -0
- data/lib/hostty/tui/tabs.rb +40 -0
- data/lib/hostty/tui/timer.rb +33 -0
- data/lib/hostty/tui/window.rb +32 -0
- data/lib/hostty/version.rb +1 -1
- data/lib/hostty.rb +50 -0
- metadata +54 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
module Events
|
|
6
|
+
class MouseReport
|
|
7
|
+
def initialize(mouse:)
|
|
8
|
+
@mouse = mouse
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def apply(controls) = controls.mouse(mouse)
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
attr_reader :mouse
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/hostty/tui/input.rb
CHANGED
|
@@ -34,14 +34,14 @@ module Hostty
|
|
|
34
34
|
|
|
35
35
|
def next_event
|
|
36
36
|
index = @pending.index(SPECIAL)
|
|
37
|
-
return
|
|
38
|
-
return
|
|
39
|
-
return take(SHIFT_TAB.size) &&
|
|
40
|
-
return take(FOCUS_IN.size) &&
|
|
41
|
-
return take(FOCUS_OUT.size) &&
|
|
37
|
+
return Events::Keys.new(bytes: take(index || @pending.size)) unless index&.zero?
|
|
38
|
+
return Events::Interrupt.new(bytes: take(1)) if @pending.start_with?(CTRL_C)
|
|
39
|
+
return take(SHIFT_TAB.size) && Events::NextTab.new if @pending.start_with?(SHIFT_TAB)
|
|
40
|
+
return take(FOCUS_IN.size) && Events::Focus.new(focused: true) if @pending.start_with?(FOCUS_IN)
|
|
41
|
+
return take(FOCUS_OUT.size) && Events::Focus.new(focused: false) if @pending.start_with?(FOCUS_OUT)
|
|
42
42
|
|
|
43
43
|
match = MOUSE.match(@pending)
|
|
44
|
-
return
|
|
44
|
+
return Events::Keys.new(bytes: take(@pending.size)) unless match
|
|
45
45
|
|
|
46
46
|
take(match[0].size)
|
|
47
47
|
mouse_event(match)
|
|
@@ -60,7 +60,7 @@ module Hostty
|
|
|
60
60
|
col: match[2].to_i - 1,
|
|
61
61
|
modifiers: MODIFIER_BITS.filter_map { |name, bit| name if code.anybits?(bit) }
|
|
62
62
|
)
|
|
63
|
-
|
|
63
|
+
Events::MouseReport.new(mouse: event) if event.button
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def mouse_action(code, final)
|
data/lib/hostty/tui/layout.rb
CHANGED
|
@@ -3,66 +3,25 @@
|
|
|
3
3
|
module Hostty
|
|
4
4
|
module Tui
|
|
5
5
|
class Layout
|
|
6
|
-
RESTART_BUTTON = "[restart]"
|
|
7
|
-
|
|
8
6
|
attr_reader :rows, :cols
|
|
9
7
|
|
|
10
|
-
def initialize(
|
|
11
|
-
@names = names
|
|
8
|
+
def initialize(rows:, cols:)
|
|
12
9
|
@rows = rows
|
|
13
10
|
@cols = cols
|
|
14
11
|
end
|
|
15
12
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
def help_row = rows - 1
|
|
19
|
-
|
|
20
|
-
def tabs_width = tabs.sum { |tab| tab[:width] }
|
|
21
|
-
|
|
22
|
-
def tabs
|
|
23
|
-
@tabs ||= begin
|
|
24
|
-
start = 0
|
|
25
|
-
|
|
26
|
-
names.each_with_index.filter_map do |name, index|
|
|
27
|
-
width = name.length + 4
|
|
28
|
-
next if start + width > cols
|
|
29
|
-
|
|
30
|
-
{index:, start:, width:}.tap { start += width }
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def url_start(url)
|
|
36
|
-
return unless url
|
|
37
|
-
|
|
38
|
-
start = cols - url.length - 1
|
|
39
|
-
start if start > tabs_width
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def url_at?(row:, col:, url:)
|
|
43
|
-
start = url_start(url)
|
|
44
|
-
row.zero? && !start.nil? && (start...(start + url.length)).cover?(col)
|
|
45
|
-
end
|
|
13
|
+
def pane_row?(row) = (1..pane_rows).cover?(row)
|
|
46
14
|
|
|
47
|
-
def
|
|
48
|
-
return unless row.zero?
|
|
49
|
-
|
|
50
|
-
tabs.find { |tab| (tab[:start]...tab[:start] + tab[:width]).cover?(col) }&.fetch(:index)
|
|
51
|
-
end
|
|
15
|
+
def pane_rows = rows - 2
|
|
52
16
|
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
" Switch: click or Shift+Tab | #{scroll} | #{RESTART_BUTTON} | Quit: Ctrl-C twice "
|
|
17
|
+
def pane_point(row:, col:)
|
|
18
|
+
{row: (row - 1).clamp(0, pane_rows - 1), col: col.clamp(0, cols - 1)}
|
|
56
19
|
end
|
|
57
20
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
21
|
+
def resize(rows:, cols:)
|
|
22
|
+
@rows = rows
|
|
23
|
+
@cols = cols
|
|
61
24
|
end
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
attr_reader :names
|
|
66
25
|
end
|
|
67
26
|
end
|
|
68
27
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Lifecycle
|
|
6
|
+
class Exited
|
|
7
|
+
def running? = false
|
|
8
|
+
|
|
9
|
+
def restart(lifecycle, manager) = manager.start(lifecycle.name)
|
|
10
|
+
|
|
11
|
+
def exited(_lifecycle, manager:) = nil
|
|
12
|
+
|
|
13
|
+
def start(lifecycle)
|
|
14
|
+
lifecycle.notify("\e[2m[hostty] Starting #{lifecycle.name}.")
|
|
15
|
+
lifecycle.become(Running.new)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Lifecycle
|
|
6
|
+
class Pending
|
|
7
|
+
def running? = false
|
|
8
|
+
|
|
9
|
+
def start(lifecycle) = lifecycle.become(Running.new)
|
|
10
|
+
|
|
11
|
+
def restart(lifecycle, manager) = manager.start(lifecycle.name)
|
|
12
|
+
|
|
13
|
+
def exited(lifecycle, manager:) = lifecycle.become(Exited.new)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Lifecycle
|
|
6
|
+
class Restarting
|
|
7
|
+
def running? = true
|
|
8
|
+
|
|
9
|
+
def start(_lifecycle) = nil
|
|
10
|
+
|
|
11
|
+
def restart(lifecycle, manager) = manager.terminate(lifecycle.name)
|
|
12
|
+
|
|
13
|
+
def exited(lifecycle, manager:)
|
|
14
|
+
lifecycle.become(Exited.new)
|
|
15
|
+
manager.start(lifecycle.name)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Lifecycle
|
|
6
|
+
class Running
|
|
7
|
+
def running? = true
|
|
8
|
+
|
|
9
|
+
def start(_lifecycle) = nil
|
|
10
|
+
|
|
11
|
+
def exited(lifecycle, manager:) = lifecycle.become(Exited.new)
|
|
12
|
+
|
|
13
|
+
def restart(lifecycle, manager)
|
|
14
|
+
lifecycle.become(Restarting.new)
|
|
15
|
+
manager.terminate(lifecycle.name)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Lifecycle
|
|
6
|
+
attr_reader :name
|
|
7
|
+
|
|
8
|
+
def initialize(name:, screen:)
|
|
9
|
+
@name = name
|
|
10
|
+
@screen = screen
|
|
11
|
+
@state = Pending.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def running? = state.running?
|
|
15
|
+
|
|
16
|
+
def start = state.start(self)
|
|
17
|
+
|
|
18
|
+
def restart(manager) = state.restart(self, manager)
|
|
19
|
+
|
|
20
|
+
def exited(exit_code, manager:)
|
|
21
|
+
notify("\e[31m[hostty] #{name} exited with code #{exit_code}.")
|
|
22
|
+
state.exited(self, manager:)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def become(state)
|
|
26
|
+
@state = state
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def notify(text)
|
|
30
|
+
screen.feed("\e[0m\r\n#{text}\e[0m\r\n")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
attr_reader :screen, :state
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
module Mouse
|
|
6
|
+
class Idle
|
|
7
|
+
def initialize(clock:)
|
|
8
|
+
@clock = clock
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def forward(event, target) = target.forward(event)
|
|
12
|
+
|
|
13
|
+
def wait = nil
|
|
14
|
+
|
|
15
|
+
def motion(_event, _target) = self
|
|
16
|
+
|
|
17
|
+
def release(_event, _target) = self
|
|
18
|
+
|
|
19
|
+
def tick(_target) = self
|
|
20
|
+
|
|
21
|
+
def press(event, target)
|
|
22
|
+
target.press(event) { |pointer| return Selecting.new(pointer:, clock:) }
|
|
23
|
+
self
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def wheel(event, target)
|
|
27
|
+
target.wheel(event)
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :clock
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
module Mouse
|
|
6
|
+
class Pointer
|
|
7
|
+
def initialize(target:, canvas:, clock:)
|
|
8
|
+
@target = target
|
|
9
|
+
@canvas = canvas
|
|
10
|
+
@state = Idle.new(clock:)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def wait = state.wait
|
|
14
|
+
|
|
15
|
+
def handle(event)
|
|
16
|
+
return if state.forward(event, target)
|
|
17
|
+
|
|
18
|
+
@state = transition(event)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def tick
|
|
22
|
+
@state = state.tick(target) { canvas.invalidate }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :state, :target, :canvas
|
|
28
|
+
|
|
29
|
+
def transition(event)
|
|
30
|
+
return state.wheel(event, target) if event.wheel?
|
|
31
|
+
return state unless event.button == :left
|
|
32
|
+
|
|
33
|
+
case event.action
|
|
34
|
+
when :press
|
|
35
|
+
state.press(event, target)
|
|
36
|
+
when :motion
|
|
37
|
+
state.motion(event, target)
|
|
38
|
+
when :release
|
|
39
|
+
state.release(event, target)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
module Mouse
|
|
6
|
+
class Selecting
|
|
7
|
+
def initialize(pointer:, clock:)
|
|
8
|
+
@pointer = pointer
|
|
9
|
+
@clock = clock
|
|
10
|
+
@autoscroll = Timer.new(seconds: AUTOSCROLL_SECONDS, clock:)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def forward(_event, _target) = false
|
|
14
|
+
|
|
15
|
+
def wait
|
|
16
|
+
AUTOSCROLL_SECONDS if @direction
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def press(event, target)
|
|
20
|
+
target.press(event) { |point| @pointer = point }
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def motion(event, target)
|
|
25
|
+
@pointer = target.drag(event)
|
|
26
|
+
direction = target.direction(event)
|
|
27
|
+
@started_at = clock.now unless direction == @direction
|
|
28
|
+
@direction = direction
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def release(event, target)
|
|
33
|
+
target.release(event)
|
|
34
|
+
Idle.new(clock:)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def wheel(event, target)
|
|
38
|
+
target.wheel(event, pointer:)
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def tick(target)
|
|
43
|
+
return self unless @direction
|
|
44
|
+
|
|
45
|
+
autoscroll.fire do
|
|
46
|
+
target.autoscroll(lines: @direction * lines, pointer:)
|
|
47
|
+
yield
|
|
48
|
+
end
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
AUTOSCROLL_SECONDS = 0.025
|
|
55
|
+
SPEEDUP_SECONDS = 0.5
|
|
56
|
+
MAX_LINES = 10
|
|
57
|
+
private_constant :AUTOSCROLL_SECONDS, :SPEEDUP_SECONDS, :MAX_LINES
|
|
58
|
+
|
|
59
|
+
attr_reader :pointer, :clock, :autoscroll
|
|
60
|
+
|
|
61
|
+
def lines
|
|
62
|
+
(1 + ((clock.now - @started_at) / SPEEDUP_SECONDS).floor).clamp(1, MAX_LINES)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
module Mouse
|
|
6
|
+
class Target
|
|
7
|
+
def initialize(tabs:, layout:, desktop:, display:)
|
|
8
|
+
@tabs = tabs
|
|
9
|
+
@layout = layout
|
|
10
|
+
@desktop = desktop
|
|
11
|
+
@display = display
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def forward(event)
|
|
15
|
+
return false unless program_mouse?(event)
|
|
16
|
+
|
|
17
|
+
selected.send_mouse(event.at(row: event.row - 1))
|
|
18
|
+
true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def press(event, &)
|
|
22
|
+
display.press(row: event.row, col: event.col, &)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def drag(event)
|
|
26
|
+
point(event).tap { |point| selected.select_to(**point) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def release(event)
|
|
30
|
+
selected.select_to(**point(event))
|
|
31
|
+
text = selected.selected_text
|
|
32
|
+
desktop.copy(text) if text
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def wheel(event, pointer: nil)
|
|
36
|
+
up = event.button == :wheel_up
|
|
37
|
+
return selected.write(arrow_key(up) * SCROLL_LINES) if selected.screen.alternate_screen?
|
|
38
|
+
|
|
39
|
+
selected.scroll(up ? SCROLL_LINES : -SCROLL_LINES)
|
|
40
|
+
selected.select_to(**pointer) if pointer
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def autoscroll(lines:, pointer:)
|
|
44
|
+
selected.scroll(lines)
|
|
45
|
+
selected.select_to(**pointer)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def direction(event)
|
|
49
|
+
if event.row < 1
|
|
50
|
+
1
|
|
51
|
+
elsif event.row > layout.pane_rows
|
|
52
|
+
-1
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
SCROLL_LINES = 3
|
|
59
|
+
private_constant :SCROLL_LINES
|
|
60
|
+
|
|
61
|
+
attr_reader :tabs, :layout, :desktop, :display
|
|
62
|
+
|
|
63
|
+
def selected = tabs.selected
|
|
64
|
+
|
|
65
|
+
def point(event) = layout.pane_point(row: event.row, col: event.col)
|
|
66
|
+
|
|
67
|
+
def program_mouse?(event)
|
|
68
|
+
!event.shift? && layout.pane_row?(event.row) && selected.screen.mouse_tracking?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def arrow_key(up)
|
|
72
|
+
prefix = selected.screen.application_cursor_keys? ? "\eO" : "\e["
|
|
73
|
+
"#{prefix}#{up ? "A" : "B"}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class OuterModes
|
|
6
|
+
def initialize(io:)
|
|
7
|
+
@io = io
|
|
8
|
+
@enabled = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def sync(screen)
|
|
12
|
+
MODES.each do |query, mode|
|
|
13
|
+
enabled = screen.public_send(query)
|
|
14
|
+
next if @enabled[mode] == enabled
|
|
15
|
+
|
|
16
|
+
io.write("\e[?#{mode}#{enabled ? "h" : "l"}")
|
|
17
|
+
@enabled[mode] = enabled
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
MODES = {application_cursor_keys?: 1, bracketed_paste?: 2004}.freeze
|
|
24
|
+
private_constant :MODES
|
|
25
|
+
|
|
26
|
+
attr_reader :io
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/hostty/tui/pane.rb
CHANGED
|
@@ -11,23 +11,24 @@ module Hostty
|
|
|
11
11
|
@rows = rows
|
|
12
12
|
@cols = cols
|
|
13
13
|
@pty = Pty.new
|
|
14
|
-
@
|
|
14
|
+
@bell = Bell.new
|
|
15
|
+
@screen = Ghostty::Screen.new(rows:, cols:, reply: pty, bell:)
|
|
16
|
+
@lifecycle = Lifecycle.new(name:, screen:)
|
|
15
17
|
@offset = 0
|
|
16
|
-
@running = false
|
|
17
|
-
@bell = false
|
|
18
|
-
@rang = false
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def running? =
|
|
20
|
+
def running? = lifecycle.running?
|
|
22
21
|
|
|
23
|
-
def bell? =
|
|
22
|
+
def bell? = bell.ringing?
|
|
24
23
|
|
|
25
24
|
def io = pty.reader
|
|
26
25
|
|
|
26
|
+
def subscribe(listener)
|
|
27
|
+
@listener = listener
|
|
28
|
+
end
|
|
29
|
+
|
|
27
30
|
def start(process)
|
|
28
|
-
|
|
29
|
-
@exit_code = nil
|
|
30
|
-
@running = true
|
|
31
|
+
lifecycle.start
|
|
31
32
|
pty.start(process, rows:, cols:)
|
|
32
33
|
end
|
|
33
34
|
|
|
@@ -36,9 +37,18 @@ module Hostty
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def read
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
listener.output(self) if pull
|
|
41
|
+
bell.relay(listener)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def exited(exit_code, manager:)
|
|
45
|
+
nil while pull && io
|
|
46
|
+
lifecycle.exited(exit_code, manager:)
|
|
47
|
+
bell.relay(listener)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def restart(manager)
|
|
51
|
+
lifecycle.restart(manager)
|
|
42
52
|
end
|
|
43
53
|
|
|
44
54
|
def write(data)
|
|
@@ -72,27 +82,8 @@ module Hostty
|
|
|
72
82
|
selection.text(history_lines(selection.rows)) if selecting?
|
|
73
83
|
end
|
|
74
84
|
|
|
75
|
-
def exited(exit_code)
|
|
76
|
-
nil while read && io
|
|
77
|
-
@exit_code = exit_code
|
|
78
|
-
@running = false
|
|
79
|
-
notify("\e[31m[hostty] #{name} exited with code #{exit_code}.")
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def request_restart
|
|
83
|
-
@restart_requested = true
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def take_restart_request
|
|
87
|
-
@restart_requested.tap { @restart_requested = false }
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def take_ring
|
|
91
|
-
@rang.tap { @rang = false }
|
|
92
|
-
end
|
|
93
|
-
|
|
94
85
|
def clear_bell
|
|
95
|
-
|
|
86
|
+
bell.silence
|
|
96
87
|
end
|
|
97
88
|
|
|
98
89
|
def scroll(lines)
|
|
@@ -114,12 +105,18 @@ module Hostty
|
|
|
114
105
|
|
|
115
106
|
private
|
|
116
107
|
|
|
117
|
-
attr_reader :rows, :cols, :pty, :selection
|
|
108
|
+
attr_reader :rows, :cols, :pty, :bell, :lifecycle, :listener, :selection
|
|
118
109
|
|
|
119
110
|
def selecting?
|
|
120
111
|
!selection.nil? && !selection.empty?
|
|
121
112
|
end
|
|
122
113
|
|
|
114
|
+
def pull
|
|
115
|
+
data = pty.read
|
|
116
|
+
screen.feed(data) if data
|
|
117
|
+
!data&.empty?
|
|
118
|
+
end
|
|
119
|
+
|
|
123
120
|
def history_row(row)
|
|
124
121
|
screen.scrollback_size - offset + row
|
|
125
122
|
end
|
|
@@ -132,15 +129,6 @@ module Hostty
|
|
|
132
129
|
screen.lines(offset: page_offset).each_with_index { |cells, index| lines[size - page_offset + index] = cells }
|
|
133
130
|
end
|
|
134
131
|
end
|
|
135
|
-
|
|
136
|
-
def ring
|
|
137
|
-
@bell = true
|
|
138
|
-
@rang = true
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def notify(text)
|
|
142
|
-
screen.feed("\e[0m\r\n#{text}\e[0m\r\n")
|
|
143
|
-
end
|
|
144
132
|
end
|
|
145
133
|
end
|
|
146
134
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Tui
|
|
5
|
+
class Reactor
|
|
6
|
+
def initialize(sources:)
|
|
7
|
+
@sources = sources
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def react(timeout:)
|
|
11
|
+
readable = Array(IO.select(sources.filter_map(&:io), nil, nil, timeout)&.first)
|
|
12
|
+
sources.each { |source| source.read if readable.include?(source.io) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader :sources
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|