Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#bg(rgb = nil) ⇒ Object



109
# File 'lib/vete.rb', line 109

def bg(rgb=nil); rgb ? "\e[48;2;#{hex(rgb)}m" : "\e[49m"; end

#clear(line = nil) ⇒ Object



93
# File 'lib/vete.rb', line 93

def clear(line=nil); line ? "\e[K" : "\e[2J"        ; end

#cursor(on) ⇒ Object



94
# File 'lib/vete.rb', line 94

def cursor(on)     ; print on ? "\e[?25h": "\e[?25l"; end

#draw(live = 0, done = 0, died = 0, jobs = 0, info = nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/vete.rb', line 111

def draw(live=0, done=0, died=0, jobs=0, info=nil)

  # outer box # # ╰╯╭╮─└┘┌┐
  unless info
    print [
      clear,
      go(2 + @work, @len + 3) + "" + "" * (@wide + 2) + "╯\n",
      go(1        , @len + 3) + "" + "" * (@wide + 2) + "╮\n",
    ].join
    @work.times {|i| print " %*d │ %*s │\n" % [@len, i + 1, @wide, ""] }
    return
  end

  # worker bars
  ppct = (done + died).to_f / jobs
  most = info.values.max
  info.each do |slot, this|
    tpct = this.to_f / most
    cols = ppct * tpct * @wide
    print go(slot + 1, @len + 5) + bg("5383ec") + @char * cols + bg
  end

  # summary bar
  dpct = done.to_f / jobs
  lpct = live.to_f / jobs
  gcol = dpct * @wide
  ycol = lpct * @wide
  print [
    go(@work + 3, @len + 5),
    fg("fff"),
    bg("58a65c") + @char * (       gcol       ),      #  green (done)
    bg("f1bf42") + @char * (              ycol),      # yellow (live)
    bg("d85140") + " "  * (@wide - gcol - ycol).ceil, #    red (rest)
    go(@work + 3, @len + 5 + @wide + 3),
    bg("5383ec") + " %.1f%% " % [ppct * 100],         #   blue (done + died)
    done > 0 ? (bg + " " + bg("58a65c") + " #{done}/#{jobs} done ") : nil,
    died > 0 ? (bg + " " + bg("d85140") +         " #{died} died ") : nil,
  ].join + fg + bg
end

#fg(rgb = nil) ⇒ Object



108
# File 'lib/vete.rb', line 108

def fg(rgb=nil); rgb ? "\e[38;2;#{hex(rgb)}m" : "\e[39m"; end

#go(r = 1, c = 1) ⇒ Object



95
# File 'lib/vete.rb', line 95

def go(r=1,c=1)    ; "\e[#{r};#{c}H"                ; end

#go!Object



96
# File 'lib/vete.rb', line 96

def go!(...)       ; print go(...)                  ; end

#hex(str = nil) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/vete.rb', line 100

def hex(str=nil)
  @hex[str] ||= begin
    str =~ /\A#?(?:(\h\h)(\h\h)(\h\h)|(\h)(\h)(\h))\z/ or return
    r, g, b = $1 ? [$1, $2, $3] : [$4*2, $5*2, $6*2]
    [r.hex, g.hex, b.hex] * ";"
  end
end

#move(path, dest) ⇒ Object



59
60
61
62
# File 'lib/vete.rb', line 59

def move(path, dest)
  dest = File.join(dest, File.basename(path)) unless path.is_a?(Array)
  FileUtils.mv(path, dest, force: true, secure: true)
end

#nukeObject



64
65
66
# File 'lib/vete.rb', line 64

def nuke
  FileUtils.rm_rf(@vete)
end

#vete_initObject



73
74
75
76
77
# File 'lib/vete.rb', line 73

def vete_init
  nuke
  list = [@todo, @done, @died]
  list.each {|path| FileUtils.mkdir_p(path) }
end

#vete_retryObject



79
80
81
82
# File 'lib/vete.rb', line 79

def vete_retry
  list = Dir.glob(File.join(@died, "*")).sort.each {|path| FileUtils.touch(path) }
  list.empty? ? false : !!move(list, @todo)
end

#vete_todo(path, data = nil) ⇒ Object



84
85
86
87
# File 'lib/vete.rb', line 84

def vete_todo(path, data=nil)
  path = File.join(@todo, path.to_s)
  data ? File.write(path, data) : FileUtils.touch(path)
end