termvas 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e006617f9d17384317e9c45880fbdef15e35049894eb82013557d170e805c97d
4
- data.tar.gz: 05fc5d8aeff21250c54bef69b4cd81c023d1c6c02aaac47c1ad72046f3c22ccd
3
+ metadata.gz: d3cf29b6b2bd27eb84a1cda85bb993a8e5f642bb27c97aab69f944a968809374
4
+ data.tar.gz: 646acf9519788a0944ae798247a5d82ee7f63c8db098fb65892b0876ddca285e
5
5
  SHA512:
6
- metadata.gz: 64cad8ca3988821b0361941f9027c2ff763e7b5b16e5fd8ac7a6b7b9e6f5859697474fe2901f001f98c1525c825aeeb8dae5e3b1c4b70eabd79897a030db556e
7
- data.tar.gz: 3cdda1da18561fd32d131dda835f19fc6062b7f4626acef9b0713b5a8ea843cf788843b5f2750b9d656cced5fbf811bfece6c01a3dd257582f540675a2485f81
6
+ metadata.gz: 2c23b3ec1a1a79e1126e976df5c4aba2ba1fae6af962c86ffbcbdfc8c021efd9340892485f7441dac1205d44b99c35e8762e716a3fef18990c6fd7f7c5efe330
7
+ data.tar.gz: 768c92089cbec5566b6b7db8193cbedf5e51399ae86fcee805a7cfbb25b7af73438d734b48b7437b2ff29f8469d76dd059426f2f7815bb2a84bb2500a8769873
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [0.3.0] - Unreleased
4
+
5
+ - Expose terminal cell-size estimates for display fitting, with environment overrides.
4
6
 
5
7
  ## [0.2.0] - 2026-09-25
6
8
 
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
@@ -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.0"
5
5
  end
data/lib/termvas.rb CHANGED
@@ -271,10 +271,11 @@ module Termvas
271
271
  class Terminal
272
272
  attr_reader :input, :output
273
273
 
274
- def initialize(input: $stdin, output: $stdout, alt_screen: true, tmux: false)
274
+ def initialize(input: $stdin, output: $stdout, alt_screen: true, tmux: false, env: ENV)
275
275
  @input = input
276
276
  @output = output
277
277
  @alt_screen = alt_screen
278
+ @env = env
278
279
  @closed = false
279
280
  @opened = false
280
281
  @raw = false
@@ -288,10 +289,14 @@ module Termvas
288
289
  return [columns, rows] if rows.to_i.positive? && columns.to_i.positive?
289
290
 
290
291
  fallback_size
291
- rescue Errno::ENOTTY, IOError, NoMethodError
292
+ rescue Errno::ENODEV, Errno::ENOTTY, IOError, NoMethodError
292
293
  fallback_size
293
294
  end
294
295
 
296
+ def cell_size
297
+ [environment_dimension("TERMVAS_CELL_WIDTH", 8), environment_dimension("TERMVAS_CELL_HEIGHT", 16)]
298
+ end
299
+
295
300
  def open
296
301
  return self if @opened
297
302
  @opened = true
@@ -367,12 +372,19 @@ module Termvas
367
372
  end
368
373
 
369
374
  def fallback_size
370
- columns = Integer(ENV.fetch("COLUMNS", 80))
371
- rows = Integer(ENV.fetch("LINES", 24))
375
+ columns = Integer(@env.fetch("COLUMNS", 80))
376
+ rows = Integer(@env.fetch("LINES", 24))
372
377
  [columns.positive? ? columns : 80, rows.positive? ? rows : 24]
373
378
  rescue ArgumentError, TypeError
374
379
  [80, 24]
375
380
  end
381
+
382
+ def environment_dimension(name, fallback)
383
+ value = Integer(@env.fetch(name, fallback))
384
+ value.positive? ? value : fallback
385
+ rescue ArgumentError, TypeError
386
+ fallback
387
+ end
376
388
  end
377
389
 
378
390
  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,7 +1,7 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada