Class: Rufio::JobMode
- Inherits:
-
Object
- Object
- Rufio::JobMode
- Defined in:
- lib/rufio/job_mode.rb
Overview
ジョブモードのUI管理クラスジョブ一覧の表示、選択、操作を行う
Instance Attribute Summary collapse
-
#selected_index ⇒ Object
readonly
Returns the value of attribute selected_index.
Instance Method Summary collapse
-
#activate ⇒ Object
ジョブモードを有効化.
-
#active? ⇒ Boolean
ジョブモードが有効かどうか.
-
#cancel_selected_job ⇒ Boolean
選択中のジョブをキャンセル.
-
#deactivate ⇒ Object
ジョブモードを無効化.
-
#enter_log_mode ⇒ Object
ログモードに入る.
-
#exit_log_mode ⇒ Object
ログモードを終了.
-
#handle_key(key) ⇒ Boolean, Symbol
キー入力を処理.
-
#initialize(job_manager:) ⇒ JobMode
constructor
A new instance of JobMode.
-
#log_mode? ⇒ Boolean
ログモードが有効かどうか.
-
#move_down ⇒ Object
下に移動.
-
#move_to_bottom ⇒ Object
末尾に移動.
-
#move_to_top ⇒ Object
先頭に移動.
-
#move_up ⇒ Object
上に移動.
-
#selected_job ⇒ TaskStatus?
選択中のジョブを取得.
Constructor Details
#initialize(job_manager:) ⇒ JobMode
Returns a new instance of JobMode.
9 10 11 12 13 14 |
# File 'lib/rufio/job_mode.rb', line 9 def initialize(job_manager:) @job_manager = job_manager @active = false @selected_index = 0 @log_mode = false end |
Instance Attribute Details
#selected_index ⇒ Object (readonly)
Returns the value of attribute selected_index.
7 8 9 |
# File 'lib/rufio/job_mode.rb', line 7 def selected_index @selected_index end |
Instance Method Details
#activate ⇒ Object
ジョブモードを有効化
17 18 19 20 21 |
# File 'lib/rufio/job_mode.rb', line 17 def activate @active = true @selected_index = 0 @log_mode = false end |
#active? ⇒ Boolean
ジョブモードが有効かどうか
31 32 33 |
# File 'lib/rufio/job_mode.rb', line 31 def active? @active end |
#cancel_selected_job ⇒ Boolean
選択中のジョブをキャンセル
82 83 84 85 86 87 |
# File 'lib/rufio/job_mode.rb', line 82 def cancel_selected_job job = selected_job return false unless job @job_manager.cancel_job(job.id) end |
#deactivate ⇒ Object
ジョブモードを無効化
24 25 26 27 |
# File 'lib/rufio/job_mode.rb', line 24 def deactivate @active = false @log_mode = false end |
#enter_log_mode ⇒ Object
ログモードに入る
42 43 44 |
# File 'lib/rufio/job_mode.rb', line 42 def enter_log_mode @log_mode = true end |
#exit_log_mode ⇒ Object
ログモードを終了
47 48 49 |
# File 'lib/rufio/job_mode.rb', line 47 def exit_log_mode @log_mode = false end |
#handle_key(key) ⇒ Boolean, Symbol
キー入力を処理
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rufio/job_mode.rb', line 92 def handle_key(key) # ログモード中の処理 if @log_mode return handle_log_mode_key(key) end case key when 'j' move_down true when 'k' move_up true when 'g' move_to_top true when 'G' move_to_bottom true when 'x' cancel_selected_job true when ' ' # Space enter_log_mode if selected_job :show_log when "\e" # Escape deactivate :exit else false end end |
#log_mode? ⇒ Boolean
ログモードが有効かどうか
37 38 39 |
# File 'lib/rufio/job_mode.rb', line 37 def log_mode? @log_mode end |
#move_down ⇒ Object
下に移動
52 53 54 55 |
# File 'lib/rufio/job_mode.rb', line 52 def move_down max_index = [@job_manager.job_count - 1, 0].max @selected_index = [@selected_index + 1, max_index].min end |
#move_to_bottom ⇒ Object
末尾に移動
68 69 70 |
# File 'lib/rufio/job_mode.rb', line 68 def move_to_bottom @selected_index = [@job_manager.job_count - 1, 0].max end |
#move_to_top ⇒ Object
先頭に移動
63 64 65 |
# File 'lib/rufio/job_mode.rb', line 63 def move_to_top @selected_index = 0 end |
#move_up ⇒ Object
上に移動
58 59 60 |
# File 'lib/rufio/job_mode.rb', line 58 def move_up @selected_index = [@selected_index - 1, 0].max end |
#selected_job ⇒ TaskStatus?
選択中のジョブを取得
74 75 76 77 78 |
# File 'lib/rufio/job_mode.rb', line 74 def selected_job return nil if @job_manager.jobs.empty? @job_manager.jobs[@selected_index] end |