Class: FunCi::Tui::Screen
- Inherits:
-
Object
- Object
- FunCi::Tui::Screen
- Defined in:
- lib/fun_ci/tui/screen.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #clear ⇒ Object
- #clear_below ⇒ Object
-
#initialize(output: $stdout, width: 80) ⇒ Screen
constructor
A new instance of Screen.
- #move_cursor_home ⇒ Object
- #println(text = "") ⇒ Object
- #render_board(rows, cursor_index:) ⇒ Object
- #render_empty_state ⇒ Object
- #render_footer(empty: false, confirming: false) ⇒ Object
- #render_header(streak_text:) ⇒ Object
- #restore_cursor ⇒ Object
- #save_cursor ⇒ Object
- #write_at(row, col, text) ⇒ Object
Constructor Details
#initialize(output: $stdout, width: 80) ⇒ Screen
Returns a new instance of Screen.
10 11 12 13 |
# File 'lib/fun_ci/tui/screen.rb', line 10 def initialize(output: $stdout, width: 80) @output = output @width = width end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/fun_ci/tui/screen.rb', line 8 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/fun_ci/tui/screen.rb', line 8 def width @width end |
Instance Method Details
#clear ⇒ Object
78 79 80 |
# File 'lib/fun_ci/tui/screen.rb', line 78 def clear @output.print "\e[2J\e[H" end |
#clear_below ⇒ Object
86 87 88 |
# File 'lib/fun_ci/tui/screen.rb', line 86 def clear_below @output.print "\e[J" end |
#move_cursor_home ⇒ Object
82 83 84 |
# File 'lib/fun_ci/tui/screen.rb', line 82 def move_cursor_home @output.print "\e[H" end |
#println(text = "") ⇒ Object
74 75 76 |
# File 'lib/fun_ci/tui/screen.rb', line 74 def println(text = "") @output.print "#{text}\e[K\r\n" end |
#render_board(rows, cursor_index:) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fun_ci/tui/screen.rb', line 63 def render_board(rows, cursor_index:) rows.each_with_index do |row, i| if cursor_index == i println "> #{row.lstrip}" else println row end println unless i == rows.length - 1 end end |
#render_empty_state ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/fun_ci/tui/screen.rb', line 53 def render_empty_state println "" println "" println " No runs yet." println "" println " Trigger one: fun-ci trigger HEAD" println " Or hook it: fun-ci install-hook pre-push" println "" end |
#render_footer(empty: false, confirming: false) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/fun_ci/tui/screen.rb', line 43 def (empty: false, confirming: false) if confirming println Ansi.dim(" Cancel running pipeline? y/n") elsif empty println Ansi.dim(" q quit") else println Ansi.dim(" j/k move c cancel q quit") end end |
#render_header(streak_text:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fun_ci/tui/screen.rb', line 29 def render_header(streak_text:) title = " fun-ci" if streak_text streak_display = Ansi.green(streak_text) plain_streak = streak_text padding = @width - title.length - plain_streak.length padding = 1 if padding < 1 line = "#{title}#{" " * padding}#{streak_display}" else line = title.ljust(@width) end println Ansi.bg_charcoal(Ansi.white(line)) end |
#restore_cursor ⇒ Object
98 99 100 |
# File 'lib/fun_ci/tui/screen.rb', line 98 def restore_cursor @output.print "\e[u" end |
#save_cursor ⇒ Object
94 95 96 |
# File 'lib/fun_ci/tui/screen.rb', line 94 def save_cursor @output.print "\e[s" end |
#write_at(row, col, text) ⇒ Object
90 91 92 |
# File 'lib/fun_ci/tui/screen.rb', line 90 def write_at(row, col, text) @output.print "\e[#{row};#{col}H#{text}" end |