Class: Keisanjaku::Renderer
- Inherits:
-
Object
- Object
- Keisanjaku::Renderer
- Defined in:
- lib/keisanjaku/renderer.rb
Constant Summary collapse
- MIN_WIDTH =
60- DEFAULT_WIDTH =
100- LABEL_WIDTH =
6
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(color: true) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(state, width: DEFAULT_WIDTH, message: nil, highlight_scale: nil) ⇒ Object
Constructor Details
#initialize(color: true) ⇒ Renderer
Returns a new instance of Renderer.
10 11 12 |
# File 'lib/keisanjaku/renderer.rb', line 10 def initialize(color: true) @color = color end |
Class Method Details
.render(state, width: DEFAULT_WIDTH, color: true, message: nil, highlight_scale: nil) ⇒ Object
35 36 37 |
# File 'lib/keisanjaku/renderer.rb', line 35 def self.render(state, width: DEFAULT_WIDTH, color: true, message: nil, highlight_scale: nil) new(color: color).render(state, width: width, message: , highlight_scale: highlight_scale) end |
Instance Method Details
#render(state, width: DEFAULT_WIDTH, message: nil, highlight_scale: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/keisanjaku/renderer.rb', line 14 def render(state, width: DEFAULT_WIDTH, message: nil, highlight_scale: nil) width = [width.to_i, MIN_WIDTH].max rail_width = width - LABEL_WIDTH - 2 cursor_col = column_for(state.cursor, rail_width) highlight_name = highlight_scale&.to_s&.upcase lines = [] lines << border_line(rail_width, :top) lines.concat(render_scale("K", state, rail_width, cursor_col, highlight_name)) lines.concat(render_scale("A", state, rail_width, cursor_col, highlight_name)) lines << border_line(rail_width, :divider) = state.face == :front ? %w[B CI C] : %w[S T] .each { |name| lines.concat(render_scale(name, state, rail_width, cursor_col, highlight_name)) } lines << border_line(rail_width, :divider) lines.concat(render_scale("D", state, rail_width, cursor_col, highlight_name)) lines.concat(render_scale("L", state, rail_width, cursor_col, highlight_name)) lines << border_line(rail_width, :bottom) lines << status_line(state, width, highlight_name) lines << ANSI.fit(.to_s, width) if lines.map { |line| ANSI.fit(line, width) } end |