Class: Rufio::NavigationController

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/navigation_controller.rb

Overview

ナビゲーション専用コントローラKeybindHandler から移動・フィルタ・プレビュースクロール系メソッドを分離し、単一責任原則に準拠

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory_listing, filter_manager) ⇒ NavigationController

Returns a new instance of NavigationController.



12
13
14
15
16
17
18
19
20
# File 'lib/rufio/navigation_controller.rb', line 12

def initialize(directory_listing, filter_manager)
  @directory_listing = directory_listing
  @filter_manager = filter_manager
  @current_index = 0
  @preview_focused = false
  @preview_scroll_offset = 0
  @file_opener = FileOpener.new
  @terminal_ui = nil
end

Instance Attribute Details

#current_indexObject (readonly)

Returns the value of attribute current_index.



10
11
12
# File 'lib/rufio/navigation_controller.rb', line 10

def current_index
  @current_index
end

#preview_scroll_offsetObject (readonly)

Returns the value of attribute preview_scroll_offset.



10
11
12
# File 'lib/rufio/navigation_controller.rb', line 10

def preview_scroll_offset
  @preview_scroll_offset
end

Instance Method Details

#clear_filter_modeObject



159
160
161
162
# File 'lib/rufio/navigation_controller.rb', line 159

def clear_filter_mode
  @filter_manager.clear_filter
  @current_index = 0
end

#exit_filter_modeObject

後方互換用エイリアス



165
166
167
# File 'lib/rufio/navigation_controller.rb', line 165

def exit_filter_mode
  clear_filter_mode
end

#exit_filter_mode_keep_filterObject



155
156
157
# File 'lib/rufio/navigation_controller.rb', line 155

def exit_filter_mode_keep_filter
  @filter_manager.exit_filter_mode_keep_filter
end

#focus_preview_pane(entry) ⇒ Object

Parameters:

  • entry (Hash)

    現在選択中のエントリ



178
179
180
181
182
183
184
185
# File 'lib/rufio/navigation_controller.rb', line 178

def focus_preview_pane(entry)
  return false unless entry
  return false unless entry[:type] == 'file'

  @preview_focused = true
  @preview_scroll_offset = 0
  true
end

#handle_enter_key(entry, in_help_mode, in_log_viewer_mode) ⇒ Object

Enterキーの処理:ファイルならプレビューフォーカス、ディレクトリならナビゲート

Parameters:

  • entry (Hash)

    現在選択中のエントリ

  • in_help_mode (Boolean)
  • in_log_viewer_mode (Boolean)


256
257
258
259
260
261
262
263
264
# File 'lib/rufio/navigation_controller.rb', line 256

def handle_enter_key(entry, in_help_mode, in_log_viewer_mode)
  return false unless entry

  if entry[:type] == 'file'
    focus_preview_pane(entry)
  else
    navigate_enter(entry, in_help_mode, in_log_viewer_mode)
  end
end

#handle_filter_input(key) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rufio/navigation_controller.rb', line 138

def handle_filter_input(key)
  result = @filter_manager.handle_filter_input(key)

  case result
  when :exit_clear
    clear_filter_mode
  when :exit_keep
    exit_filter_mode_keep_filter
  when :backspace_exit
    clear_filter_mode
  when :continue
    @current_index = [@current_index, [@filter_manager.filtered_entries.length - 1, 0].max].min
  end

  true
end

#handle_preview_focus_key(key) ⇒ Object

プレビューペインフォーカス中のキー処理



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/rufio/navigation_controller.rb', line 235

def handle_preview_focus_key(key)
  case key
  when 'j', "\e[B"  # j or Down arrow
    scroll_preview_down
  when 'k', "\e[A"  # k or Up arrow
    scroll_preview_up
  when "\x04"  # Ctrl+D
    scroll_preview_page_down
  when "\x15"  # Ctrl+U
    scroll_preview_page_up
  when "\e"   # ESC
    unfocus_preview_pane
  else
    false
  end
end

#move_down(entries) ⇒ Object

移動メソッド



39
40
41
42
43
# File 'lib/rufio/navigation_controller.rb', line 39

def move_down(entries)
  @current_index = [@current_index + 1, entries.length - 1].min
  reset_preview_scroll
  true
end

#move_to_bottom(entries) ⇒ Object



56
57
58
59
# File 'lib/rufio/navigation_controller.rb', line 56

def move_to_bottom(entries)
  @current_index = [entries.length - 1, 0].max
  true
end

#move_to_topObject



51
52
53
54
# File 'lib/rufio/navigation_controller.rb', line 51

def move_to_top
  @current_index = 0
  true
end

#move_upObject



45
46
47
48
49
# File 'lib/rufio/navigation_controller.rb', line 45

def move_up
  @current_index = [@current_index - 1, 0].max
  reset_preview_scroll
  true
end

エントリに対してEnterキーの動作を実行

Parameters:

  • entry (Hash)

    対象エントリ

  • in_help_mode (Boolean)

    ヘルプモード中かどうか

  • in_log_viewer_mode (Boolean)

    ログビューワモード中かどうか



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rufio/navigation_controller.rb', line 69

def navigate_enter(entry, in_help_mode, in_log_viewer_mode)
  return false unless entry

  if entry[:type] == 'directory'
    return false if in_help_mode || in_log_viewer_mode

    result = @directory_listing.navigate_to(entry[:name])
    if result
      @current_index = 0
      clear_filter_mode
    end
    result
  else
    false
  end
end


86
87
88
89
90
91
92
93
94
95
# File 'lib/rufio/navigation_controller.rb', line 86

def navigate_parent
  return false unless @directory_listing

  result = @directory_listing.navigate_to_parent
  if result
    @current_index = 0
    clear_filter_mode
  end
  result
end

#open_current_file(entry) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/rufio/navigation_controller.rb', line 111

def open_current_file(entry)
  return false unless entry

  if entry[:type] == 'file'
    @file_opener.open_file(entry[:path])
    :needs_refresh
  else
    false
  end
end

#open_directory_in_explorerObject



122
123
124
125
126
# File 'lib/rufio/navigation_controller.rb', line 122

def open_directory_in_explorer
  current_path = @directory_listing&.current_path || Dir.pwd
  @file_opener.open_directory_in_explorer(current_path)
  true
end

#preview_focused?Boolean

プレビューペインフォーカス

Returns:

  • (Boolean)


173
174
175
# File 'lib/rufio/navigation_controller.rb', line 173

def preview_focused?
  @preview_focused
end

#refreshObject



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rufio/navigation_controller.rb', line 97

def refresh
  @terminal_ui&.refresh_display
  return false unless @directory_listing

  @directory_listing.refresh
  if @filter_manager.filter_active?
    @filter_manager.update_entries(@directory_listing.list_entries)
  else
    entries = @directory_listing.list_entries
    @current_index = [@current_index, entries.length - 1].min if entries.any?
  end
  true
end

#reset_preview_scrollObject



226
227
228
# File 'lib/rufio/navigation_controller.rb', line 226

def reset_preview_scroll
  @preview_scroll_offset = 0
end

#scroll_preview_downObject

プレビュースクロール



198
199
200
201
202
203
# File 'lib/rufio/navigation_controller.rb', line 198

def scroll_preview_down
  return false unless @preview_focused

  @preview_scroll_offset += 1
  true
end

#scroll_preview_page_downObject



212
213
214
215
216
217
# File 'lib/rufio/navigation_controller.rb', line 212

def scroll_preview_page_down
  return false unless @preview_focused

  @preview_scroll_offset += 20
  true
end

#scroll_preview_page_upObject



219
220
221
222
223
224
# File 'lib/rufio/navigation_controller.rb', line 219

def scroll_preview_page_up
  return false unless @preview_focused

  @preview_scroll_offset = [@preview_scroll_offset - 20, 0].max
  true
end

#scroll_preview_upObject



205
206
207
208
209
210
# File 'lib/rufio/navigation_controller.rb', line 205

def scroll_preview_up
  return false unless @preview_focused

  @preview_scroll_offset = [@preview_scroll_offset - 1, 0].max
  true
end

#select_index(index) ⇒ Object



31
32
33
# File 'lib/rufio/navigation_controller.rb', line 31

def select_index(index)
  @current_index = index
end

#set_directory_listing(directory_listing) ⇒ Object



26
27
28
29
# File 'lib/rufio/navigation_controller.rb', line 26

def set_directory_listing(directory_listing)
  @directory_listing = directory_listing
  @current_index = 0
end

#set_terminal_ui(terminal_ui) ⇒ Object



22
23
24
# File 'lib/rufio/navigation_controller.rb', line 22

def set_terminal_ui(terminal_ui)
  @terminal_ui = terminal_ui
end

#start_filter_modeObject

フィルタ



132
133
134
135
136
# File 'lib/rufio/navigation_controller.rb', line 132

def start_filter_mode
  @filter_manager.start_filter_mode(@directory_listing.list_entries)
  @current_index = 0
  true
end

#unfocus_preview_paneObject



187
188
189
190
191
192
# File 'lib/rufio/navigation_controller.rb', line 187

def unfocus_preview_pane
  return false unless @preview_focused

  @preview_focused = false
  true
end