Module: ExcADG::Tui
- Defined in:
- lib/excadg/tui.rb,
lib/excadg/tui/block.rb,
lib/excadg/tui/assets.rb,
lib/excadg/tui/format.rb
Overview
static assets to select from
Defined Under Namespace
Modules: Assets, Format Classes: Block
Constant Summary collapse
- MAX_VERTEX_TO_SHOW =
10- DELAY =
0.2
- DEFAULT_BOX_SIZE =
{ height: 50, width: 150 }.freeze
Class Method Summary collapse
- .clear ⇒ Object
-
.get_summary(has_failed, timed_out) ⇒ Object
private.
- .refresh_sizes ⇒ Object
-
.run ⇒ Object
spawns a thread to show stats to console in background.
-
.state_stats ⇒ Object
make states summary, one for a line with consistent placing.
-
.stats(summary: nil) ⇒ Object
make summary paragraph on veritces.
- .summarize(has_failed, timed_out) ⇒ Object
- .vertices_stats(vertice_pairs) ⇒ Object
Class Method Details
.clear ⇒ Object
65 66 67 |
# File 'lib/excadg/tui.rb', line 65 def clear print "\e[2J\e[f" end |
.get_summary(has_failed, timed_out) ⇒ Object
private
43 44 45 46 |
# File 'lib/excadg/tui.rb', line 43 def get_summary has_failed, timed_out [timed_out ? 'execution timed out' : 'execution completed', "#{has_failed ? 'some' : 'no'} vertices failed"] end |
.refresh_sizes ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/excadg/tui.rb', line 69 def refresh_sizes box_size = { height: IO.console&.winsize&.first.nil? || DEFAULT_BOX_SIZE[:height] < IO.console.winsize.first ? DEFAULT_BOX_SIZE[:height] : IO.console.winsize.first, width: IO.console&.winsize&.last.nil? || DEFAULT_BOX_SIZE[:width] < IO.console&.winsize&.last ? DEFAULT_BOX_SIZE[:width] : IO.console.winsize.last }.freeze @content_size = { height: box_size[:height] - 4, # 2 for borders, 1 for \n, 1 for remark width: box_size[:width] - 5 # 2 for borders, 2 to indent }.freeze @line_template = "│ %-#{@content_size[:width]}s │\n" end |
.run ⇒ Object
spawns a thread to show stats to console in background
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/excadg/tui.rb', line 22 def run Log.info 'spawning tui' @thread = Thread.new { loop { # print_in_box stats clear refresh_sizes print stats sleep DELAY } } end |
.state_stats ⇒ Object
make states summary, one for a line with consistent placing
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/excadg/tui.rb', line 82 def state_stats skeleton = StateMachine::GRAPH.vertices.collect { |v| [v, []] }.to_h # rubocop:disable Style/HashTransformValues filled = skeleton.merge Broker.data_store.to_a .group_by(&:state) .collect { |state, vertices| [state, vertices_stats(vertices)] } .to_h # rubocop:enable Style/HashTransformValues filled.collect { |k, v| format ' %-10s: %s', k, "#{v.empty? ? '<none>' : v}" } end |
.stats(summary: nil) ⇒ Object
make summary paragraph on veritces
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/excadg/tui.rb', line 49 def stats summary: nil Block.column( Block.column(summary || 'running').h_pad!(1).box!.v_align!(:center, width: @content_size[:width]), Block.column( *[ "time spent (ms): #{DateTime.now.strftime('%Q').to_i - @started_at}", "vertices seen: #{Broker.data_store.size}", 'progress:' ] + state_stats, align: :left ).h_pad!(2), align: :left ).fit!(width: @content_size[:width], height: @content_size[:height], fill: true) .box!(corners: :sharp) end |
.summarize(has_failed, timed_out) ⇒ Object
35 36 37 38 39 |
# File 'lib/excadg/tui.rb', line 35 def summarize has_failed, timed_out @thread.kill clear print stats summary: get_summary(has_failed, timed_out) end |
.vertices_stats(vertice_pairs) ⇒ Object
93 94 95 |
# File 'lib/excadg/tui.rb', line 93 def vertices_stats vertice_pairs vertice_pairs.collect(&:name).join(', ') end |