lib/fasten/ui/curses.rb in fasten-0.5.2 vs lib/fasten/ui/curses.rb in fasten-0.5.4

- old
+ new

@@ -5,10 +5,11 @@ module Fasten module UI class Curses include ::Curses extend Forwardable + def_delegators :executor, :worker_list, :task_list, :task_done_list, :task_error_list, :task_running_list, :task_waiting_list, :worker_list def_delegators :executor, :name, :workers, :workers=, :state, :state= attr_accessor :n_rows, :n_cols, :clear_needed, :message, :executor @@ -137,17 +138,17 @@ ui_state end def ui_state - if state == :RUNNING + if executor.running? attrs = color_pair(2) - elsif state == :PAUSING + elsif executor.pausing? attrs = color_pair(1) | A_BLINK | A_STANDOUT - elsif state == :PAUSED + elsif executor.paused? attrs = color_pair(1) | A_STANDOUT - elsif state == :QUITTING + elsif executor.quitting? attrs = color_pair(3) | A_BLINK | A_STANDOUT end l = ui_text_aligned(1, :right, state.to_s, attrs) return unless message @@ -159,11 +160,11 @@ def ui_progressbar(row, col_ini, col_fin, count, total) slice = total.to_f / (col_fin - col_ini + 1) col_ini.upto col_fin do |col| setpos row, col count -= slice - if count.positive? + if count >= 0 addstr PROGRESSBAR_STR[-1] elsif count > -slice addstr PROGRESSBAR_STR[(count * PROGRESSBAR_LEN / slice) % PROGRESSBAR_LEN] else addstr '.' @@ -177,12 +178,14 @@ SPINNER_STR[task.worker&.spinner] when :FAIL '✘' when :DONE '✔' - else + when :WAIT '…' + else + ' ' end end def ui_task_color(task) case task.state @@ -191,11 +194,15 @@ when :FAIL color_pair(3) | A_TOP when :DONE color_pair(2) | A_TOP else - color_pair(4) | A_TOP + if task_waiting_list.include? task + A_TOP + else + color_pair(4) | A_DIM + end end end def ui_task_string(task, y, x, icon: nil, str: nil) setpos y, x @@ -225,30 +232,37 @@ ui_text_aligned(2, :right, "#{(count_done * 100 / count_total).to_i}%") if count_total.positive? ui_progressbar(2, col_ini, col_fin, count_done, count_total) max = 2 - list = task_list.sort_by(&:run_score) + list = task_list.sort_by.with_index { |x, index| [x.run_score, index] } list.each_with_index do |task, index| next if 3 + index >= n_rows x = ui_task_string(task, 3 + index, 2, icon: true) max = x if x > max end list.each_with_index do |task, index| next if 3 + index >= n_rows - if task.dif - setpos 3 + index, max + 2 - ui_task_string(task, 3 + index, max + 2, str: format('%.2f s', task.dif)) - elsif task.depends && !task.depends.empty? - setpos 3 + index, max - x = max + 2 - addstr ':' + if task.depends && !task.depends.empty? + x = max + x = ui_task_string(task, 3 + index, x, str: ':') + 1 task.depends.each do |dependant_task| x = ui_task_string(dependant_task, 3 + index, x) + 1 end + else + x = max + 1 + last = executor.stats_last(task) + if task.dif + str = format ' %.2f s', task.dif + elsif last['avg'] && last['err'] + str = format '≈ %.2f s ± %.2f %s', last['avg'], last['err'], task.worker&.name + elsif last['avg'] + str = format '≈ %.2f s %s', last['avg'], task.worker&.name + end + ui_task_string(task, 3 + index, x, str: str) if str end end end end end