Class: Rufio::BookmarkManager
- Inherits:
-
Object
- Object
- Rufio::BookmarkManager
- Defined in:
- lib/rufio/bookmark_manager.rb
Overview
Manages bookmark operations with interactive UI
Instance Method Summary collapse
-
#add(path, name) ⇒ Boolean
Add bookmark.
-
#add_interactive(path) ⇒ Boolean
Add a bookmark interactively.
-
#count ⇒ Integer
Get bookmark count.
-
#find_by_number(number) ⇒ Hash?
Get bookmark by number.
-
#get_left_pane_data ⇒ Array<String>
Get left pane display data for bookmarks.
-
#get_right_pane_data(number) ⇒ String
Get right pane display data for a selected bookmark.
-
#initialize(bookmark = nil, dialog_renderer = nil) ⇒ BookmarkManager
constructor
A new instance of BookmarkManager.
-
#list ⇒ Array<Hash>
Get all bookmarks.
-
#list_interactive ⇒ Hash?
List all bookmarks interactively.
-
#path_exists?(bookmark) ⇒ Boolean
Validate bookmark path exists.
-
#remove(name) ⇒ Boolean
Remove bookmark.
-
#remove_interactive ⇒ Boolean
Remove a bookmark interactively.
-
#rename_interactive ⇒ Boolean
Rename a bookmark interactively.
-
#set_terminal_ui(terminal_ui) ⇒ Object
terminal_ui を設定.
-
#show_menu(current_path) ⇒ Symbol?
Show bookmark menu and handle user selection.
Constructor Details
#initialize(bookmark = nil, dialog_renderer = nil) ⇒ BookmarkManager
Returns a new instance of BookmarkManager.
10 11 12 13 14 |
# File 'lib/rufio/bookmark_manager.rb', line 10 def initialize(bookmark = nil, dialog_renderer = nil) @bookmark = bookmark || create_default_bookmark @dialog_renderer = dialog_renderer @terminal_ui = nil end |
Instance Method Details
#add(path, name) ⇒ Boolean
Add bookmark
355 356 357 |
# File 'lib/rufio/bookmark_manager.rb', line 355 def add(path, name) @bookmark.add(path, name) end |
#add_interactive(path) ⇒ Boolean
Add a bookmark interactively
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rufio/bookmark_manager.rb', line 99 def add_interactive(path) return false unless @dialog_renderer # Show floating input dialog title = 'Add Bookmark' prompt = 'Enter bookmark name:' name = @dialog_renderer.show_input_dialog(title, prompt, { border_color: "\e[34m", # Blue title_color: "\e[1;34m", # Bold blue content_color: "\e[37m" # White }) return false if name.nil? || name.empty? # Add bookmark (name is already trimmed in show_input_dialog) if @bookmark.add(path, name) show_result_dialog('Bookmark Added', "Added: #{name}", :success) true else show_result_dialog('Add Failed', 'Failed to add bookmark', :error) false end end |
#count ⇒ Integer
Get bookmark count
387 388 389 |
# File 'lib/rufio/bookmark_manager.rb', line 387 def count @bookmark.list.length end |
#find_by_number(number) ⇒ Hash?
Get bookmark by number
332 333 334 |
# File 'lib/rufio/bookmark_manager.rb', line 332 def find_by_number(number) @bookmark.find_by_number(number) end |
#get_left_pane_data ⇒ Array<String>
Get left pane display data for bookmarks
368 369 370 371 372 373 |
# File 'lib/rufio/bookmark_manager.rb', line 368 def get_left_pane_data bookmarks = @bookmark.list bookmarks.map.with_index(1) do |bookmark, index| "#{index}. #{bookmark[:name]}" end end |
#get_right_pane_data(number) ⇒ String
Get right pane display data for a selected bookmark
378 379 380 381 382 383 |
# File 'lib/rufio/bookmark_manager.rb', line 378 def get_right_pane_data(number) bookmark = @bookmark.find_by_number(number) return '' unless bookmark "Name: #{bookmark[:name]}\nPath: #{bookmark[:path]}" end |
#list ⇒ Array<Hash>
Get all bookmarks
347 348 349 |
# File 'lib/rufio/bookmark_manager.rb', line 347 def list @bookmark.list end |
#list_interactive ⇒ Hash?
List all bookmarks interactively
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/rufio/bookmark_manager.rb', line 270 def list_interactive bookmarks = @bookmark.list if bookmarks.empty? show_result_dialog('No Bookmarks', 'No bookmarks found', :error) return nil end return nil unless @dialog_renderer # Build content lines content_lines = ['', 'Select a bookmark:',''] bookmarks.each_with_index do |bookmark, index| # Truncate path if too long display_path = bookmark[:path] if display_path.start_with?(Dir.home) display_path = display_path.sub(Dir.home, '~') end if display_path.length > 35 display_path = "...#{display_path[-32..]}" end content_lines << " #{index + 1}. #{bookmark[:name]}" content_lines << " #{display_path}" end content_lines << '' content_lines << 'Press 1-9 to select, ESC to cancel' title = 'Bookmarks' width = 60 height = [content_lines.length + 4, 20].min # Wait for selection selected_bookmark = nil (title, content_lines, { width: width, height: height, border_color: "\e[34m", # Blue title_color: "\e[1;34m", # Bold blue content_color: "\e[37m" # White }) do loop do input = STDIN.getch.downcase if input >= '1' && input <= '9' number = input.to_i if number > 0 && number <= bookmarks.length selected_bookmark = bookmarks[number - 1] break end elsif input == "\e" # ESC break end end nil end selected_bookmark end |
#path_exists?(bookmark) ⇒ Boolean
Validate bookmark path exists
339 340 341 342 343 |
# File 'lib/rufio/bookmark_manager.rb', line 339 def path_exists?(bookmark) return false unless bookmark Dir.exist?(bookmark[:path]) end |
#remove(name) ⇒ Boolean
Remove bookmark
362 363 364 |
# File 'lib/rufio/bookmark_manager.rb', line 362 def remove(name) @bookmark.remove(name) end |
#remove_interactive ⇒ Boolean
Remove a bookmark interactively
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/rufio/bookmark_manager.rb', line 201 def remove_interactive bookmarks = @bookmark.list if bookmarks.empty? show_result_dialog('No Bookmarks', 'No bookmarks found', :error) return false end return false unless @dialog_renderer # Build content lines for bookmark selection content_lines = ['', 'Select bookmark to delete:', ''] bookmarks.each_with_index do |bookmark, index| # Truncate path if too long display_path = bookmark[:path] if display_path.start_with?(Dir.home) display_path = display_path.sub(Dir.home, '~') end if display_path.length > 35 display_path = "...#{display_path[-32..]}" end content_lines << " #{index + 1}. #{bookmark[:name]}" content_lines << " #{display_path}" end content_lines << '' content_lines << 'Press 1-9 to select, ESC to cancel' title = 'Delete Bookmark' width = 60 height = [content_lines.length + 4, 20].min # Wait for selection selected_number = nil (title, content_lines, { width: width, height: height, border_color: "\e[31m", # Red (warning) title_color: "\e[1;31m", # Bold red content_color: "\e[37m" # White }) do loop do input = STDIN.getch.downcase if input >= '1' && input <= '9' number = input.to_i if number > 0 && number <= bookmarks.length selected_number = number break end elsif input == "\e" # ESC break end end nil end return false unless selected_number # Confirm deletion bookmark_to_remove = bookmarks[selected_number - 1] if show_remove_confirmation(bookmark_to_remove[:name]) @bookmark.remove(bookmark_to_remove[:name]) else false end end |
#rename_interactive ⇒ Boolean
Rename a bookmark interactively
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rufio/bookmark_manager.rb', line 125 def rename_interactive bookmarks = @bookmark.list if bookmarks.empty? show_result_dialog('No Bookmarks', 'No bookmarks found', :error) return false end return false unless @dialog_renderer # Build content lines for bookmark selection content_lines = ['', 'Select bookmark to rename:', ''] bookmarks.each_with_index do |bookmark, index| # Truncate path if too long display_path = bookmark[:path] if display_path.start_with?(Dir.home) display_path = display_path.sub(Dir.home, '~') end if display_path.length > 35 display_path = "...#{display_path[-32..]}" end content_lines << " #{index + 1}. #{bookmark[:name]}" content_lines << " #{display_path}" end content_lines << '' content_lines << 'Press 1-9 to select, ESC to cancel' title = 'Rename Bookmark' width = 60 height = [content_lines.length + 4, 20].min # Wait for selection selected_number = nil (title, content_lines, { width: width, height: height, border_color: "\e[33m", # Yellow title_color: "\e[1;33m", # Bold yellow content_color: "\e[37m" # White }) do loop do input = STDIN.getch.downcase if input >= '1' && input <= '9' number = input.to_i if number > 0 && number <= bookmarks.length selected_number = number break end elsif input == "\e" # ESC break end end nil end return false unless selected_number # Get new name bookmark_to_rename = bookmarks[selected_number - 1] old_name = bookmark_to_rename[:name] new_name = @dialog_renderer.show_input_dialog("Rename: #{old_name}", "Enter new name:", { border_color: "\e[33m", # Yellow title_color: "\e[1;33m", # Bold yellow content_color: "\e[37m" # White }) return false if new_name.nil? || new_name.empty? # Rename bookmark @bookmark.rename(old_name, new_name) end |
#set_terminal_ui(terminal_ui) ⇒ Object
terminal_ui を設定
17 18 19 |
# File 'lib/rufio/bookmark_manager.rb', line 17 def set_terminal_ui(terminal_ui) @terminal_ui = terminal_ui end |
#show_menu(current_path) ⇒ Symbol?
Show bookmark menu and handle user selection
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rufio/bookmark_manager.rb', line 37 def (current_path) return :cancel unless @dialog_renderer title = 'Bookmark Menu' content_lines = [ '', '[A]dd current directory to bookmarks', '[L]ist bookmarks', '[R]ename bookmark', '[D]elete bookmark', '', 'Press 1-9 to go to bookmark directly', '', 'Press any other key to cancel' ] dialog_width = 45 dialog_height = 4 + content_lines.length result = { action: :cancel } (title, content_lines, { width: dialog_width, height: dialog_height, border_color: "\e[34m", # Blue title_color: "\e[1;34m", # Bold blue content_color: "\e[37m" # White }) do # Wait for key input loop do input = STDIN.getch.downcase case input when 'a' result = { action: :add, path: current_path } break when 'l' result = { action: :list } break when 'r' result = { action: :rename } break when 'd' result = { action: :remove } break when '1', '2', '3', '4', '5', '6', '7', '8', '9' result = { action: :navigate, number: input.to_i } break else # Cancel result = { action: :cancel } break end end nil end result end |