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: 70, width: 200 }.freeze

Class Method Summary collapse

Class Method Details

.clearObject



70
71
72
# File 'lib/excadg/tui.rb', line 70

def clear
  print "\e[2J\e[f"
end

.get_summary(has_failed, timed_out) ⇒ Object

private



44
45
46
47
# File 'lib/excadg/tui.rb', line 44

def get_summary has_failed, timed_out
  [timed_out ? 'execution timed out' : '🮱  execution completed',
   "#{has_failed ? '🯀  some' : '🮱  no'} vertices failed"]
end

.pending_verticesObject

gather pending vertices (in :new state) from the tracker and render dependencies they’re waiting for



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/excadg/tui.rb', line 90

def pending_vertices
  return nil if Broker.instance.vtracker.nil?
  if Broker.instance.vtracker.by_state[:new].nil? || Broker.instance.vtracker.by_state[:new].empty?
    return Block.column('... no pending vertices').h_pad!
  end

  Broker.instance.vtracker.by_state[:new].sort_by(&:name).collect { |v|
    deps = Broker.instance.vtracker.get_deps v
    deps = nil if deps.empty?
    deps&.sort_by!(&:state)
    width = 20
    Block.column(
      Block.column(v).fit!(width: width - 4).h_pad!.box!,
      '🮦',
      Block.column(*deps || 'no deps to wait').fit!(width: width - 4).h_pad!.box!
    ).fit!(width: width, fill: true).h_pad!(2)
  }
end

.refresh_sizesObject



74
75
76
77
78
79
# File 'lib/excadg/tui.rb', line 74

def refresh_sizes
  @content_size = {
    height: (IO.console&.winsize&.first.nil? || DEFAULT_BOX_SIZE[:height] < IO.console.winsize.first ? DEFAULT_BOX_SIZE[:height] : IO.console.winsize.first) - 4,
    width: (IO.console&.winsize&.last.nil? || DEFAULT_BOX_SIZE[:width] < IO.console&.winsize&.last ? DEFAULT_BOX_SIZE[:width] : IO.console.winsize.last) - 2
  }
end

.runObject

spawns a thread to show stats to console in background



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/excadg/tui.rb', line 22

def run
  Log.info 'spawning tui'
  Thread.report_on_exception = false
  @thread = Thread.new {
    loop {
      # print_in_box stats
      clear
      refresh_sizes
      print stats
      sleep DELAY
    }
  }
end

.state_statsObject

make states summary, one for a line with consistent placing



82
83
84
85
86
# File 'lib/excadg/tui.rb', line 82

def state_stats
  skeleton = StateMachine::GRAPH.vertices.collect { |v| [v, []] }.to_h
  filled = skeleton.merge(Broker.instance.vtracker.by_state.transform_values { |vertices| vertices.collect(&:name).join(', ') })
  filled.collect { |k, v| format '  %-10s: %s', k, "#{v.empty? ? '<none>' : v}" }
end

.stats(summary: nil) ⇒ Object

make summary paragraph on veritces



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/excadg/tui.rb', line 50

def stats summary: nil
  Block.column(
    Block.row(
      Block.column(summary || '🮚  running').h_pad!(1).v_align!(:center).box!.h_pad!,
      Block.column(
        *[
          "🮚  time spent (ms): #{DateTime.now.strftime('%Q').to_i - @started_at}",
          "#  vertices seen: #{Broker.instance.vtracker.graph.vertices.size}",
          '🮶  progress:'
        ] + state_stats,
        align: :left
      ).h_pad!(2)
    ),
    Block.row('🮲 🮳  pending vertices and their dependencies:').pad!,
    Block.row(*pending_vertices || 'tracking is n/a', align: :top).h_pad!,
    align: :left
  ).fit!(width: @content_size[:width], height: @content_size[:height], fill: true)
       .box!(corners: :sharp)
end

.summarize(has_failed, timed_out) ⇒ Object



36
37
38
39
40
# File 'lib/excadg/tui.rb', line 36

def summarize has_failed, timed_out
  @thread.kill
  clear
  print stats summary: get_summary(has_failed, timed_out)
end