hostty 1.0.0 → 1.1.0

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/docs/assets/demo.svg +405 -126
  3. data/docs/features/stopping.md +12 -2
  4. data/lib/hostty/cli.rb +5 -1
  5. data/lib/hostty/config/loader.rb +4 -1
  6. data/lib/hostty/config/rules/path_settings.rb +3 -1
  7. data/lib/hostty/config/validator.rb +5 -1
  8. data/lib/hostty/ghostty/cell_reader.rb +1 -0
  9. data/lib/hostty/ghostty/mouse.rb +3 -1
  10. data/lib/hostty/ghostty/screen.rb +5 -1
  11. data/lib/hostty/ghostty/style_decoder.rb +3 -1
  12. data/lib/hostty/manager/child.rb +4 -1
  13. data/lib/hostty/manager/countdown.rb +39 -0
  14. data/lib/hostty/manager/events.rb +3 -1
  15. data/lib/hostty/manager.rb +47 -17
  16. data/lib/hostty/output.rb +8 -2
  17. data/lib/hostty/plain/app.rb +4 -1
  18. data/lib/hostty/plain/pipe.rb +9 -2
  19. data/lib/hostty/port_chooser.rb +18 -3
  20. data/lib/hostty/terminal/cell.rb +3 -1
  21. data/lib/hostty/terminal/style.rb +22 -5
  22. data/lib/hostty/tui/app.rb +14 -3
  23. data/lib/hostty/tui/blink.rb +5 -1
  24. data/lib/hostty/tui/canvas.rb +5 -1
  25. data/lib/hostty/tui/desktop.rb +11 -3
  26. data/lib/hostty/tui/display.rb +3 -1
  27. data/lib/hostty/tui/input.rb +7 -1
  28. data/lib/hostty/tui/mouse/idle.rb +4 -1
  29. data/lib/hostty/tui/mouse/pointer.rb +4 -1
  30. data/lib/hostty/tui/mouse/selecting.rb +4 -1
  31. data/lib/hostty/tui/mouse/target.rb +3 -1
  32. data/lib/hostty/tui/pane.rb +8 -1
  33. data/lib/hostty/tui/pty.rb +14 -0
  34. data/lib/hostty/tui/reactor.rb +4 -1
  35. data/lib/hostty/tui/regions/pane_view.rb +4 -1
  36. data/lib/hostty/tui/regions/tab_bar.rb +18 -4
  37. data/lib/hostty/tui/renderer.rb +5 -1
  38. data/lib/hostty/tui/selection.rb +3 -1
  39. data/lib/hostty/tui/sources/stdin.rb +4 -1
  40. data/lib/hostty/tui/tabs.rb +3 -1
  41. data/lib/hostty/tui/window.rb +5 -1
  42. data/lib/hostty/version.rb +1 -1
  43. data/lib/hostty.rb +1 -0
  44. metadata +2 -1
@@ -32,6 +32,10 @@ module Hostty
32
32
  pty.start(process, rows:, cols:)
33
33
  end
34
34
 
35
+ def discard_output
36
+ pty.discard
37
+ end
38
+
35
39
  def finish
36
40
  pty.close
37
41
  end
@@ -126,7 +130,10 @@ module Hostty
126
130
 
127
131
  range.step(rows).each_with_object({}) do |first, lines|
128
132
  page_offset = (size - first).clamp(0, size)
129
- screen.lines(offset: page_offset).each_with_index { |cells, index| lines[size - page_offset + index] = cells }
133
+
134
+ screen.lines(offset: page_offset).each_with_index do |cells, index|
135
+ lines[size - page_offset + index] = cells
136
+ end
130
137
  end
131
138
  end
132
139
  end
@@ -45,6 +45,14 @@ module Hostty
45
45
  nil
46
46
  end
47
47
 
48
+ def discard
49
+ if reader
50
+ Thread.new(reader) do |io|
51
+ discard_until_closed(io)
52
+ end
53
+ end
54
+ end
55
+
48
56
  def close
49
57
  [reader, writer].compact.reject(&:closed?).each(&:close)
50
58
  @reader = nil
@@ -57,6 +65,12 @@ module Hostty
57
65
  private_constant :READ_SIZE
58
66
 
59
67
  attr_reader :writer
68
+
69
+ def discard_until_closed(io)
70
+ nil while io.readpartial(READ_SIZE)
71
+ rescue Errno::EIO, IOError
72
+ nil
73
+ end
60
74
  end
61
75
  end
62
76
  end
@@ -9,7 +9,10 @@ module Hostty
9
9
 
10
10
  def react(timeout:)
11
11
  readable = Array(IO.select(sources.filter_map(&:io), nil, nil, timeout)&.first)
12
- sources.each { |source| source.read if readable.include?(source.io) }
12
+
13
+ sources.each do |source|
14
+ source.read if readable.include?(source.io)
15
+ end
13
16
  end
14
17
 
15
18
  private
@@ -11,7 +11,10 @@ module Hostty
11
11
 
12
12
  def rows
13
13
  pane = tabs.selected
14
- pane.lines.each_with_index.map { |cells, row| line_text(cells, pane.selected_columns(row, cells.size)) }
14
+
15
+ pane.lines.each_with_index.map do |cells, row|
16
+ line_text(cells, pane.selected_columns(row, cells.size))
17
+ end
15
18
  end
16
19
 
17
20
  def press(row:, col:)
@@ -40,7 +40,11 @@ module Hostty
40
40
 
41
41
  def selected = tabs.selected
42
42
 
43
- def tabs_width(spans) = spans.sum { |span| span[:width] }
43
+ def tabs_width(spans)
44
+ spans.sum do |span|
45
+ span[:width]
46
+ end
47
+ end
44
48
 
45
49
  def tab_spans
46
50
  start = 0
@@ -49,7 +53,9 @@ module Hostty
49
53
  width = pane.name.length + 4
50
54
  next if start + width > layout.cols
51
55
 
52
- {index:, pane:, start:, width:}.tap { start += width }
56
+ {index:, pane:, start:, width:}.tap do
57
+ start += width
58
+ end
53
59
  end
54
60
  end
55
61
 
@@ -62,7 +68,11 @@ module Hostty
62
68
  end
63
69
 
64
70
  def tab_row(spans, start)
65
- text = spans.map { |span| tab_label(span[:pane]) }.join
71
+ text =
72
+ spans
73
+ .map { |span| tab_label(span[:pane]) }
74
+ .join
75
+
66
76
  return "#{text}#{Palette::BAR}#{" " * (layout.cols - tabs_width(spans))}#{Palette::RESET}" unless start
67
77
 
68
78
  "#{text}#{Palette::BAR}#{" " * (start - tabs_width(spans))}#{selected.url} #{Palette::RESET}"
@@ -80,7 +90,11 @@ module Hostty
80
90
  end
81
91
 
82
92
  def select_tab(spans, col)
83
- span = spans.find { |candidate| (candidate[:start]...candidate[:start] + candidate[:width]).cover?(col) }
93
+ span =
94
+ spans.find do |candidate|
95
+ (candidate[:start]...candidate[:start] + candidate[:width]).cover?(col)
96
+ end
97
+
84
98
  return false unless span
85
99
 
86
100
  tabs.select_at(span[:index])
@@ -15,7 +15,11 @@ module Hostty
15
15
  def render(display)
16
16
  rows = display.rows
17
17
  frame = +""
18
- rows.each_with_index { |row, index| frame << "\e[#{index + 1};1H#{row}" unless @previous[index] == row }
18
+
19
+ rows.each_with_index do |row, index|
20
+ frame << "\e[#{index + 1};1H#{row}" unless @previous[index] == row
21
+ end
22
+
19
23
  @previous = rows
20
24
  io.write(frame << cursor(display.cursor))
21
25
  end
@@ -28,7 +28,9 @@ module Hostty
28
28
  end
29
29
 
30
30
  def text(lines)
31
- rows.map { |row| row_text(lines[row] || [], row) }.join("\n")
31
+ rows
32
+ .map { |row| row_text(lines[row] || [], row) }
33
+ .join("\n")
32
34
  end
33
35
 
34
36
  private
@@ -19,7 +19,10 @@ module Hostty
19
19
  return if data == :wait_readable
20
20
  return outcome.decide(0) unless data
21
21
 
22
- input.parse(data).each { |event| event.apply(controls) }
22
+ input.parse(data).each do |event|
23
+ event.apply(controls)
24
+ end
25
+
23
26
  outcome.decide(0) if controls.quit?
24
27
  canvas.invalidate
25
28
  end
@@ -29,7 +29,9 @@ module Hostty
29
29
  end
30
30
 
31
31
  def named(name)
32
- find { |pane| pane.name == name }
32
+ find do |pane|
33
+ pane.name == name
34
+ end
33
35
  end
34
36
 
35
37
  private
@@ -17,7 +17,11 @@ module Hostty
17
17
  return if [rows, cols] == [layout.rows, layout.cols]
18
18
 
19
19
  layout.resize(rows:, cols:)
20
- tabs.each { |pane| pane.resize(rows: layout.pane_rows, cols:) }
20
+
21
+ tabs.each do |pane|
22
+ pane.resize(rows: layout.pane_rows, cols:)
23
+ end
24
+
21
25
  canvas.reset
22
26
  end
23
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hostty
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/hostty.rb CHANGED
@@ -38,6 +38,7 @@ require_relative "hostty/manager/events"
38
38
  require_relative "hostty/manager/process_exited"
39
39
  require_relative "hostty/manager/signal_received"
40
40
  require_relative "hostty/manager/child"
41
+ require_relative "hostty/manager/countdown"
41
42
  require_relative "hostty/manager"
42
43
  require_relative "hostty/plain/pipe"
43
44
  require_relative "hostty/plain/app"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hostty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bert McCutchen
@@ -98,6 +98,7 @@ files:
98
98
  - lib/hostty/ghostty/style_decoder.rb
99
99
  - lib/hostty/manager.rb
100
100
  - lib/hostty/manager/child.rb
101
+ - lib/hostty/manager/countdown.rb
101
102
  - lib/hostty/manager/events.rb
102
103
  - lib/hostty/manager/process_exited.rb
103
104
  - lib/hostty/manager/signal_received.rb