Class: FunCi::Tui::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_ci/tui/screen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/fun_ci/tui/screen.rb', line 8

def height
  @height
end

#widthObject

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

#clearObject



78
79
80
# File 'lib/fun_ci/tui/screen.rb', line 78

def clear
  @output.print "\e[2J\e[H"
end

#clear_belowObject



86
87
88
# File 'lib/fun_ci/tui/screen.rb', line 86

def clear_below
  @output.print "\e[J"
end

#move_cursor_homeObject



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_stateObject



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


43
44
45
46
47
48
49
50
51
# File 'lib/fun_ci/tui/screen.rb', line 43

def render_footer(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_cursorObject



98
99
100
# File 'lib/fun_ci/tui/screen.rb', line 98

def restore_cursor
  @output.print "\e[u"
end

#save_cursorObject



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