elelem-ghostty 0.1.1
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 +7 -0
- data/LICENSE.txt +21 -0
- data/lib/elelem/ghostty/library.rb +79 -0
- data/lib/elelem/ghostty/mirror.rb +35 -0
- data/lib/elelem/ghostty/screen.rb +36 -0
- data/lib/elelem/ghostty/version.rb +7 -0
- data/lib/elelem/ghostty.rb +18 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5a5d35cff384e58f3a383ad4ce4cd1e3848409279cc377e7493de45c23c58913
|
|
4
|
+
data.tar.gz: b9bd3fb37206981771abcf77347fa25317106e88e65919a6561fab12ed707f62
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6bab6ba4591944aff2713a1c5e27d411d86a21badd443f096d15bac8e87a3ce617ddc3361c921d826938b6b71fc02bfd6cac66d34a199b6608d487026054b575
|
|
7
|
+
data.tar.gz: c96a46399d879500e0fa53f69a84a9697398866a5df325d1fe20b20b61ffdcd817b68d38e6db35062315e9d7c6d92ae7bf6eb25ccbee9776e857f23b33606e84
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 2809074 Alberta Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Elelem
|
|
4
|
+
module Ghostty
|
|
5
|
+
class Library
|
|
6
|
+
P = Fiddle::TYPE_VOIDP
|
|
7
|
+
SIZE = Fiddle::TYPE_SIZE_T
|
|
8
|
+
INT = Fiddle::TYPE_INT
|
|
9
|
+
VOID = Fiddle::TYPE_VOID
|
|
10
|
+
SIGNATURES = {
|
|
11
|
+
ghostty_terminal_new: [[P, P, Fiddle::TYPE_UINT16_T, Fiddle::TYPE_UINT16_T], INT],
|
|
12
|
+
ghostty_terminal_vt_write: [[P, P, SIZE], VOID],
|
|
13
|
+
ghostty_terminal_free: [[P], VOID],
|
|
14
|
+
ghostty_formatter_terminal_new: [[P, P, P], INT],
|
|
15
|
+
ghostty_formatter_set: [[P, INT, P], INT],
|
|
16
|
+
ghostty_formatter_format_alloc: [[P, P, P, P], INT],
|
|
17
|
+
ghostty_formatter_free: [[P], VOID],
|
|
18
|
+
ghostty_free: [[P, P, SIZE], VOID]
|
|
19
|
+
}.freeze
|
|
20
|
+
NAMES = %w[libghostty-vt.so.1 libghostty-vt.1.dylib].freeze
|
|
21
|
+
CANDIDATES = (NAMES.map { File.join(__dir__, "native", it) } + NAMES).freeze
|
|
22
|
+
|
|
23
|
+
def self.releaser(lib, terminal, formatter)
|
|
24
|
+
proc do
|
|
25
|
+
lib.call(:ghostty_formatter_free, formatter)
|
|
26
|
+
lib.call(:ghostty_terminal_free, terminal)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.open(paths)
|
|
31
|
+
paths.lazy.filter_map { attempt(it) }.first or raise LoadError, "no libghostty-vt in #{paths.join(", ")}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.attempt(path)
|
|
35
|
+
Fiddle.dlopen(path)
|
|
36
|
+
rescue Fiddle::DLError
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def initialize(paths: CANDIDATES)
|
|
41
|
+
@handle = Library.open(paths)
|
|
42
|
+
@functions = SIGNATURES.to_h { |name, (args, ret)| [name, Fiddle::Function.new(@handle[name.to_s], args, ret)] }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def call(name, *args) = @functions.fetch(name).call(*args)
|
|
46
|
+
|
|
47
|
+
def terminal_new(cols, rows) = handle_out { |out| call(:ghostty_terminal_new, nil, out, cols, rows) }
|
|
48
|
+
def formatter_new(terminal) = handle_out { |out| call(:ghostty_formatter_terminal_new, nil, out, terminal) }
|
|
49
|
+
def vt_write(terminal, bytes) = call(:ghostty_terminal_vt_write, terminal, bytes, bytes.bytesize)
|
|
50
|
+
|
|
51
|
+
def set(formatter, option, value) = check(call(:ghostty_formatter_set, formatter, option, [value].pack("L")))
|
|
52
|
+
|
|
53
|
+
def format(formatter)
|
|
54
|
+
out = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
|
|
55
|
+
len = Fiddle::Pointer.malloc(Fiddle::SIZEOF_SIZE_T, Fiddle::RUBY_FREE)
|
|
56
|
+
check(call(:ghostty_formatter_format_alloc, formatter, nil, out, len))
|
|
57
|
+
take(out.ptr, len[0, Fiddle::SIZEOF_SIZE_T].unpack1("J"))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def take(buffer, size)
|
|
63
|
+
return +"" if buffer.null?
|
|
64
|
+
|
|
65
|
+
buffer[0, size].tap { call(:ghostty_free, nil, buffer, size) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def handle_out
|
|
69
|
+
out = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
|
|
70
|
+
check(yield(out))
|
|
71
|
+
out.ptr
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def check(result)
|
|
75
|
+
raise Error, "libghostty-vt returned #{result}" unless result.zero?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Elelem
|
|
4
|
+
module Ghostty
|
|
5
|
+
class Mirror
|
|
6
|
+
attr_reader :screen
|
|
7
|
+
|
|
8
|
+
def initialize(stream, screen: Screen.new(cols: Mirror.width(stream)))
|
|
9
|
+
@stream = stream
|
|
10
|
+
@screen = screen
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.width(stream)
|
|
14
|
+
stream.winsize[1]
|
|
15
|
+
rescue StandardError
|
|
16
|
+
80
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def print(*texts)
|
|
20
|
+
texts.each { |text| record(text) }
|
|
21
|
+
@stream.print(*texts)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def gets = @stream.gets.tap { |line| record(line) }
|
|
25
|
+
def redraw = @stream.print("\e[2J#{@screen.to_vt}")
|
|
26
|
+
|
|
27
|
+
def flush = @stream.flush
|
|
28
|
+
def winsize = @stream.winsize
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def record(text) = @screen.write(text.to_s.gsub(/(?<!\r)\n/, "\r\n"))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Elelem
|
|
4
|
+
module Ghostty
|
|
5
|
+
class Screen
|
|
6
|
+
PLAIN = 0
|
|
7
|
+
VT = 1
|
|
8
|
+
EMIT = 1
|
|
9
|
+
EXTRAS = 5
|
|
10
|
+
ALL_BUT_PALETTE = 0xFFE
|
|
11
|
+
|
|
12
|
+
def initialize(cols: 80, rows: 24, library: Library.new)
|
|
13
|
+
@lib = library
|
|
14
|
+
@terminal = @lib.terminal_new(cols, rows)
|
|
15
|
+
@formatter = @lib.formatter_new(@terminal)
|
|
16
|
+
ObjectSpace.define_finalizer(self, Library.releaser(@lib, @terminal, @formatter))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write(bytes)
|
|
20
|
+
@lib.vt_write(@terminal, bytes.to_s.b)
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s = format(PLAIN).force_encoding(Encoding::UTF_8)
|
|
25
|
+
def to_vt = format(VT, extras: ALL_BUT_PALETTE)
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def format(emit, extras: 0)
|
|
30
|
+
@lib.set(@formatter, EMIT, emit)
|
|
31
|
+
@lib.set(@formatter, EXTRAS, extras)
|
|
32
|
+
@lib.format(@formatter)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fiddle"
|
|
4
|
+
require "elelem"
|
|
5
|
+
require_relative "ghostty/version"
|
|
6
|
+
require_relative "ghostty/library"
|
|
7
|
+
require_relative "ghostty/screen"
|
|
8
|
+
require_relative "ghostty/mirror"
|
|
9
|
+
|
|
10
|
+
module Elelem
|
|
11
|
+
module Ghostty
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Elelem.configure do |config|
|
|
17
|
+
config.stream { |io| Elelem::Ghostty::Mirror.new(io) }
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: elelem-ghostty
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- mo khan
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: elelem
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.20'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.20'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '1'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: fiddle
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '1.1'
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 1.1.8
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '1.1'
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 1.1.8
|
|
52
|
+
description: Keeps a libghostty-vt screen of everything elelem prints, so a session
|
|
53
|
+
can be redrawn.
|
|
54
|
+
email:
|
|
55
|
+
- mo@mokhan.ca
|
|
56
|
+
executables: []
|
|
57
|
+
extensions: []
|
|
58
|
+
extra_rdoc_files: []
|
|
59
|
+
files:
|
|
60
|
+
- LICENSE.txt
|
|
61
|
+
- lib/elelem/ghostty.rb
|
|
62
|
+
- lib/elelem/ghostty/library.rb
|
|
63
|
+
- lib/elelem/ghostty/mirror.rb
|
|
64
|
+
- lib/elelem/ghostty/screen.rb
|
|
65
|
+
- lib/elelem/ghostty/version.rb
|
|
66
|
+
homepage: https://elelem.sh
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
allowed_push_host: https://rubygems.org
|
|
71
|
+
homepage_uri: https://elelem.sh
|
|
72
|
+
source_code_uri: https://github.com/elelem-sh/ghostty
|
|
73
|
+
rubygems_mfa_required: 'true'
|
|
74
|
+
rdoc_options: []
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 4.0.0
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
requirements: []
|
|
88
|
+
rubygems_version: 4.0.20
|
|
89
|
+
specification_version: 4
|
|
90
|
+
summary: Mirror elelem's output into a libghostty-vt screen.
|
|
91
|
+
test_files: []
|