termvas 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e006617f9d17384317e9c45880fbdef15e35049894eb82013557d170e805c97d
4
- data.tar.gz: 05fc5d8aeff21250c54bef69b4cd81c023d1c6c02aaac47c1ad72046f3c22ccd
3
+ metadata.gz: d96a53546db38dd9887bd4f0368a1b818ea2eafd58bb7fc9024ef1bf5d6d08da
4
+ data.tar.gz: 01ccfbff4469d665303695ad61600c8e591604cc7ce9b8b5c6f64b1026d48199
5
5
  SHA512:
6
- metadata.gz: 64cad8ca3988821b0361941f9027c2ff763e7b5b16e5fd8ac7a6b7b9e6f5859697474fe2901f001f98c1525c825aeeb8dae5e3b1c4b70eabd79897a030db556e
7
- data.tar.gz: 3cdda1da18561fd32d131dda835f19fc6062b7f4626acef9b0713b5a8ea843cf788843b5f2750b9d656cced5fbf811bfece6c01a3dd257582f540675a2485f81
6
+ metadata.gz: af06e7b15123c603edef3f89b8c5b8e13e7a3fde78ae0ed052a07f9a7320985e81ab6e75ec396760a289f70d835bd01100329d7bee9aa1242077df47b7f99225
7
+ data.tar.gz: a416408455b495482c2cc057c284509de678fdf48e15d950caa9f36637c5bd929a2110f20155e8da083231cf9ef06c7cb173027460418734d0577d1553824a91
data/.codespellignore ADDED
@@ -0,0 +1 @@
1
+ iTerm
data/.yamllint ADDED
@@ -0,0 +1,16 @@
1
+ extends: default
2
+ ignore: |
3
+ build/
4
+ node_modules/
5
+ runtime/build/
6
+ tmp/
7
+ **/*.dSYM/**
8
+
9
+ rules:
10
+ comments:
11
+ min-spaces-from-content: 1
12
+ document-start: disable
13
+ line-length:
14
+ max: 200
15
+ truthy:
16
+ check-keys: false
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [0.3.1] - 2026-09-26
4
+
5
+ - Skip unsupported terminal control sequences instead of reporting them as key events.
6
+ - Reject non-finite terminal frame limits.
7
+
8
+ ## [0.3.0] - 2026-09-25
9
+
10
+ - Expose terminal cell-size estimates for display fitting, with environment overrides.
4
11
 
5
12
  ## [0.2.0] - 2026-09-25
6
13
 
data/README.md CHANGED
@@ -84,6 +84,12 @@ The encoders, protocol detection, input parser, and terminal sizing utilities
84
84
  load with <code>require "termvas"</code> alone. The optional RBGL backend is
85
85
  available from <code>require "termvas/rbgl"</code>.
86
86
 
87
+ <code>Termvas::Terminal#size</code> returns <code>[columns, rows]</code>.
88
+ <code>#cell_size</code> returns estimated pixel dimensions as
89
+ <code>[width, height]</code> (8 × 16 by default). Set
90
+ <code>TERMVAS_CELL_WIDTH</code> and <code>TERMVAS_CELL_HEIGHT</code> to tune the
91
+ estimate; sizing does not query the terminal.
92
+
87
93
  ## Terminal notes
88
94
 
89
95
  <code>fit: :contain</code> is the default and reduces oversized frames to the
data/Rakefile CHANGED
@@ -3,9 +3,7 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
 
6
- RSpec::Core::RakeTask.new(:spec) do |task|
7
- task.ruby_opts = %w[-I../rbgl/lib -I../larb/lib -I../tessel/lib]
8
- end
6
+ RSpec::Core::RakeTask.new(:spec)
9
7
 
10
8
  task default: :spec
11
9
  task verify: :spec
data/lib/termvas/rbgl.rb CHANGED
@@ -17,7 +17,7 @@ module Termvas
17
17
  @fit = fit.to_sym
18
18
  raise ArgumentError, "fit must be :contain or :none" unless %i[contain none].include?(@fit)
19
19
  @max_fps = max_fps.nil? ? nil : Float(max_fps)
20
- raise ArgumentError, "max_fps must be positive" if @max_fps && !@max_fps.positive?
20
+ raise ArgumentError, "max_fps must be positive and finite" if @max_fps && (!@max_fps.positive? || !@max_fps.finite?)
21
21
  @terminal = Terminal.new(input: input, output: output, alt_screen: alt_screen, tmux: tmux)
22
22
  @output = output
23
23
  @input = input
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termvas
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/termvas.rb CHANGED
@@ -179,6 +179,14 @@ module Termvas
179
179
  @buffer << bytes
180
180
  events = []
181
181
  loop do
182
+ if @buffer.start_with?("\e[")
183
+ sequence = @buffer.match(/\A\e\[[0-?]*[ -\/]*[@-~]/)
184
+ break unless sequence
185
+ unless sequence[0].match?(/\A\e\[<\d+;\d+;\d+[Mm]\z|\A\e\[[0-9;]*[A-Za-z~]\z/)
186
+ @buffer = @buffer.byteslice(sequence[0].bytesize..).to_s.b
187
+ next
188
+ end
189
+ end
182
190
  if @buffer.start_with?("\e[<")
183
191
  match = @buffer.match(/\A\e\[<([0-9]+);([0-9]+);([0-9]+)([Mm])/
184
192
  )
@@ -271,10 +279,11 @@ module Termvas
271
279
  class Terminal
272
280
  attr_reader :input, :output
273
281
 
274
- def initialize(input: $stdin, output: $stdout, alt_screen: true, tmux: false)
282
+ def initialize(input: $stdin, output: $stdout, alt_screen: true, tmux: false, env: ENV)
275
283
  @input = input
276
284
  @output = output
277
285
  @alt_screen = alt_screen
286
+ @env = env
278
287
  @closed = false
279
288
  @opened = false
280
289
  @raw = false
@@ -288,10 +297,14 @@ module Termvas
288
297
  return [columns, rows] if rows.to_i.positive? && columns.to_i.positive?
289
298
 
290
299
  fallback_size
291
- rescue Errno::ENOTTY, IOError, NoMethodError
300
+ rescue Errno::ENODEV, Errno::ENOTTY, IOError, NoMethodError
292
301
  fallback_size
293
302
  end
294
303
 
304
+ def cell_size
305
+ [environment_dimension("TERMVAS_CELL_WIDTH", 8), environment_dimension("TERMVAS_CELL_HEIGHT", 16)]
306
+ end
307
+
295
308
  def open
296
309
  return self if @opened
297
310
  @opened = true
@@ -367,12 +380,19 @@ module Termvas
367
380
  end
368
381
 
369
382
  def fallback_size
370
- columns = Integer(ENV.fetch("COLUMNS", 80))
371
- rows = Integer(ENV.fetch("LINES", 24))
383
+ columns = Integer(@env.fetch("COLUMNS", 80))
384
+ rows = Integer(@env.fetch("LINES", 24))
372
385
  [columns.positive? ? columns : 80, rows.positive? ? rows : 24]
373
386
  rescue ArgumentError, TypeError
374
387
  [80, 24]
375
388
  end
389
+
390
+ def environment_dimension(name, fallback)
391
+ value = Integer(@env.fetch(name, fallback))
392
+ value.positive? ? value : fallback
393
+ rescue ArgumentError, TypeError
394
+ fallback
395
+ end
376
396
  end
377
397
 
378
398
  end
data/sig/termvas.rbs CHANGED
@@ -1,4 +1,9 @@
1
1
  module Termvas
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ class Terminal
5
+ def initialize: (?input: untyped, ?output: untyped, ?alt_screen: bool, ?tmux: bool, ?env: Hash[String, String]) -> void
6
+ def size: () -> [Integer, Integer]
7
+ def cell_size: () -> [Integer, Integer]
8
+ end
4
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-25 00:00:00.000000000 Z
11
+ date: 2026-09-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Half block, Kitty, iTerm2, and Sixel terminal output with input parsing.
14
14
  email:
@@ -18,6 +18,8 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".codespellignore"
22
+ - ".yamllint"
21
23
  - CHANGELOG.md
22
24
  - LICENSE.txt
23
25
  - README.md