Class: TuiTui::BoxChrome

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Attribute Details

#blObject (readonly)

Returns the value of attribute bl

Returns:

  • (Object)

    the current value of bl



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def bl
  @bl
end

#brObject (readonly)

Returns the value of attribute br

Returns:

  • (Object)

    the current value of br



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def br
  @br
end

#btObject (readonly)

Returns the value of attribute bt

Returns:

  • (Object)

    the current value of bt



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def bt
  @bt
end

#crossObject (readonly)

Returns the value of attribute cross

Returns:

  • (Object)

    the current value of cross



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def cross
  @cross
end

#hObject (readonly)

Returns the value of attribute h

Returns:

  • (Object)

    the current value of h



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def h
  @h
end

#ltObject (readonly)

Returns the value of attribute lt

Returns:

  • (Object)

    the current value of lt



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def lt
  @lt
end

#rtObject (readonly)

Returns the value of attribute rt

Returns:

  • (Object)

    the current value of rt



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def rt
  @rt
end

#tlObject (readonly)

Returns the value of attribute tl

Returns:

  • (Object)

    the current value of tl



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def tl
  @tl
end

#trObject (readonly)

Returns the value of attribute tr

Returns:

  • (Object)

    the current value of tr



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def tr
  @tr
end

#trackObject (readonly)

Returns the value of attribute track

Returns:

  • (Object)

    the current value of track



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def track
  @track
end

#ttObject (readonly)

Returns the value of attribute tt

Returns:

  • (Object)

    the current value of tt



5
6
7
# File 'lib/tui_tui/box_chrome.rb', line 5

def tt
  @tt
end

#vObject (readonly)

Returns the value of attribute v

Returns:

  • (Object)

    the current value of 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.

Returns:

  • (Boolean)


40
41
42
# File 'lib/tui_tui/box_chrome.rb', line 40

def self.supported?(total_width)
  total_width == PROBE_GLYPHS.length
end