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,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
class Config
|
|
5
|
+
module Rules
|
|
6
|
+
class Text
|
|
7
|
+
def initialize(value)
|
|
8
|
+
@value = value
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def present?
|
|
12
|
+
value.is_a?(String) && !value.strip.empty?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader :value
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
class Config
|
|
5
|
+
module Rules
|
|
6
|
+
class UniqueDomains
|
|
7
|
+
def initialize(processes:)
|
|
8
|
+
@processes = processes
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def valid? = duplicates.empty?
|
|
12
|
+
|
|
13
|
+
def message = "More than one process uses the domain #{duplicates.join(", ")}."
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader :processes
|
|
18
|
+
|
|
19
|
+
def duplicates
|
|
20
|
+
@duplicates ||=
|
|
21
|
+
processes
|
|
22
|
+
.filter_map(&:domain)
|
|
23
|
+
.tally
|
|
24
|
+
.select { |_domain, count| count > 1 }
|
|
25
|
+
.keys
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
class Config
|
|
5
|
+
class Validator
|
|
6
|
+
def initialize(*rules)
|
|
7
|
+
@rules = rules
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
failure = rules.find { |rule| !rule.valid? }
|
|
12
|
+
raise ConfigError, failure.message if failure
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.call(...) = new(...).call
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
attr_reader :rules
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/hostty/config.rb
CHANGED
|
@@ -5,74 +5,11 @@ module Hostty
|
|
|
5
5
|
FILE_NAME = ".hostty.yml"
|
|
6
6
|
BASE_PORT = 5000
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
@path = File.expand_path(path)
|
|
10
|
-
@base_port = base_port
|
|
11
|
-
validate!
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def processes
|
|
15
|
-
@processes ||=
|
|
16
|
-
process_data.each_with_index.map do |(name, settings), index|
|
|
17
|
-
ProcessConfig.new(
|
|
18
|
-
name: name.to_s,
|
|
19
|
-
settings:,
|
|
20
|
-
default_port: base_port + (index * PORT_STEP),
|
|
21
|
-
root_path: File.dirname(path),
|
|
22
|
-
ports: port_chooser
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def notices = port_chooser.notices
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
PORT_STEP = 100
|
|
32
|
-
KEYS = %w[processes skip_used_ports].freeze
|
|
33
|
-
private_constant :PORT_STEP, :KEYS
|
|
34
|
-
|
|
35
|
-
attr_reader :path, :base_port
|
|
36
|
-
|
|
37
|
-
def data
|
|
38
|
-
@data ||= YAML.safe_load_file(path)
|
|
39
|
-
rescue Errno::ENOENT
|
|
40
|
-
raise ConfigError, "No config file at #{path}."
|
|
41
|
-
rescue Psych::Exception => e
|
|
42
|
-
raise ConfigError, "The config file at #{path} is not valid YAML: #{e.message}"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def process_data = data["processes"]
|
|
46
|
-
|
|
47
|
-
def skip_used_ports = data.fetch("skip_used_ports", false)
|
|
48
|
-
|
|
49
|
-
def port_chooser
|
|
50
|
-
@port_chooser ||= PortChooser.new(skip_used_ports:)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def validate!
|
|
54
|
-
validate_shape!
|
|
55
|
-
raise ConfigError, "skip_used_ports must be true or false." unless [true, false].include?(skip_used_ports)
|
|
56
|
-
|
|
57
|
-
processes.partition(&:fixed_port?).flatten.each(&:port)
|
|
58
|
-
raise_on_duplicate_domains
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def validate_shape!
|
|
62
|
-
raise ConfigError, "The config file at #{path} must be a list of settings." unless data.is_a?(Hash)
|
|
63
|
-
raise ConfigError, "The config file at #{path} must list at least one process under processes." unless process_data.is_a?(Hash) && process_data.any?
|
|
64
|
-
raise ConfigError, "The config file at #{path} has unknown settings: #{unknown_keys.join(", ")}." if unknown_keys.any?
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def unknown_keys
|
|
68
|
-
data.keys.map(&:to_s) - KEYS
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def raise_on_duplicate_domains
|
|
72
|
-
duplicates = processes.filter_map(&:domain).tally.select { |_domain, count| count > 1 }.keys
|
|
73
|
-
return if duplicates.empty?
|
|
8
|
+
attr_reader :processes, :notices
|
|
74
9
|
|
|
75
|
-
|
|
10
|
+
def initialize(processes:, notices:)
|
|
11
|
+
@processes = processes
|
|
12
|
+
@notices = notices
|
|
76
13
|
end
|
|
77
14
|
end
|
|
78
15
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
class Domains
|
|
5
|
+
class NginxOptions
|
|
6
|
+
def initialize(process:)
|
|
7
|
+
@process = process
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_h
|
|
11
|
+
{
|
|
12
|
+
domain: process.domain,
|
|
13
|
+
port: process.port,
|
|
14
|
+
root_path: static_root,
|
|
15
|
+
template_path: template&.path,
|
|
16
|
+
host: process.host,
|
|
17
|
+
ssl: process.ssl,
|
|
18
|
+
log: process.log
|
|
19
|
+
}.compact
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_reader :process
|
|
25
|
+
|
|
26
|
+
def template
|
|
27
|
+
@template ||= NginxTemplate.new(name: process.template, base_path: process.root_path) if process.template
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def static_root
|
|
31
|
+
return File.expand_path(process.root, process.root_path) if process.root
|
|
32
|
+
|
|
33
|
+
template&.static_root || process.root_path
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/hostty/domains.rb
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Ghostty
|
|
5
|
+
class CellReader
|
|
6
|
+
def initialize(cells:)
|
|
7
|
+
@cells = cells
|
|
8
|
+
@raw_cell = RawCell.new
|
|
9
|
+
@style_decoder = StyleDecoder.new
|
|
10
|
+
@narrow_cells = Terminal::Flyweight.new
|
|
11
|
+
@raw_memory = FFI::MemoryPointer.new(:uint64)
|
|
12
|
+
@style_memory = FFI::MemoryPointer.new(:uint8, 16)
|
|
13
|
+
@text_memory = FFI::MemoryPointer.new(:uint8, TEXT_CAPACITY)
|
|
14
|
+
@text_buffer =
|
|
15
|
+
Library::Buffer.new.tap do |buffer|
|
|
16
|
+
buffer[:ptr] = text_memory
|
|
17
|
+
buffer[:cap] = TEXT_CAPACITY
|
|
18
|
+
end
|
|
19
|
+
@keys = FFI::MemoryPointer.new(:int, KEYS.size).write_array_of_int(KEYS)
|
|
20
|
+
@values = FFI::MemoryPointer.new(:pointer, KEYS.size).write_array_of_pointer([raw_memory, style_memory, text_buffer.pointer])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def read
|
|
24
|
+
result = Library.ghostty_render_state_row_cells_get_multi(cells, KEYS.size, keys, values, nil)
|
|
25
|
+
build((result == Library::SUCCESS) ? text : "�", style_memory.get_bytes(0, 16))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
KEYS = [Library::ROW_CELLS_DATA_RAW, Library::ROW_CELLS_DATA_STYLE, Library::ROW_CELLS_DATA_GRAPHEMES_UTF8].freeze
|
|
31
|
+
TEXT_CAPACITY = 256
|
|
32
|
+
private_constant :KEYS, :TEXT_CAPACITY
|
|
33
|
+
|
|
34
|
+
attr_reader :cells, :raw_cell, :style_decoder, :narrow_cells, :raw_memory, :style_memory, :text_memory, :text_buffer, :keys, :values
|
|
35
|
+
|
|
36
|
+
def text
|
|
37
|
+
text_memory.get_bytes(0, text_buffer[:len]).force_encoding(Encoding::UTF_8)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def build(text, style_bytes)
|
|
41
|
+
return narrow(text, style_bytes) if text.bytesize == 1
|
|
42
|
+
|
|
43
|
+
raw_cell.load(raw_memory.read_uint64)
|
|
44
|
+
|
|
45
|
+
case raw_cell.wide
|
|
46
|
+
when Library::CELL_WIDE_SPACER_TAIL
|
|
47
|
+
Terminal::Cell.continuation(style_decoder.decode(style_bytes))
|
|
48
|
+
when Library::CELL_WIDE_WIDE
|
|
49
|
+
Terminal::Cell.new(char: text, style: style_decoder.decode(style_bytes), width: 2)
|
|
50
|
+
else
|
|
51
|
+
text.empty? ? blank(style_bytes) : Terminal::Cell.new(char: text, style: style_decoder.decode(style_bytes))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def narrow(text, style_bytes)
|
|
56
|
+
cells_by_text = narrow_cells.fetch(style_bytes) { {} }
|
|
57
|
+
cells_by_text[text] ||= Terminal::Cell.new(char: text, style: style_decoder.decode(style_bytes))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def blank(style_bytes)
|
|
61
|
+
background = raw_cell.background
|
|
62
|
+
return narrow(" ", style_bytes) unless background
|
|
63
|
+
|
|
64
|
+
Terminal::Cell.blank(Terminal::Style.shared(style_decoder.decode(style_bytes).to_h.merge(bg: background)))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
data/lib/hostty/ghostty/frame.rb
CHANGED
|
@@ -10,7 +10,8 @@ module Hostty
|
|
|
10
10
|
@cells = Library.create(:ghostty_render_state_row_cells_new, :ghostty_render_state_row_cells_free)
|
|
11
11
|
@row_iterator_reference = Library.reference(row_iterator)
|
|
12
12
|
@cells_reference = Library.reference(cells)
|
|
13
|
-
@
|
|
13
|
+
@cell_reader = CellReader.new(cells:)
|
|
14
|
+
@row_id_memory = FFI::MemoryPointer.new(:uint8, 16)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def lines
|
|
@@ -22,22 +23,12 @@ module Hostty
|
|
|
22
23
|
|
|
23
24
|
private
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
CELL_KEYS = [Library::CELL_DATA_WIDE, Library::CELL_DATA_CONTENT_TAG].freeze
|
|
27
|
-
TEXT_CAPACITY = 256
|
|
28
|
-
STYLE_LIMIT = 1024
|
|
29
|
-
private_constant :KEYS, :CELL_KEYS, :TEXT_CAPACITY, :STYLE_LIMIT
|
|
30
|
-
|
|
31
|
-
attr_reader :terminal, :state, :row_iterator, :cells, :row_iterator_reference, :cells_reference, :styles
|
|
26
|
+
attr_reader :terminal, :state, :row_iterator, :cells, :row_iterator_reference, :cells_reference, :cell_reader, :row_id_memory
|
|
32
27
|
|
|
33
28
|
def dirty
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def read_state(type, data)
|
|
38
|
-
value = FFI::MemoryPointer.new(type)
|
|
39
|
-
Library.ghostty_render_state_get(state, data, value)
|
|
40
|
-
value.read(type)
|
|
29
|
+
value = FFI::MemoryPointer.new(:int)
|
|
30
|
+
Library.ghostty_render_state_get(state, Library::RENDER_STATE_DATA_DIRTY, value)
|
|
31
|
+
value.read_int
|
|
41
32
|
end
|
|
42
33
|
|
|
43
34
|
def read_lines
|
|
@@ -53,10 +44,6 @@ module Hostty
|
|
|
53
44
|
row_id_memory.get_bytes(0, 16)
|
|
54
45
|
end
|
|
55
46
|
|
|
56
|
-
def row_id_memory
|
|
57
|
-
@row_id_memory ||= FFI::MemoryPointer.new(:uint8, 16)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
47
|
def row_dirty?
|
|
61
48
|
value = FFI::MemoryPointer.new(:uint8)
|
|
62
49
|
Library.ghostty_render_state_row_get(row_iterator, Library::ROW_DATA_DIRTY, value)
|
|
@@ -66,138 +53,9 @@ module Hostty
|
|
|
66
53
|
def read_row
|
|
67
54
|
Library.ghostty_render_state_row_get(row_iterator, Library::ROW_DATA_CELLS, cells_reference)
|
|
68
55
|
row = []
|
|
69
|
-
row <<
|
|
56
|
+
row << cell_reader.read while Library.ghostty_render_state_row_cells_next(cells)
|
|
70
57
|
row
|
|
71
58
|
end
|
|
72
|
-
|
|
73
|
-
def read_cell
|
|
74
|
-
result = Library.ghostty_render_state_row_cells_get_multi(cells, KEYS.size, keys, values, nil)
|
|
75
|
-
text = (result == Library::SUCCESS) ? text_memory.get_bytes(0, text_buffer[:len]).force_encoding(Encoding::UTF_8) : "�"
|
|
76
|
-
build_cell(text, raw_memory.read_uint64)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def build_cell(text, raw)
|
|
80
|
-
style_bytes = style_memory.get_bytes(0, 16)
|
|
81
|
-
return narrow_cell(text, style_bytes) if text.bytesize == 1
|
|
82
|
-
|
|
83
|
-
Library.ghostty_cell_get_multi(raw, CELL_KEYS.size, cell_keys, cell_values, nil)
|
|
84
|
-
|
|
85
|
-
case wide_memory.read_int
|
|
86
|
-
when Library::CELL_WIDE_SPACER_TAIL
|
|
87
|
-
Terminal::Cell.continuation(style_for(style_bytes))
|
|
88
|
-
when Library::CELL_WIDE_WIDE
|
|
89
|
-
Terminal::Cell.new(char: text, style: style_for(style_bytes), width: 2)
|
|
90
|
-
else
|
|
91
|
-
text.empty? ? blank_cell(raw, style_bytes) : Terminal::Cell.new(char: text, style: style_for(style_bytes))
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def narrow_cell(text, style_bytes)
|
|
96
|
-
cells = narrow_cells[style_bytes] ||= {}
|
|
97
|
-
cells[text] ||= Terminal::Cell.new(char: text, style: style_for(style_bytes))
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def narrow_cells
|
|
101
|
-
@narrow_cells = {} if @narrow_cells.nil? || @narrow_cells.size > STYLE_LIMIT
|
|
102
|
-
@narrow_cells
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def blank_cell(raw, style_bytes)
|
|
106
|
-
case content_memory.read_int
|
|
107
|
-
when Library::CELL_CONTENT_BG_COLOR_PALETTE
|
|
108
|
-
background_cell(style_bytes, cell_bytes(raw, Library::CELL_DATA_COLOR_PALETTE, 1).first)
|
|
109
|
-
when Library::CELL_CONTENT_BG_COLOR_RGB
|
|
110
|
-
background_cell(style_bytes, cell_bytes(raw, Library::CELL_DATA_COLOR_RGB, 3))
|
|
111
|
-
else
|
|
112
|
-
narrow_cell(" ", style_bytes)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def background_cell(style_bytes, bg)
|
|
117
|
-
Terminal::Cell.blank(Terminal::Style.shared(style_for(style_bytes).to_h.merge(bg:)))
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def cell_bytes(raw, data, count)
|
|
121
|
-
Library.ghostty_cell_get(raw, data, color_memory)
|
|
122
|
-
color_memory.get_bytes(0, count).bytes
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def style_for(bytes)
|
|
126
|
-
styles.clear if styles.size > STYLE_LIMIT
|
|
127
|
-
styles[bytes] ||= decode_style(*bytes.unpack("C12S<"))
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def decode_style(*colors, flags)
|
|
131
|
-
Terminal::Style.shared(
|
|
132
|
-
fg: color(*colors[0, 4]),
|
|
133
|
-
bg: color(*colors[4, 4]),
|
|
134
|
-
bold: flags.anybits?(1 << 0),
|
|
135
|
-
dim: flags.anybits?(1 << 2),
|
|
136
|
-
italic: flags.anybits?(1 << 1),
|
|
137
|
-
underline: flags.anybits?(0b111 << 8),
|
|
138
|
-
blink: flags.anybits?(1 << 3),
|
|
139
|
-
inverse: flags.anybits?(1 << 4),
|
|
140
|
-
invisible: flags.anybits?(1 << 5),
|
|
141
|
-
strikethrough: flags.anybits?(1 << 6),
|
|
142
|
-
overline: flags.anybits?(1 << 7)
|
|
143
|
-
)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def color(tag, *value)
|
|
147
|
-
case tag
|
|
148
|
-
when 1
|
|
149
|
-
value.first
|
|
150
|
-
when 2
|
|
151
|
-
value
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def raw_memory
|
|
156
|
-
@raw_memory ||= FFI::MemoryPointer.new(:uint64)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def style_memory
|
|
160
|
-
@style_memory ||= FFI::MemoryPointer.new(:uint8, 16)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def text_memory
|
|
164
|
-
@text_memory ||= FFI::MemoryPointer.new(:uint8, TEXT_CAPACITY)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def text_buffer
|
|
168
|
-
@text_buffer ||= Library::Buffer.new.tap do |buffer|
|
|
169
|
-
buffer[:ptr] = text_memory
|
|
170
|
-
buffer[:cap] = TEXT_CAPACITY
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def wide_memory
|
|
175
|
-
@wide_memory ||= FFI::MemoryPointer.new(:int)
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def content_memory
|
|
179
|
-
@content_memory ||= FFI::MemoryPointer.new(:int)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def color_memory
|
|
183
|
-
@color_memory ||= FFI::MemoryPointer.new(:uint8, 4)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def cell_keys
|
|
187
|
-
@cell_keys ||= FFI::MemoryPointer.new(:int, CELL_KEYS.size).write_array_of_int(CELL_KEYS)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def cell_values
|
|
191
|
-
@cell_values ||= FFI::MemoryPointer.new(:pointer, CELL_KEYS.size).write_array_of_pointer([wide_memory, content_memory])
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def keys
|
|
195
|
-
@keys ||= FFI::MemoryPointer.new(:int, KEYS.size).write_array_of_int(KEYS)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def values
|
|
199
|
-
@values ||= FFI::MemoryPointer.new(:pointer, KEYS.size).write_array_of_pointer([raw_memory, style_memory, text_buffer.pointer])
|
|
200
|
-
end
|
|
201
59
|
end
|
|
202
60
|
end
|
|
203
61
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Ghostty
|
|
5
|
+
class RawCell
|
|
6
|
+
def initialize
|
|
7
|
+
@wide_memory = FFI::MemoryPointer.new(:int)
|
|
8
|
+
@content_memory = FFI::MemoryPointer.new(:int)
|
|
9
|
+
@color_memory = FFI::MemoryPointer.new(:uint8, 4)
|
|
10
|
+
@keys = FFI::MemoryPointer.new(:int, KEYS.size).write_array_of_int(KEYS)
|
|
11
|
+
@values = FFI::MemoryPointer.new(:pointer, KEYS.size).write_array_of_pointer([wide_memory, content_memory])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def wide = wide_memory.read_int
|
|
15
|
+
|
|
16
|
+
def load(raw)
|
|
17
|
+
@raw = raw
|
|
18
|
+
Library.ghostty_cell_get_multi(raw, KEYS.size, keys, values, nil)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def background
|
|
22
|
+
case content_memory.read_int
|
|
23
|
+
when Library::CELL_CONTENT_BG_COLOR_PALETTE
|
|
24
|
+
color(Library::CELL_DATA_COLOR_PALETTE, 1).first
|
|
25
|
+
when Library::CELL_CONTENT_BG_COLOR_RGB
|
|
26
|
+
color(Library::CELL_DATA_COLOR_RGB, 3)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
KEYS = [Library::CELL_DATA_WIDE, Library::CELL_DATA_CONTENT_TAG].freeze
|
|
33
|
+
private_constant :KEYS
|
|
34
|
+
|
|
35
|
+
attr_reader :wide_memory, :content_memory, :color_memory, :keys, :values, :raw
|
|
36
|
+
|
|
37
|
+
def color(data, count)
|
|
38
|
+
Library.ghostty_cell_get(raw, data, color_memory)
|
|
39
|
+
color_memory.get_bytes(0, count).bytes
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hostty
|
|
4
|
+
module Ghostty
|
|
5
|
+
class StyleDecoder
|
|
6
|
+
def initialize
|
|
7
|
+
@styles = Terminal::Flyweight.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def decode(bytes)
|
|
11
|
+
styles.fetch(bytes) { style(*bytes.unpack("C12S<")) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
attr_reader :styles
|
|
17
|
+
|
|
18
|
+
def style(*colors, flags)
|
|
19
|
+
Terminal::Style.shared(
|
|
20
|
+
fg: color(*colors[0, 4]),
|
|
21
|
+
bg: color(*colors[4, 4]),
|
|
22
|
+
bold: flags.anybits?(1 << 0),
|
|
23
|
+
dim: flags.anybits?(1 << 2),
|
|
24
|
+
italic: flags.anybits?(1 << 1),
|
|
25
|
+
underline: flags.anybits?(0b111 << 8),
|
|
26
|
+
blink: flags.anybits?(1 << 3),
|
|
27
|
+
inverse: flags.anybits?(1 << 4),
|
|
28
|
+
invisible: flags.anybits?(1 << 5),
|
|
29
|
+
strikethrough: flags.anybits?(1 << 6),
|
|
30
|
+
overline: flags.anybits?(1 << 7)
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def color(tag, *value)
|
|
35
|
+
case tag
|
|
36
|
+
when 1
|
|
37
|
+
value.first
|
|
38
|
+
when 2
|
|
39
|
+
value
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -2,31 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
module Hostty
|
|
4
4
|
class ProcessConfig
|
|
5
|
-
attr_reader :name, :root_path
|
|
5
|
+
attr_reader :name, :port, :root_path
|
|
6
6
|
|
|
7
|
-
def initialize(name:, settings:,
|
|
7
|
+
def initialize(name:, settings:, port:, root_path:)
|
|
8
8
|
@name = name
|
|
9
|
-
@settings = settings
|
|
10
|
-
@
|
|
9
|
+
@settings = settings
|
|
10
|
+
@port = port
|
|
11
11
|
@root_path = root_path
|
|
12
|
-
@ports = ports
|
|
13
|
-
validate!
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
def fixed_port? = settings["port"].is_a?(Integer)
|
|
17
|
-
|
|
18
14
|
def command = settings["command"]
|
|
19
15
|
|
|
20
16
|
def domain = settings["domain"]
|
|
21
17
|
|
|
22
|
-
def
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
def ssl = settings["ssl"]
|
|
19
|
+
|
|
20
|
+
def host = settings["host"]
|
|
21
|
+
|
|
22
|
+
def log = settings["log"]
|
|
23
|
+
|
|
24
|
+
def root = settings["root"]
|
|
25
|
+
|
|
26
|
+
def template = settings["template"]
|
|
25
27
|
|
|
26
28
|
def url
|
|
27
29
|
return unless domain
|
|
28
30
|
|
|
29
|
-
"#{
|
|
31
|
+
"#{ssl ? "https" : "http"}://#{domain}"
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def environment
|
|
@@ -36,62 +38,8 @@ module Hostty
|
|
|
36
38
|
.merge("PORT" => port.to_s)
|
|
37
39
|
end
|
|
38
40
|
|
|
39
|
-
def nginx_options
|
|
40
|
-
{
|
|
41
|
-
domain:,
|
|
42
|
-
port:,
|
|
43
|
-
root_path: static_root,
|
|
44
|
-
template_path: template&.path,
|
|
45
|
-
host: settings["host"],
|
|
46
|
-
ssl: settings["ssl"],
|
|
47
|
-
log: settings["log"]
|
|
48
|
-
}.compact
|
|
49
|
-
end
|
|
50
|
-
|
|
51
41
|
private
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
PATH_KEYS = %w[root template].freeze
|
|
55
|
-
PORTS = 1..65_535
|
|
56
|
-
private_constant :KEYS, :PATH_KEYS, :PORTS
|
|
57
|
-
|
|
58
|
-
attr_reader :settings, :default_port, :ports
|
|
59
|
-
|
|
60
|
-
def validate!
|
|
61
|
-
raise ConfigError, "#{name} must be a command or a list of settings." unless settings.is_a?(Hash)
|
|
62
|
-
raise ConfigError, "#{name} has unknown settings: #{unknown_keys.join(", ")}." if unknown_keys.any?
|
|
63
|
-
raise ConfigError, "#{name} needs a command." unless present_string?(command)
|
|
64
|
-
raise ConfigError, "#{name} needs a port from 1 to 65535, or \"random\"." unless valid_port_setting?
|
|
65
|
-
raise ConfigError, "#{name} needs a text value for its domain." unless domain.nil? || present_string?(domain)
|
|
66
|
-
raise ConfigError, "#{name} needs a text value for its #{invalid_path_keys.join(" and ")}." if invalid_path_keys.any?
|
|
67
|
-
raise ConfigError, "#{name} needs a list of names and values for its env." unless settings.fetch("env", {}).is_a?(Hash)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def invalid_path_keys
|
|
71
|
-
PATH_KEYS.select { |key| settings.key?(key) && !present_string?(settings[key]) }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def template
|
|
75
|
-
@template ||= NginxTemplate.new(name: settings["template"], base_path: root_path) if settings["template"]
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def static_root
|
|
79
|
-
return File.expand_path(settings["root"], root_path) if settings["root"]
|
|
80
|
-
|
|
81
|
-
template&.static_root || root_path
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def unknown_keys
|
|
85
|
-
settings.keys.map(&:to_s) - KEYS
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def valid_port_setting?
|
|
89
|
-
requested = settings.fetch("port", default_port)
|
|
90
|
-
requested == "random" || (requested.is_a?(Integer) && PORTS.cover?(requested))
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def present_string?(value)
|
|
94
|
-
value.is_a?(String) && !value.strip.empty?
|
|
95
|
-
end
|
|
43
|
+
attr_reader :settings
|
|
96
44
|
end
|
|
97
45
|
end
|
data/lib/hostty/terminal/cell.rb
CHANGED
|
@@ -19,11 +19,11 @@ module Hostty
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def self.blank(style = Style.plain)
|
|
22
|
-
blanks
|
|
22
|
+
blanks.fetch(style.bg) { new(char: " ", style: style.background) }
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def self.blanks
|
|
26
|
-
@blanks ||=
|
|
26
|
+
@blanks ||= Flyweight.new
|
|
27
27
|
end
|
|
28
28
|
private_class_method :blanks
|
|
29
29
|
|