crussh 0.1.0-x86_64-linux

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 (82) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +371 -0
  5. data/lib/crussh/auth.rb +46 -0
  6. data/lib/crussh/channel/key_parser.rb +125 -0
  7. data/lib/crussh/channel.rb +381 -0
  8. data/lib/crussh/cipher/algorithm.rb +31 -0
  9. data/lib/crussh/cipher/chacha20poly1305.rb +98 -0
  10. data/lib/crussh/cipher.rb +25 -0
  11. data/lib/crussh/compression.rb +42 -0
  12. data/lib/crussh/crypto/3.4/poly1305.so +0 -0
  13. data/lib/crussh/crypto/4.0/poly1305.so +0 -0
  14. data/lib/crussh/gatekeeper.rb +50 -0
  15. data/lib/crussh/handler/line_buffer.rb +131 -0
  16. data/lib/crussh/handler.rb +128 -0
  17. data/lib/crussh/heartbeat.rb +68 -0
  18. data/lib/crussh/kex/algorithm.rb +86 -0
  19. data/lib/crussh/kex/curve25519.rb +30 -0
  20. data/lib/crussh/kex/exchange.rb +234 -0
  21. data/lib/crussh/kex.rb +42 -0
  22. data/lib/crussh/keys/key_pair.rb +61 -0
  23. data/lib/crussh/keys/public_key.rb +35 -0
  24. data/lib/crussh/keys.rb +70 -0
  25. data/lib/crussh/limits.rb +45 -0
  26. data/lib/crussh/logger.rb +95 -0
  27. data/lib/crussh/mac/algorithm.rb +23 -0
  28. data/lib/crussh/mac/crypto.rb +60 -0
  29. data/lib/crussh/mac/none.rb +9 -0
  30. data/lib/crussh/mac.rb +28 -0
  31. data/lib/crussh/negotiator.rb +41 -0
  32. data/lib/crussh/preferred.rb +16 -0
  33. data/lib/crussh/protocol/channel_close.rb +11 -0
  34. data/lib/crussh/protocol/channel_data.rb +12 -0
  35. data/lib/crussh/protocol/channel_eof.rb +11 -0
  36. data/lib/crussh/protocol/channel_extended_data.rb +13 -0
  37. data/lib/crussh/protocol/channel_failure.rb +11 -0
  38. data/lib/crussh/protocol/channel_open.rb +69 -0
  39. data/lib/crussh/protocol/channel_open_confirmation.rb +15 -0
  40. data/lib/crussh/protocol/channel_open_failure.rb +14 -0
  41. data/lib/crussh/protocol/channel_request.rb +146 -0
  42. data/lib/crussh/protocol/channel_success.rb +11 -0
  43. data/lib/crussh/protocol/channel_window_adjust.rb +12 -0
  44. data/lib/crussh/protocol/debug.rb +15 -0
  45. data/lib/crussh/protocol/disconnect.rb +39 -0
  46. data/lib/crussh/protocol/ext_info.rb +48 -0
  47. data/lib/crussh/protocol/global_request.rb +46 -0
  48. data/lib/crussh/protocol/ignore.rb +11 -0
  49. data/lib/crussh/protocol/kex_ecdh_init.rb +11 -0
  50. data/lib/crussh/protocol/kex_ecdh_reply.rb +13 -0
  51. data/lib/crussh/protocol/kex_init.rb +38 -0
  52. data/lib/crussh/protocol/new_keys.rb +9 -0
  53. data/lib/crussh/protocol/ping.rb +11 -0
  54. data/lib/crussh/protocol/pong.rb +11 -0
  55. data/lib/crussh/protocol/request_failure.rb +9 -0
  56. data/lib/crussh/protocol/request_success.rb +11 -0
  57. data/lib/crussh/protocol/service_accept.rb +11 -0
  58. data/lib/crussh/protocol/service_request.rb +11 -0
  59. data/lib/crussh/protocol/unimplemented.rb +11 -0
  60. data/lib/crussh/protocol/userauth_banner.rb +12 -0
  61. data/lib/crussh/protocol/userauth_failure.rb +12 -0
  62. data/lib/crussh/protocol/userauth_pk_ok.rb +12 -0
  63. data/lib/crussh/protocol/userauth_request.rb +52 -0
  64. data/lib/crussh/protocol/userauth_success.rb +9 -0
  65. data/lib/crussh/protocol.rb +135 -0
  66. data/lib/crussh/server/auth_handler.rb +18 -0
  67. data/lib/crussh/server/config.rb +157 -0
  68. data/lib/crussh/server/layers/connection.rb +363 -0
  69. data/lib/crussh/server/layers/transport.rb +49 -0
  70. data/lib/crussh/server/layers/userauth.rb +232 -0
  71. data/lib/crussh/server/request_rule.rb +76 -0
  72. data/lib/crussh/server/session.rb +192 -0
  73. data/lib/crussh/server.rb +214 -0
  74. data/lib/crussh/ssh_id.rb +44 -0
  75. data/lib/crussh/transport/packet_stream.rb +245 -0
  76. data/lib/crussh/transport/reader.rb +98 -0
  77. data/lib/crussh/transport/version_exchange.rb +26 -0
  78. data/lib/crussh/transport/writer.rb +72 -0
  79. data/lib/crussh/version.rb +5 -0
  80. data/lib/crussh.rb +61 -0
  81. data/sig/crussh.rbs +4 -0
  82. metadata +240 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8b47f2f8b5c514209e26b4bd16515ef07bd5ea50c699a442c38db285f240defd
4
+ data.tar.gz: 414a3722970ff5c5b3876478ee17a98da360a28ae17bb02ad247019dc6f32d6b
5
+ SHA512:
6
+ metadata.gz: bf17502e616214c3ad7507825876eea67a696961676a6fc3dc720799eb97df4972004e2ff683053dc28ba84c9269e2037f4f5a193f83e369dd0568d6fa6fe7b2
7
+ data.tar.gz: 10f7bd8cfe125320ab786317a916308b9a5aedf64930aee13bd96e280521e72f2b57d4eef1a711d5b5d4855016be95ea0a566293aeb1fc05a779169dbe122056
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-01-03
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 MSILycanthropy
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.
data/README.md ADDED
@@ -0,0 +1,371 @@
1
+ # Crussh
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/crussh.svg)](https://badge.fury.io/rb/crussh)
4
+ [![Build Status](https://github.com/MSILycanthropy/crussh/actions/workflows/main.yml/badge.svg)](https://github.com/MSILycanthropy/crussh/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.3-ruby.svg)](https://www.ruby-lang.org)
7
+
8
+ A low-level SSH server library for Ruby.
9
+
10
+ <details>
11
+ <summary>
12
+ <strong>Algorithm Support</strong>
13
+ </summary>
14
+
15
+ - Ciphers:
16
+ - `chacha20-poly1305@openssh.com`
17
+ - Key exchanges:
18
+ - `curve25519-sha256`
19
+ - `curve25519-sha256@libssh.org`
20
+ - Host keys:
21
+ - `ssh-ed25519`
22
+ - `rsa-sha2-256`
23
+ - `rsa-sha2-512`
24
+ - `ecdsa-sha2-nistp256`
25
+ - `ecdsa-sha2-nistp384`
26
+ - `ecdsa-sha2-nistp521`
27
+ - Authentication:
28
+ - `none`
29
+ - `password`
30
+ - `publickey`
31
+ - Compression:
32
+ - `none`
33
+ - `zlib@openssh.com`
34
+ - Channels:
35
+ - `session`
36
+ - `direct-tcpip`
37
+ - `forwarded-tcpip`
38
+ - `x11`
39
+ - Other: - Strict key exchange (KEX) - `server-sig-algs` extension - `ping@openssh.com` extension - OpenSSH keepalive handling.
40
+ </details>
41
+
42
+ ## Why SSH?
43
+
44
+ When we think about SSH, we almost exclusively think of it as a tool for remote shell access — `ssh user@server` and you're accessing a remote machine. But SSH is a _protocol_, not just a tool. Like HTTP, and it comes with some really nice benefits out of the box:
45
+
46
+ - **Encrypted by default** — No certificates to manage, no HTTPS setup
47
+ - **Built-in authentication** — Literally everyone and their mother has an SSH key
48
+ - **Universal client** — Everyone has a beautiful SSH client already
49
+ - **Terminal-native** — We've all got a terminal
50
+
51
+ You can build all kinds of things over SSH: git servers, file browsers, and even [coffee shops](https://terminal.shop).
52
+
53
+ Crussh is a library for building these kinds of things in Ruby.
54
+
55
+ ## Installation
56
+
57
+ Add to your Gemfile:
58
+
59
+ ```ruby
60
+ gem "crussh"
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ```ruby
66
+ require "crussh"
67
+
68
+ class HelloHandler < Crussh::Handler
69
+ before :log_connect
70
+ after :log_disconnect
71
+
72
+ def handle
73
+ puts "Hello, #{user}!"
74
+ puts "Your terminal is #{pty&.term || "unknown"}"
75
+
76
+ exit_status(0)
77
+ close
78
+ end
79
+
80
+ private
81
+
82
+ def log_connect
83
+ logger.info("Client connected", user:)
84
+ end
85
+
86
+ def log_disconnect
87
+ logger.info("Client disconnected", user:)
88
+ end
89
+ end
90
+
91
+ class HelloServer < Crussh::Server
92
+ configure do |c|
93
+ c.port = 2222
94
+
95
+ # Automatically generate host keys
96
+ c.generate_host_keys!
97
+
98
+ # OR load from a file
99
+ # c.host_key_files << "/path/to/host_key"
100
+ end
101
+
102
+ authenticate(:none) { true }
103
+
104
+ handle :shell, HelloHandler
105
+ end
106
+
107
+ Sync { HelloServer.run }
108
+ ```
109
+
110
+ Connect with any SSH client:
111
+
112
+ ```bash
113
+ ssh localhost -p 2222
114
+ # => Hello, yourname!
115
+ # => Your terminal is xterm-256color
116
+ ```
117
+
118
+ ## Features
119
+
120
+ - **No OpenSSH** — No OpenSSH dependency. Runs anywhere Ruby runs.
121
+ - **Modern cryptography** — ChaCha20-Poly1305, Curve25519, Ed25519 by default
122
+ - **Async-native** — Built on [Async](https://github.com/socketry/async) for concurrent connections and channels
123
+ - **Clean DSL** — Rails-inspired configuration and authentication
124
+ - **Handler-based** — Separate classes for shell, exec, and subsystem requests
125
+ - **Low-level access** — Drop down to raw channel I/O when you need control
126
+
127
+ ## Authentication
128
+
129
+ Crussh currently supports `none`, `password` and `publickey` auth. `keyboard-interactive` is planned — PRs welcome!
130
+
131
+ ```ruby
132
+ class MyServer < Crussh::Server
133
+ authenticate(:none) { |username| username == "guest" }
134
+
135
+ authenticate(:password) do |username, password|
136
+ Users.authenticate(username, password)
137
+ end
138
+
139
+ authenticate(:publickey) do |username, key|
140
+ AuthorizedKeys.include?(username, key.fingerprint)
141
+ end
142
+ end
143
+ ```
144
+
145
+ ## Handlers
146
+
147
+ Handlers are plain Ruby classes that process SSH requests. They inherit from `Crussh::Handler` and give you a clean, testable way to organize your logic:
148
+
149
+ ```ruby
150
+ class ShellHandler < Crussh::Handler
151
+ def handle
152
+ puts "Welcome, #{user}!"
153
+ puts "Type 'exit' to quit."
154
+
155
+ each_line(prompt: "$ ") do |line|
156
+ break if line == "exit"
157
+
158
+ puts "You typed: #{line}"
159
+ end
160
+
161
+ exit_status(0)
162
+ close
163
+ end
164
+ end
165
+
166
+ class ExecHandler < Crussh::Handler
167
+ def setup(command)
168
+ @command = command
169
+ end
170
+
171
+ def handle
172
+ IO.popen(@command, err: [:child, :out]) do |io|
173
+ IO.copy_stream(io, channel)
174
+ end
175
+
176
+ exit_status($CHILD_STATUS.exitstatus)
177
+ close
178
+ end
179
+ end
180
+
181
+ class MyServer < Crussh::Server
182
+ configure do |c|
183
+ c.port = 2222
184
+ c.generate_host_keys!
185
+ end
186
+
187
+ authenticate(:publickey) { |user, key| authorized?(user, key) }
188
+
189
+ handle :shell, ShellHandler
190
+ handle :exec, ExecHandler
191
+ end
192
+ ```
193
+
194
+ Handlers have access to:
195
+
196
+ - `user` — the authenticated username
197
+ - `pty` — PTY info (term, width, height) if requested
198
+ - `env` — environment variables from the client
199
+ - `channel` — the underlying channel for advanced use
200
+ - I/O methods: `puts`, `print`, `gets`, `read`, `write`
201
+ - Lifecycle: `close`, `send_eof`, `exit_status`, `exit_signal`
202
+
203
+ ### Callbacks
204
+
205
+ Handlers support Rails-style lifecycle callbacks:
206
+
207
+ ```ruby
208
+ class MyHandler < Crussh::Handler
209
+ before :setup_environment
210
+ after :cleanup
211
+ around :with_timing
212
+
213
+ rescue_from IOError, with: :handle_disconnect
214
+
215
+ def handle
216
+ # ...
217
+ end
218
+
219
+ private
220
+
221
+ def with_timing
222
+ start = Time.now
223
+ yield
224
+ ensure
225
+ logger.debug("Duration", seconds: Time.now - start)
226
+ end
227
+ end
228
+ ```
229
+
230
+ ## Input Handling
231
+
232
+ Crussh provides three levels of abstraction for reading events on the channel:
233
+
234
+ ```ruby
235
+ class MyHandler < Crussh::Handler
236
+ def handle
237
+ # Low-level: raw SSH events
238
+ each_event do |event|
239
+ case event
240
+ in Channel::Data(data:)
241
+ # raw bytes from client
242
+ in Channel::WindowChange(width:, height:)
243
+ # terminal resized
244
+ in Channel::EOF
245
+ # client sent EOF
246
+ end
247
+ end
248
+
249
+ # Mid-level: parsed keystrokes
250
+ each_key do |key|
251
+ case key
252
+ when :arrow_up then move_up
253
+ when :enter then submit
254
+ when String then insert(key)
255
+ end
256
+ end
257
+
258
+ # High-level: line editing with prompt
259
+ each_line(prompt: "> ") do |line|
260
+ process(line)
261
+ end
262
+ end
263
+
264
+ # Called automatically by each_key/each_line on window resize
265
+ def resize(width, height)
266
+ @width = width
267
+ @height = height
268
+ redraw
269
+ end
270
+ end
271
+ ```
272
+
273
+ ## Configuration
274
+
275
+ ```ruby
276
+ class MyServer < Crussh::Server
277
+ configure do |c|
278
+ # Network
279
+ c.host = "0.0.0.0"
280
+ c.port = 2222
281
+
282
+ # Keys (generate or load from files)
283
+ c.generate_host_keys!
284
+ # c.host_key_files << "/path/to/ssh_host_ed25519_key"
285
+
286
+ c.max_connections = 100
287
+ c.max_auth_attempts = 6
288
+
289
+ c.connection_timeout = 10
290
+ c.auth_timeout = 30
291
+ c.inactivity_timeout = 600
292
+
293
+ c.keepalive_interval = 30
294
+ c.keepalive_max = 3
295
+ end
296
+ end
297
+ ```
298
+
299
+ ## Pro Tips
300
+
301
+ ### Development SSH Config
302
+
303
+ When developing locally, add this to `~/.ssh/config` to avoid `known_hosts` conflicts:
304
+
305
+ ```
306
+ Host localhost
307
+ UserKnownHostsFile /dev/null
308
+ StrictHostKeyChecking no
309
+ ```
310
+
311
+ ### How It Works
312
+
313
+ Crussh implements the SSH protocol from scratch using Ruby and a small Rust extension for Poly1305. OpenSSH is never involved — you can uninstall it entirely if you want.
314
+
315
+ Because there's no default shell behavior, there's no risk of accidentally exposing system access. Your server only does what you explicitly implement.
316
+
317
+ ## Running with systemd
318
+
319
+ For production deployments, create a systemd unit file:
320
+
321
+ ```ini
322
+ # /etc/systemd/system/myapp.service
323
+ [Unit]
324
+ Description=My SSH App
325
+ After=network.target
326
+
327
+ [Service]
328
+ Type=simple
329
+ User=myapp
330
+ Group=myapp
331
+ WorkingDirectory=/home/myapp
332
+ ExecStart=/usr/bin/ruby /home/myapp/server.rb
333
+ Restart=on-failure
334
+
335
+ [Install]
336
+ WantedBy=multi-user.target
337
+ ```
338
+
339
+ Then:
340
+
341
+ ```bash
342
+ # Create a dedicated user
343
+ sudo useradd --system --user-group --create-home myapp
344
+
345
+ # Enable and start
346
+ sudo systemctl daemon-reload
347
+ sudo systemctl enable myapp
348
+ sudo systemctl start myapp
349
+ ```
350
+
351
+ ## Documentation
352
+
353
+ _Coming soon_
354
+
355
+ - Getting Started
356
+ - Configuration Reference
357
+ - Authentication Guide
358
+ - Writing Handlers
359
+ - API Reference
360
+
361
+ ## Contributing
362
+
363
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MSILycanthropy/crussh.
364
+
365
+ ## License
366
+
367
+ [MIT](LICENSE.txt)
368
+
369
+ ---
370
+
371
+ Crussh is inspired by [russh](https://github.com/warp-tech/russh) (Rust) and [Wish](https://github.com/charmbracelet/wish) (Go). Built on [Async](https://github.com/socketry/async) for Ruby's concurrent future.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crussh
4
+ module Auth
5
+ Result = Data.define(:status, :continue_with) do
6
+ class << self
7
+ def success
8
+ new(status: :success, continue_with: nil)
9
+ end
10
+
11
+ def failure
12
+ new(status: :failure, continue_with: nil)
13
+ end
14
+
15
+ def partial(*methods)
16
+ new(status: :parital, continue_with: methods)
17
+ end
18
+ end
19
+
20
+ def success? = status == :success
21
+ def partial? = status == :partial
22
+ def failure? = status == :failure
23
+ end
24
+
25
+ class << self
26
+ def accept = Result.success
27
+ def reject = Result.failure
28
+ def partial(...) = Result.partial(...)
29
+
30
+ def normalize(result)
31
+ case result
32
+ when Result then result
33
+ when true then accept
34
+ when false, nil then reject
35
+ else reject
36
+ end
37
+ end
38
+ end
39
+
40
+ module DSL
41
+ def accept = Auth.accept
42
+ def reject = Auth.reject
43
+ def partial(...) = Auth.partial(...)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crussh
4
+ class Channel
5
+ module Keys
6
+ ENTER = :enter
7
+ INTERRUPT = :interrupt
8
+ EOF = :eof
9
+ BACKSPACE = :backspace
10
+ DELETE = :delete
11
+ TAB = :tab
12
+
13
+ ARROW_UP = :arrow_up
14
+ ARROW_DOWN = :arrow_down
15
+ ARROW_LEFT = :arrow_left
16
+ ARROW_RIGHT = :arrow_right
17
+
18
+ HOME = :home
19
+ END_KEY = :end
20
+ PAGE_UP = :page_up
21
+ PAGE_DOWN = :page_down
22
+ INSERT = :insert
23
+ end
24
+
25
+ class KeyParser
26
+ ESCAPE = "\e"
27
+ ESCAPE_SEQUENCES = {
28
+ "[A" => Keys::ARROW_UP,
29
+ "[B" => Keys::ARROW_DOWN,
30
+ "[C" => Keys::ARROW_RIGHT,
31
+ "[D" => Keys::ARROW_LEFT,
32
+ "[H" => Keys::HOME,
33
+ "[F" => Keys::END_KEY,
34
+ "[1~" => Keys::HOME,
35
+ "[4~" => Keys::END_KEY,
36
+ "[2~" => Keys::INSERT,
37
+ "[3~" => Keys::DELETE,
38
+ "[5~" => Keys::PAGE_UP,
39
+ "[6~" => Keys::PAGE_DOWN,
40
+ "OH" => Keys::HOME,
41
+ "OF" => Keys::END_KEY,
42
+ }
43
+ MAX_ESCAPE_LENGTH = 8
44
+
45
+ def initialize
46
+ @escape_buffer = +""
47
+ end
48
+
49
+ def parse(data)
50
+ keys = []
51
+
52
+ data.each_char do |char|
53
+ if @escape_buffer.empty?
54
+ if char == ESCAPE
55
+ @escape_buffer = +ESCAPE
56
+ else
57
+ key = parse_char(char)
58
+ keys << key if key
59
+ end
60
+ else
61
+ @escape_buffer << char
62
+
63
+ if complete_escape?
64
+ key = resolve_escape
65
+ keys << key if key
66
+ @escape_buffer = +""
67
+ elsif @escape_buffer.length >= MAX_ESCAPE_LENGTH
68
+ @escape_buffer = +""
69
+ end
70
+ end
71
+ end
72
+
73
+ keys
74
+ end
75
+
76
+ def flush
77
+ return if @escape_buffer.empty?
78
+
79
+ key = @escape_buffer == ESCAPE ? :escape : nil
80
+ @escape_buffer = ""
81
+ key
82
+ end
83
+
84
+ private
85
+
86
+ def parse_char(char)
87
+ case char
88
+ when "\r", "\n"
89
+ Keys::ENTER
90
+ when "\t"
91
+ Keys::TAB
92
+ when "\u0003" # Ctrl+C
93
+ Keys::INTERRUPT
94
+ when "\u0004" # Ctrl+D
95
+ Keys::EOF
96
+ when "\u007F", "\b" # DEL and BS
97
+ Keys::BACKSPACE
98
+ else
99
+ char if char.ord >= 32
100
+ end
101
+ end
102
+
103
+ def complete_escape?
104
+ return false if @escape_buffer.length < 2
105
+
106
+ sequence = @escape_buffer[1..]
107
+
108
+ if sequence.start_with?("[")
109
+ return sequence.length > 1 && sequence[-1].match?(/[A-Za-z~]/)
110
+ end
111
+
112
+ if sequence.start_with?("O")
113
+ return sequence.length == 2 && sequence[-1].match?(/[A-Za-z]/)
114
+ end
115
+
116
+ sequence >= 2
117
+ end
118
+
119
+ def resolve_escape
120
+ sequence = @escape_buffer[1..]
121
+ ESCAPE_SEQUENCES[sequence]
122
+ end
123
+ end
124
+ end
125
+ end