Class: TuiTui::BoxChrome
- Inherits:
-
Data
- Object
- Data
- TuiTui::BoxChrome
- Defined in:
- lib/tui_tui/box_chrome.rb,
lib/tui_tui/box_chrome.rb
Overview
The glyph set used to draw chrome (frame borders, dividers, scrollbar track).
Constant Summary collapse
- ASCII =
new( tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|", lt: "+", rt: "+", tt: "+", bt: "+", cross: "+", track: "|" )
- UNICODE =
Single-line box drawing (U+2500..U+253C).
new( tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│", lt: "├", rt: "┤", tt: "┬", bt: "┴", cross: "┼", track: "│" )
- PROBE_GLYPHS =
The distinct Unicode glyphs chrome can emit, probed as one string.
"─│┌┐└┘├┤┬┴┼"- MIN_PROBE_COLS =
Narrower than this and the probe glyphs would wrap at column 1.
12
Instance Attribute Summary collapse
-
#bl ⇒ Object
readonly
Returns the value of attribute bl.
-
#br ⇒ Object
readonly
Returns the value of attribute br.
-
#bt ⇒ Object
readonly
Returns the value of attribute bt.
-
#cross ⇒ Object
readonly
Returns the value of attribute cross.
-
#h ⇒ Object
readonly
Returns the value of attribute h.
-
#lt ⇒ Object
readonly
Returns the value of attribute lt.
-
#rt ⇒ Object
readonly
Returns the value of attribute rt.
-
#tl ⇒ Object
readonly
Returns the value of attribute tl.
-
#tr ⇒ Object
readonly
Returns the value of attribute tr.
-
#track ⇒ Object
readonly
Returns the value of attribute track.
-
#tt ⇒ Object
readonly
Returns the value of attribute tt.
-
#v ⇒ Object
readonly
Returns the value of attribute v.
Class Method Summary collapse
-
.from(name) ⇒ Object
Resolve an override string to a chrome, or :auto when a probe is needed.
-
.resolve(input:, output:, term_cols:, env: ENV, prober: BoxProber.new) ⇒ Object
Full resolution given a live console.
-
.supported?(total_width) ⇒ Boolean
The capability gate: every probed glyph must render at width 1, so the total advance equals the glyph count.
Instance Attribute Details
#bl ⇒ Object (readonly)
Returns the value of attribute bl
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def bl @bl end |
#br ⇒ Object (readonly)
Returns the value of attribute br
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def br @br end |
#bt ⇒ Object (readonly)
Returns the value of attribute bt
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def bt @bt end |
#cross ⇒ Object (readonly)
Returns the value of attribute cross
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def cross @cross end |
#h ⇒ Object (readonly)
Returns the value of attribute h
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def h @h end |
#lt ⇒ Object (readonly)
Returns the value of attribute lt
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def lt @lt end |
#rt ⇒ Object (readonly)
Returns the value of attribute rt
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def rt @rt end |
#tl ⇒ Object (readonly)
Returns the value of attribute tl
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def tl @tl end |
#tr ⇒ Object (readonly)
Returns the value of attribute tr
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def tr @tr end |
#track ⇒ Object (readonly)
Returns the value of attribute track
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def track @track end |
#tt ⇒ Object (readonly)
Returns the value of attribute tt
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def tt @tt end |
#v ⇒ Object (readonly)
Returns the value of attribute v
5 6 7 |
# File 'lib/tui_tui/box_chrome.rb', line 5 def v @v end |
Class Method Details
.from(name) ⇒ Object
Resolve an override string to a chrome, or :auto when a probe is needed.
30 31 32 33 34 35 36 |
# File 'lib/tui_tui/box_chrome.rb', line 30 def self.from(name) case name.to_s.downcase when "ascii", "0", "off", "false" then ASCII when "unicode", "1", "on", "true" then UNICODE else :auto end end |
.resolve(input:, output:, term_cols:, env: ENV, prober: BoxProber.new) ⇒ Object
Full resolution given a live console. Honors TUITUI_BOX, else probes; falls back to ASCII when forced off, the terminal is too narrow, or the probe fails.
46 47 48 49 50 51 52 |
# File 'lib/tui_tui/box_chrome.rb', line 46 def self.resolve(input:, output:, term_cols:, env: ENV, prober: BoxProber.new) forced = from(env["TUITUI_BOX"].to_s) return forced unless forced == :auto return ASCII if term_cols < MIN_PROBE_COLS supported?(prober.measure_all(input: input, output: output)) ? UNICODE : ASCII end |
.supported?(total_width) ⇒ Boolean
The capability gate: every probed glyph must render at width 1, so the total advance equals the glyph count.
40 41 42 |
# File 'lib/tui_tui/box_chrome.rb', line 40 def self.supported?(total_width) total_width == PROBE_GLYPHS.length end |