rufio 1.6.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/README.md +17 -10
  4. data/README_ja.md +17 -9
  5. data/SECURITY.md +14 -6
  6. data/docs/csv_cell_preview_design_ja.md +682 -0
  7. data/docs/guide.md +109 -47
  8. data/docs/guide_ja.md +110 -48
  9. data/docs/image_preview_design_ja.md +335 -0
  10. data/docs/native_fuzzy_search_design_ja.md +2 -2
  11. data/examples/config.rb +23 -0
  12. data/info/help.md +32 -27
  13. data/info/keybindings.md +42 -12
  14. data/info/welcome.md +4 -6
  15. data/lib/rufio/background_status.rb +7 -0
  16. data/lib/rufio/bookmark_controller.rb +0 -45
  17. data/lib/rufio/clipboard.rb +162 -0
  18. data/lib/rufio/command_locator.rb +49 -0
  19. data/lib/rufio/config.rb +7 -2
  20. data/lib/rufio/config_loader.rb +56 -21
  21. data/lib/rufio/csv_table_source.rb +125 -0
  22. data/lib/rufio/encoding_detector.rb +152 -0
  23. data/lib/rufio/file_operation_controller.rb +41 -0
  24. data/lib/rufio/file_preview.rb +92 -19
  25. data/lib/rufio/graphics_layer.rb +223 -0
  26. data/lib/rufio/health_checker.rb +27 -10
  27. data/lib/rufio/help_menu.rb +16 -11
  28. data/lib/rufio/image_preview_view.rb +421 -0
  29. data/lib/rufio/image_source.rb +158 -0
  30. data/lib/rufio/keybind_handler.rb +21 -35
  31. data/lib/rufio/kitty_graphics.rb +128 -0
  32. data/lib/rufio/native/aarch64-linux-gnu/librufio_zig.so +0 -0
  33. data/lib/rufio/native/aarch64-linux-musl/librufio_zig.so +0 -0
  34. data/lib/rufio/native/aarch64-macos/librufio_zig.dylib +0 -0
  35. data/lib/rufio/native/aarch64-windows/rufio_zig.dll +0 -0
  36. data/lib/rufio/native/x86_64-linux-gnu/librufio_zig.so +0 -0
  37. data/lib/rufio/native/x86_64-linux-musl/librufio_zig.so +0 -0
  38. data/lib/rufio/native/x86_64-macos/librufio_zig.dylib +0 -0
  39. data/lib/rufio/native/x86_64-windows/rufio_zig.dll +0 -0
  40. data/lib/rufio/native_content_search.rb +1 -1
  41. data/lib/rufio/native_image.rb +177 -0
  42. data/lib/rufio/native_scanner_zig.rb +22 -0
  43. data/lib/rufio/navigation_controller.rb +47 -16
  44. data/lib/rufio/preview_registry.rb +86 -0
  45. data/lib/rufio/preview_view.rb +363 -0
  46. data/lib/rufio/renderer.rb +8 -8
  47. data/lib/rufio/screen.rb +33 -0
  48. data/lib/rufio/search_prompt.rb +50 -0
  49. data/lib/rufio/{global_search.rb → search_screen.rb} +41 -14
  50. data/lib/rufio/sheet_picker.rb +87 -0
  51. data/lib/rufio/sqlite_table_source.rb +205 -0
  52. data/lib/rufio/tab_mode_manager.rb +1 -3
  53. data/lib/rufio/table_cursor.rb +117 -0
  54. data/lib/rufio/table_document.rb +261 -0
  55. data/lib/rufio/table_layout.rb +231 -0
  56. data/lib/rufio/table_preview_view.rb +376 -0
  57. data/lib/rufio/table_query.rb +240 -0
  58. data/lib/rufio/table_source.rb +46 -0
  59. data/lib/rufio/terminal_graphics.rb +168 -0
  60. data/lib/rufio/terminal_ui.rb +63 -111
  61. data/lib/rufio/text_utils.rb +27 -0
  62. data/lib/rufio/ui_renderer.rb +379 -16
  63. data/lib/rufio/version.rb +1 -1
  64. data/lib/rufio/xlsx_table_source.rb +112 -0
  65. data/lib/rufio.rb +19 -5
  66. data/lib_zig/rufio_native/Makefile +6 -4
  67. data/lib_zig/rufio_native/build.zig +10 -0
  68. data/lib_zig/rufio_native/src/image.zig +525 -0
  69. data/lib_zig/rufio_native/src/image_bmp.zig +111 -0
  70. data/lib_zig/rufio_native/src/image_jpeg.zig +878 -0
  71. data/lib_zig/rufio_native/src/image_png.zig +561 -0
  72. data/lib_zig/rufio_native/src/image_resize.zig +170 -0
  73. data/lib_zig/rufio_native/src/image_test.zig +401 -0
  74. data/lib_zig/rufio_native/src/main.zig +1 -0
  75. data/lib_zig/rufio_native/src/search.zig +38 -19
  76. data/lib_zig/rufio_native/src/search_test.zig +35 -0
  77. data/lib_zig/rufio_native/src/testdata/alpha.png +0 -0
  78. data/lib_zig/rufio_native/src/testdata/gradient.bmp +0 -0
  79. data/lib_zig/rufio_native/src/testdata/gradient.jpg +0 -0
  80. data/lib_zig/rufio_native/src/testdata/gradient.png +0 -0
  81. data/retag.sh +4 -4
  82. metadata +37 -9
  83. data/lib/rufio/fuzzy_candidate_cache.rb +0 -258
  84. data/lib/rufio/fuzzy_finder.rb +0 -313
  85. data/lib/rufio/fuzzy_preview_loader.rb +0 -107
  86. data/lib/rufio/rga_result_source.rb +0 -89
  87. data/lib/rufio/search_controller.rb +0 -94
  88. data/lib_zig/rufio_native/src/main.zig.sync +0 -205
data/info/keybindings.md CHANGED
@@ -24,9 +24,20 @@ Complete reference of all keyboard shortcuts in **rufio**.
24
24
  | `d` | Delete file or directory (with confirmation) |
25
25
  | `a` | Create new file |
26
26
  | `A` | Create new directory |
27
+ | `y` | Copy the path of the current file to the clipboard |
27
28
 
28
29
  `.zip` previews list the archive entries (size, method, modified time, name) without extracting them.
29
30
 
31
+ Image previews (`.png`, `.jpg`, `.bmp`) use the Kitty graphics protocol when the terminal supports it; the bundled native library decodes and scales the picture down to the pane first. Otherwise the format, size and dimensions are shown as text. `RUFIO_IMAGE_PREVIEW=0` disables images, `RUFIO_NATIVE_IMAGE=0` only the decoding (PNG is then sent as-is).
32
+
33
+ ### Preview of an image
34
+ - **+** / **-**: Zoom in 25% steps, up to 4x
35
+ - **0**: Fit the picture to the pane
36
+ - **h/j/k/l** or the **arrow keys**: Move around the picture while zoomed
37
+ - **y**: Copy the file path | **ESC**: Back to the file list
38
+
39
+ `.csv`, `.tsv`, `.tab`, `.xlsx`, `.xlsm` and `.ods` previews, and SQLite databases when the `sqlite3` command is installed, show the file as a grid: column letters with the header row, row numbers, a fixed header while scrolling, and a last line with the row/column counts, the detected encoding and any truncation. `TABLE_PREVIEW` in `config.rb` changes the limits (`max_bytes`, up to 4 MiB, `max_rows`, `max_columns`, `max_column_width`) and the `header`, `delimiter` and `encoding` handling.
40
+
30
41
  Text previews read at most the first 64 KiB. PDF bodies are not previewed, keeping file navigation responsive.
31
42
 
32
43
  ## File Selection
@@ -37,6 +48,7 @@ Text previews read at most the first 64 KiB. PDF bodies are not previewed, keepi
37
48
  | `m` | Move selected items to current directory |
38
49
  | `c` | Copy selected items to current directory |
39
50
  | `x` | Delete selected items |
51
+ | `y` | Copy every selected path to the clipboard (one per line) |
40
52
  | `z` | Extract selected `.zip` files (each into `<name>/`) / compress selected items into one `.zip` |
41
53
 
42
54
  ZIP extraction and compression run as background jobs. Check progress in Jobs mode (`J`).
@@ -46,12 +58,9 @@ ZIP extraction and compression run as background jobs. Check progress in Jobs mo
46
58
  | Key | Action |
47
59
  |-----|--------|
48
60
  | `f` | Enter filter mode (type to filter) |
49
- | `s` | Fuzzy search file names |
50
- | `/` | Fuzzy search file names (same as `s`) |
51
- | `F` | Search file contents with rga and pick a result |
52
- | `G` | Global search: file names or contents across all bookmarks |
61
+ | `/` | Search under the current directory (file names or contents) |
53
62
 
54
- In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Down** or **Ctrl+J/K** to select, **Enter** to open and **ESC** to go back. **Ctrl+R** rescans a cached file list; wide screens show a preview of the selected file.
63
+ `/` is the only search key, and what it searches depends on where you are: the file list searches the directory tree, a preview searches inside the file, and a table preview filters its rows. In the file list it opens the search screen, where you type to filter, **Tab** switches between fuzzy file names and literal contents, **Up/Down** or **Ctrl+J/K** select, **Enter** goes to the file and **ESC** returns.
55
64
 
56
65
  ## Bookmarks & Navigation
57
66
 
@@ -61,8 +70,6 @@ In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Do
61
70
  | `B` | Bookmark menu (view/add/remove/script paths) |
62
71
  | `0` | Jump to startup directory |
63
72
  | `1-9` | Jump to bookmark 1-9 |
64
- | `Tab` | Cycle to next bookmark (Files mode) |
65
- | `Shift+Tab` | Cycle to previous bookmark (Files mode) |
66
73
  | `z` | Navigate using zoxide history (when nothing is selected) |
67
74
 
68
75
  ## Modes & Tool Runtime
@@ -70,7 +77,6 @@ In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Do
70
77
  | Key | Action |
71
78
  |-----|--------|
72
79
  | `:` | Enter command mode |
73
- | `G` | Global search mode |
74
80
  | `C` | Config mode: open `~/.config/rufio/` |
75
81
  | `J` | Job mode (view background jobs) |
76
82
  | `L` | View execution logs |
@@ -84,10 +90,32 @@ In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Do
84
90
 
85
91
  ### Preview
86
92
  - **P**: Open fullscreen file preview (hides the file list)
93
+ - **y**: Copy the file path to the clipboard
87
94
  - **j/k**: Scroll preview
88
95
  - **Ctrl+D/U**: Page down/up
96
+ - **/**: Search inside the file. Type to jump to the first match, `Enter` keeps it, **n** / **N** move to the next / previous match (wrapping around), `ESC` clears the search. Matches are highlighted, the current one in a different colour
97
+ - **ESC**: Back to the file list (clears a search first)
98
+
99
+ ### Preview of a table (`.csv` / `.tsv` / `.tab` / `.xlsx` / `.xlsm` / `.ods` / SQLite)
100
+ - **h/j/k/l** or the **arrow keys**: Move the cell cursor. The grid scrolls, horizontally as well, to keep the cursor in view and the header row in place
101
+ - **Ctrl+D/U**: Move one screen of rows
102
+ - **g/}**: First / last row
103
+ - **0/$**: First / last column of the row
104
+ - **Space**: Select / unselect the column under the cursor. The selected columns' cells are marked, and the line under the file name lists them (`cols A,C`). Switching sheets clears the selection
105
+ - **y**: Copy the cell under the cursor to the clipboard (the raw value, including any newlines inside it). With columns selected, it copies the cursor row's selected columns instead, joined with commas as one CSV line (`apple,30`), in column order
106
+ - **Y**: Copy the whole row as one CSV line
107
+ - **[/]**: Previous / next sheet, for a workbook's sheets or a database's tables
108
+ - **/**: Filter the rows. `price > 100, name a%` means price over 100 and a name starting with `a`; a term without a column is searched in every column. `Enter` applies it, `ESC` clears it. A SQLite table is filtered with a read-only `SELECT ... WHERE` inside the database, so rows past the preview's row limit are found too
109
+ - **t**: Open the list of sheets or tables. `j`/`k` or the arrow keys move, `Ctrl+D/U` page, `g/}` jump to the first and last entry, `Enter` opens the selected one, `ESC` closes the list. `>` marks the sheet on screen. A single-sheet file has no list
110
+ - The line under the file name shows the cell address and the column name, e.g. `R3C2 price`, and the result of a copy
89
111
  - **ESC**: Back to the file list
90
112
 
113
+ Cell movement follows the `move_up` / `move_down` / `navigate_parent` / `navigate_enter` keybinds, so rebinding `hjkl` applies here too.
114
+
115
+ A `.csv` or `.tsv` is read up to 512 KiB, and only `max_rows` rows of it are parsed, so a wider limit costs no more parsing. Only the sheet being shown is read, so a workbook's other sheets and a database's other tables cost nothing until you switch to them. A SQLite database is recognised by the file's own signature, whatever its extension. A spreadsheet over 10 MiB, or one that cannot be read, falls back to the ZIP entry list.
116
+
117
+ Copying uses `pbcopy`, `clip`, `wl-copy`, `xclip` or `xsel` when one is available, and OSC 52 otherwise, which also works over SSH if the terminal supports it (in tmux, `set -g set-clipboard on`). `CLIPBOARD_COMMAND` in `config.rb` sets your own command, and `rufio -c` reports which one is used.
118
+
91
119
  ### Filter Mode
92
120
  - **Any character**: Add to filter query
93
121
  - **Backspace**: Remove last character
@@ -109,14 +137,16 @@ In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Do
109
137
  - `cd <path>` - Go to a directory (paste a path; a file path selects the file, `cd -` goes back, `Tab` completes directories)
110
138
  - `command` - Execute a built-in or plugin command
111
139
 
112
- ### Global Search (G)
113
- - **Type**: Filter results (literal, case insensitive)
140
+ ### Search (`/`) in the file list
141
+ - **Type**: Filter results (fuzzy for file names, literal and case insensitive for contents)
114
142
  - **Tab**: Switch between file names and content
115
143
  - **Up/Down** or **Ctrl+J/K or Ctrl+N/P**: Select a result
116
144
  - **Enter**: Go to the selected file in Files mode
117
145
  - **Ctrl+U**: Clear the query
118
- - **ESC**: Return to the previous mode
146
+ - **ESC**: Return to Files mode
147
+ - Only the current directory tree is searched; bookmarks are not
119
148
  - Content search also reads `.pdf`, `.xlsx` and `.pptx`
149
+ - `SEARCH_EXCLUDED_EXTENSIONS` in `config.rb` skips extensions, or `/name` directories and files
120
150
 
121
151
  ### Config Mode (C)
122
152
  - Same navigation, preview and file operations as Files mode
@@ -140,7 +170,7 @@ In the built-in search screen (`s`, `/`, `F`), type to fuzzy-filter, use **Up/Do
140
170
 
141
171
  - **Vim users**: Navigation keys (`hjkl`) work exactly like Vim
142
172
  - **Selection**: Use `Space` to mark multiple files, then operate on all at once
143
- - **Quick access**: Number keys `1-9` and `Tab` provide instant access to bookmarks
173
+ - **Quick access**: Number keys `1-9` provide instant access to bookmarks
144
174
  - **Filtering**: Press `f` and start typing for real-time filtering
145
175
  - **Rake tasks**: Type `:rake:` then `Tab` to see available tasks
146
176
  - **Local scripts**: Scripts in the current directory are auto-detected with `@` prefix
data/info/welcome.md CHANGED
@@ -9,8 +9,8 @@ A TUI file manager that executes and coordinates tools and scripts from files.
9
9
  - **Tool Runtime** - Execute scripts and rake tasks from command mode
10
10
  - **Vim-like Keybindings** - Navigate with `j/k/h/l` keys
11
11
  - **Real-time Filtering** - Press `f` to filter files instantly
12
- - **Fuzzy Search** - Press `s` to fuzzy-search file names in a built-in screen, `F` to pick from `rga` content results
13
- - **Global Search** - Press `G` to search names or contents (including PDF/Excel/PowerPoint) across all bookmarks
12
+ - **One Search Key** - Press `/` to search: file names or contents (including PDF/Excel/PowerPoint) under the current directory, inside a preview, or the rows of a table
13
+ - **Grid & Image Previews** - View `.csv` / `.tsv` / `.xlsx` / `.ods` / SQLite as grids and `.png` / `.jpg` / `.bmp` in Kitty-compatible terminals
14
14
  - **ZIP Support** - Preview `.zip` contents, extract or compress selected items with `z`
15
15
  - **Bookmark Support** - Quick access to favorite directories
16
16
  - **Job Management** - Run commands in the background
@@ -25,12 +25,10 @@ Text previews read at most the first 64 KiB. PDF bodies are not previewed, keepi
25
25
  | `j/k` | Move down/up |
26
26
  | `h/l` | Go to parent / Enter directory |
27
27
  | `f` | Filter files |
28
- | `s` | Fuzzy search file names |
28
+ | `/` | Search under the current directory |
29
29
  | `b` | Add bookmark |
30
30
  | `B` | Bookmark menu |
31
- | `Tab` | Next bookmark |
32
31
  | `z` | zoxide history / extract or compress selected items |
33
- | `G` | Global search across bookmarks |
34
32
  | `C` | Config mode |
35
33
  | `:` | Command mode |
36
34
  | `J` | Job mode |
@@ -39,7 +37,7 @@ Text previews read at most the first 64 KiB. PDF bodies are not previewed, keepi
39
37
  | `q` | Quit |
40
38
  | `T` | Quit and cd to the current directory |
41
39
 
42
- In G mode, use `Up` / `Down` or `Ctrl+J` / `Ctrl+K` to select the next / previous result and `Enter` to open it. Application cursor arrows and extended Ctrl-key sequences are supported, including on Ghostty.
40
+ In the search screen, use `Up` / `Down` or `Ctrl+J` / `Ctrl+K` to select the next / previous result and `Enter` to open it. Application cursor arrows and extended Ctrl-key sequences are supported, including on Ghostty.
43
41
 
44
42
  ## Command Mode
45
43
 
@@ -16,6 +16,13 @@ module Rufio
16
16
  @expires_at = nil
17
17
  end
18
18
 
19
+ # 即時操作の結果など、短い通知を出す(DISPLAY_DURATION 秒後に自動で消える)。
20
+ def notify(message, now: Time.now)
21
+ @message = message
22
+ @expires_at = now + DISPLAY_DURATION
23
+ true
24
+ end
25
+
19
26
  # 描画に関わる状態が変化した場合だけ true を返す。
20
27
  def update(executor, now: Time.now)
21
28
  changed = expire(now)
@@ -18,7 +18,6 @@ module Rufio
18
18
  @notification_manager = notification_manager
19
19
  @zoxide_integration = zoxide_integration
20
20
  @terminal_ui = nil
21
- @last_bookmark_idx = nil
22
21
  end
23
22
 
24
23
  def set_terminal_ui(terminal_ui)
@@ -133,8 +132,6 @@ module Rufio
133
132
  return false unless bookmark
134
133
  return false unless @bookmark_manager.path_exists?(bookmark)
135
134
 
136
- # Tab循環位置を更新(数字キー後の Tab が次の番号から続くように)
137
- @last_bookmark_idx = number - 1
138
135
  navigate_to_directory(bookmark[:path])
139
136
  end
140
137
 
@@ -150,22 +147,6 @@ module Rufio
150
147
  navigate_to_directory(start_dir)
151
148
  end
152
149
 
153
- # 次のブックマークに移動(Tabキー)
154
- # 現在のディレクトリがブックマーク内なら current_path を基準に次へ、
155
- # そうでない場合は @last_bookmark_idx から継続(ブックマーク外に出ても循環が止まらない)
156
- # 存在しないパスのブックマークはスキップする
157
- # @return [Integer, nil] 新しいブックマークインデックス、またはnil
158
- def goto_next_bookmark
159
- cycle_bookmark(1)
160
- end
161
-
162
- # 前のブックマークに移動(Shift+Tabキー)
163
- # 存在しないパスのブックマークはスキップする
164
- # @return [Integer, nil] 新しいブックマークインデックス、またはnil
165
- def goto_prev_bookmark
166
- cycle_bookmark(-1)
167
- end
168
-
169
150
  # ============================
170
151
  # zoxide 連携
171
152
  # ============================
@@ -304,32 +285,6 @@ module Rufio
304
285
 
305
286
  private
306
287
 
307
- def cycle_bookmark(step)
308
- bookmarks = @bookmark_manager.list
309
- return nil unless bookmarks&.any?
310
-
311
- len = bookmarks.length
312
- current_path = @directory_listing.current_path
313
- current_position = bookmarks.find_index { |bm| bm[:path] == current_path }
314
- start_idx = if current_position
315
- (current_position + step + len) % len
316
- elsif @last_bookmark_idx
317
- (@last_bookmark_idx + step + len) % len
318
- else
319
- step > 0 ? 0 : len - 1
320
- end
321
-
322
- len.times do |i|
323
- idx = (start_idx + (i * step) + len) % len
324
- next unless Dir.exist?(bookmarks[idx][:path])
325
-
326
- @last_bookmark_idx = idx
327
- navigate_to_directory(bookmarks[idx][:path])
328
- return @last_bookmark_idx
329
- end
330
- nil
331
- end
332
-
333
288
  def show_notification(title, _message, type)
334
289
  return unless @notification_manager
335
290
 
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'rbconfig'
5
+ require_relative 'config_loader'
6
+ require_relative 'command_locator'
7
+
8
+ module Rufio
9
+ # クリップボードへのコピー。
10
+ #
11
+ # OS のコマンド(pbcopy / clip / wl-copy / xclip / xsel)を優先し、見つからなければ
12
+ # OSC 52 で端末に渡す。OSC 52 は SSH 越しでも届く代わりに、端末が対応しているかを
13
+ # 知る方法がない(成否が返らない)ため、どの手段を使ったかを呼び出し側で表示する。
14
+ #
15
+ # コマンドはシェルを経由せず argv で起動する(SECURITY.md の方針)。
16
+ module Clipboard
17
+ # コピーできる最大サイズ
18
+ MAX_BYTES = 100 * 1024
19
+ # OSC 52 で多くの端末が受け取れる上限の目安
20
+ OSC52_MAX_BYTES = 74_994
21
+ # コピー時に落とす末尾の改行
22
+ TRAILING_NEWLINES = /[\r\n]+\z/.freeze
23
+ # 改行とタブ以外の制御文字。セルの値としては意味を持たない一方、貼り付け先の端末を
24
+ # 操作しうる(ブラケットペーストが無効な端末では ESC がそのまま解釈される)
25
+ UNSAFE_CONTROL_CHARS = /[[:cntrl:]&&[^\n\t]]+/.freeze
26
+
27
+ Candidate = Struct.new(:name, :argv, keyword_init: true)
28
+
29
+ class << self
30
+ # @param text [String] コピーする文字列
31
+ # @return [Symbol, false] 使った手段(:pbcopy / :xclip / :osc52 ...)、失敗なら false
32
+ def copy(text, out: $stdout)
33
+ return false if text.nil?
34
+
35
+ # 末尾の改行は、シェルに貼り付けた瞬間にそのまま実行される原因になるため落とす。
36
+ # 途中の改行は値そのものなので残す(複数行だと分かるよう呼び出し側が件数を出す)。
37
+ # 改行・タブ以外の制御文字は、貼り付け先の端末を操作しうるので空白に置き換える
38
+ payload = sanitize(text.to_s)
39
+ return false if payload.empty? || payload.bytesize > MAX_BYTES
40
+
41
+ candidate = command_candidate
42
+ return candidate.name if candidate && run_command(candidate.argv, payload)
43
+
44
+ osc52(payload, out: out) ? :osc52 : false
45
+ end
46
+
47
+ # rufio -c(ヘルスチェック)用。使えそうな手段の名前
48
+ # @return [Symbol] コマンドが見つからなければ :osc52
49
+ def available_method
50
+ command_candidate&.name || :osc52
51
+ end
52
+
53
+ # 見つかったコマンドの argv(ヘルスチェックの表示用)
54
+ def available_command
55
+ command_candidate&.argv
56
+ end
57
+
58
+ # 設定や環境変数を読み直す(テスト用)
59
+ def reset!
60
+ @command_candidate = nil
61
+ @resolved = false
62
+ CommandLocator.reset!
63
+ end
64
+
65
+ private
66
+
67
+ def sanitize(text)
68
+ trimmed = text.sub(TRAILING_NEWLINES, '')
69
+ trimmed.match?(UNSAFE_CONTROL_CHARS) ? trimmed.gsub(UNSAFE_CONTROL_CHARS, ' ') : trimmed
70
+ end
71
+
72
+ def command_candidate
73
+ return @command_candidate if @resolved
74
+
75
+ @resolved = true
76
+ @command_candidate = candidates.find { |candidate| command_available?(candidate.argv.first) }
77
+ end
78
+
79
+ def candidates
80
+ [configured_candidate, *platform_candidates].compact
81
+ end
82
+
83
+ # config.rb の CLIPBOARD_COMMAND(文字列または argv 配列)
84
+ def configured_candidate
85
+ value = ConfigLoader.clipboard_command
86
+ return nil if value.nil?
87
+
88
+ argv = (value.is_a?(Array) ? value : [value]).map(&:to_s).reject(&:empty?)
89
+ return nil if argv.empty?
90
+
91
+ Candidate.new(name: :configured, argv: argv)
92
+ end
93
+
94
+ def platform_candidates
95
+ case RbConfig::CONFIG['host_os']
96
+ when /darwin/
97
+ [Candidate.new(name: :pbcopy, argv: ['pbcopy'])]
98
+ when /mswin|mingw|cygwin/
99
+ [
100
+ Candidate.new(name: :clip, argv: ['clip']),
101
+ Candidate.new(name: :set_clipboard,
102
+ argv: ['powershell', '-NoProfile', '-Command', '$input | Set-Clipboard'])
103
+ ]
104
+ else
105
+ unix_candidates
106
+ end
107
+ end
108
+
109
+ # Wayland / X11 のセッションがあるときだけコマンドを試す。
110
+ # SSH 越し(DISPLAY なし)では OSC 52 に任せる。
111
+ def unix_candidates
112
+ list = []
113
+ list << Candidate.new(name: :wl_copy, argv: ['wl-copy']) if env?('WAYLAND_DISPLAY')
114
+ if env?('DISPLAY')
115
+ list << Candidate.new(name: :xclip, argv: ['xclip', '-selection', 'clipboard'])
116
+ list << Candidate.new(name: :xsel, argv: ['xsel', '--clipboard', '--input'])
117
+ end
118
+ list
119
+ end
120
+
121
+ def env?(name)
122
+ value = ENV[name]
123
+ !value.nil? && !value.empty?
124
+ end
125
+
126
+ def command_available?(name)
127
+ CommandLocator.available?(name)
128
+ end
129
+
130
+ def run_command(argv, text)
131
+ IO.popen(argv, 'w') { |io| io.write(text) }
132
+ status = Process.last_status
133
+ status.nil? || status.success?
134
+ rescue SystemCallError, IOError
135
+ false
136
+ end
137
+
138
+ # OSC 52。tmux / screen の中では DCS パススルーで包む必要がある。
139
+ def osc52(text, out: $stdout)
140
+ sequence = "\e]52;c;#{Base64.strict_encode64(text)}\a"
141
+ return false if sequence.bytesize > OSC52_MAX_BYTES
142
+
143
+ out.write(wrap_for_multiplexer(sequence))
144
+ out.flush
145
+ true
146
+ rescue SystemCallError, IOError
147
+ false
148
+ end
149
+
150
+ def wrap_for_multiplexer(sequence)
151
+ if env?('TMUX')
152
+ # tmux 側は set-clipboard on が必要
153
+ "\ePtmux;#{sequence.gsub("\e", "\e\e")}\e\\"
154
+ elsif ENV['TERM'].to_s.start_with?('screen')
155
+ "\eP#{sequence.gsub("\e", "\e\e")}\e\\"
156
+ else
157
+ sequence
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbconfig'
4
+
5
+ module Rufio
6
+ # PATH 上にコマンドがあるかを調べる。
7
+ # which を起動しないので、キー入力ごとに呼ばれても負荷にならず、which が無い
8
+ # Windows でも動く(PATHEXT を見る)。
9
+ module CommandLocator
10
+ WINDOWS_DEFAULT_PATHEXT = '.COM;.EXE;.BAT;.CMD'
11
+
12
+ class << self
13
+ def available?(name)
14
+ cache.fetch(name) { cache[name] = locate(name) }
15
+ end
16
+
17
+ def reset!
18
+ @cache = {}
19
+ end
20
+
21
+ private
22
+
23
+ def cache
24
+ @cache ||= {}
25
+ end
26
+
27
+ def locate(name)
28
+ return false if name.nil? || name.to_s.empty?
29
+ return executable?(name) if name.to_s.include?(File::SEPARATOR)
30
+
31
+ ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).any? do |dir|
32
+ next false if dir.empty?
33
+
34
+ extensions.any? { |ext| executable?(File.join(dir, "#{name}#{ext}")) }
35
+ end
36
+ end
37
+
38
+ def extensions
39
+ return [''] unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
40
+
41
+ (ENV['PATHEXT'] || WINDOWS_DEFAULT_PATHEXT).split(';')
42
+ end
43
+
44
+ def executable?(path)
45
+ File.executable?(path) && !File.directory?(path)
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/rufio/config.rb CHANGED
@@ -34,6 +34,7 @@ module Rufio
34
34
  'file.cannot_preview' => 'Cannot preview',
35
35
  'file.encoding_error' => 'Character encoding error - cannot read file',
36
36
  'file.invalid_archive' => 'Invalid ZIP archive',
37
+ 'file.not_parsed_as_table' => 'not parsed as table',
37
38
  'file.preview_error' => 'Preview error',
38
39
  'file.error_prefix' => 'Error',
39
40
 
@@ -62,9 +63,14 @@ module Rufio
62
63
  'health.title' => 'rufio Health Check',
63
64
  'health.ruby_version' => 'Ruby version',
64
65
  'health.required_gems' => 'Required gems',
65
- 'health.rga' => 'rga (content search)',
66
+ 'health.sqlite3' => 'sqlite3 (SQLite preview)',
66
67
  'health.zoxide' => 'zoxide (directory history)',
67
68
  'health.bat' => 'bat (syntax highlight)',
69
+ 'health.clipboard' => 'Clipboard (y to copy)',
70
+ 'health.clipboard_osc52' => 'OSC 52 (no clipboard command found)',
71
+ 'health.clipboard_hint' => 'Install pbcopy, wl-copy, xclip or xsel for a local clipboard, ' \
72
+ 'or set CLIPBOARD_COMMAND. Over SSH, OSC 52 needs terminal support ' \
73
+ '(in tmux also set-clipboard on)',
68
74
  'health.file_opener' => 'System file opener',
69
75
  'health.summary' => 'Summary:',
70
76
  'health.ok' => 'OK',
@@ -85,7 +91,6 @@ module Rufio
85
91
  'health.install_brew' => 'Install: brew install',
86
92
  'health.install_apt' => 'Install: apt install',
87
93
  'health.install_guide' => 'Install: Check the installation guide for your platform',
88
- 'health.rga_releases' => 'Install: https://github.com/phiresky/ripgrep-all/releases',
89
94
  'health.ruby_upgrade_needed' => 'Please upgrade Ruby to version 2.7.0 or higher'
90
95
  }.freeze
91
96
 
@@ -14,11 +14,26 @@ module Rufio
14
14
  # 後方互換性のためのパス(非推奨)
15
15
  YAML_CONFIG_PATH = Config::YAML_CONFIG_PATH
16
16
  LOCAL_YAML_PATH = Config::LOCAL_YAML_PATH
17
- # 1.6.0 で改名したアクション(旧名 => 新名)。ユーザー設定の旧名も受け付ける
18
- LEGACY_KEYBIND_ACTIONS = { fzf_search: :file_search, fzf_search_alt: :file_search_alt }.freeze
19
- # s / / の一覧キャッシュ(FuzzyCandidateCache)。FUZZY_SEARCH_CACHE で MAX_FUZZY_SEARCH_CACHE まで変更できる
20
- DEFAULT_FUZZY_SEARCH_CACHE = { max_entries: 200_000, max_roots: 4, ttl: 300 }.freeze
21
- MAX_FUZZY_SEARCH_CACHE = { max_entries: 1_000_000, max_roots: 16, ttl: 86_400 }.freeze
17
+ # 改名・統合したアクション(旧名 => 新名)。ユーザー設定の旧名も受け付ける。
18
+ # 2.0.0 で検索を :search 一本にまとめたため、旧 s / / / F / G の設定は :search に移す
19
+ LEGACY_KEYBIND_ACTIONS = {
20
+ fzf_search: :search, fzf_search_alt: :search,
21
+ file_search: :search, file_search_alt: :search,
22
+ rga_search: :search, global_search: :search
23
+ }.freeze
24
+
25
+ # 表プレビュー(CSV / TSV / Excel / SQLite)の読み込み上限と表示設定。
26
+ # max_bytes はテキスト形式(CSV / TSV)を読む量。max_rows 行で解析を打ち切るため、
27
+ # ここを広げても解析時間は増えない(読み込みと文字コード判定の分だけ増える)。
28
+ DEFAULT_TABLE_PREVIEW = {
29
+ max_bytes: 512 * 1024, max_rows: 1000, max_columns: 256, max_column_width: 32
30
+ }.freeze
31
+ MIN_TABLE_PREVIEW = {
32
+ max_bytes: 1024, max_rows: 1, max_columns: 1, max_column_width: 3
33
+ }.freeze
34
+ MAX_TABLE_PREVIEW = {
35
+ max_bytes: 4 * 1024 * 1024, max_rows: 100_000, max_columns: 4096, max_column_width: 200
36
+ }.freeze
22
37
 
23
38
  class << self
24
39
  def load_config
@@ -63,14 +78,13 @@ module Rufio
63
78
  create_dir: 'A',
64
79
  move_selected: 'm',
65
80
  copy_selected: 'c',
81
+ copy_to_clipboard: 'y',
66
82
  delete_selected: 'x',
67
83
  open_explorer: 'e',
68
84
  # 選択・検索
69
85
  select: ' ',
70
86
  filter: 'f',
71
- file_search: 's',
72
- file_search_alt: '/',
73
- rga_search: 'F',
87
+ search: '/',
74
88
  # ブックマーク
75
89
  add_bookmark: 'b',
76
90
  bookmark_menu: 'B',
@@ -78,7 +92,6 @@ module Rufio
78
92
  start_dir: '0',
79
93
  # モード・ツール
80
94
  job_mode: 'J',
81
- global_search: 'G',
82
95
  config_mode: 'C',
83
96
  help: '?',
84
97
  log_viewer: 'L',
@@ -113,18 +126,35 @@ module Rufio
113
126
  default_keybinds.merge(renamed).merge(current)
114
127
  end
115
128
 
116
- # 0 以上の整数だけを受け付け、上限を超える値は上限に丸める。不正な値は既定値のまま
117
- def fuzzy_search_cache
118
- values = load_config[:fuzzy_search_cache]
129
+ # クリップボードへコピーするコマンド(文字列または argv 配列)。
130
+ # 未設定なら OS ごとの既定コマンド → OSC 52 の順で試す。
131
+ def clipboard_command
132
+ value = load_config[:clipboard_command]
133
+ return value if value.is_a?(String) && !value.empty?
134
+ return value if value.is_a?(Array) && value.all? { |item| item.is_a?(String) } && !value.empty?
135
+
136
+ nil
137
+ end
138
+
139
+ # 表プレビュー設定(整数は min..max に丸め、不正な値は既定値のまま)
140
+ def table_preview
141
+ values = load_config[:table_preview]
119
142
  values = {} unless values.is_a?(Hash)
120
- DEFAULT_FUZZY_SEARCH_CACHE.each_with_object({}) do |(key, default), settings|
143
+
144
+ settings = DEFAULT_TABLE_PREVIEW.each_with_object({}) do |(key, default), acc|
121
145
  value = values[key]
122
- settings[key] = value.is_a?(Integer) && value >= 0 ? [value, MAX_FUZZY_SEARCH_CACHE[key]].min : default
146
+ acc[key] = value.is_a?(Integer) ? value.clamp(MIN_TABLE_PREVIEW[key], MAX_TABLE_PREVIEW[key]) : default
123
147
  end
148
+
149
+ settings[:header] = values[:header] != false
150
+ settings[:delimiter] = values[:delimiter].is_a?(String) ? values[:delimiter] : 'auto'
151
+ settings[:encoding] = values[:encoding].is_a?(String) ? values[:encoding] : 'auto'
152
+ settings
124
153
  end
125
154
 
126
- def global_search_excluded_extensions
127
- values = load_config[:global_search_excluded_extensions]
155
+ # 検索(`/`)で中身を読まない拡張子・ディレクトリ
156
+ def search_excluded_extensions
157
+ values = load_config[:search_excluded_extensions]
128
158
  return [] unless values.is_a?(Array)
129
159
 
130
160
  values.select { |value| value.is_a?(String) }.map do |value|
@@ -313,8 +343,11 @@ module Rufio
313
343
  applications: safe_const_get(:APPLICATIONS, default_config[:applications]),
314
344
  colors: safe_const_get(:COLORS, default_config[:colors]),
315
345
  keybinds: safe_const_get(:KEYBINDS, {}),
316
- global_search_excluded_extensions: safe_const_get(:GLOBAL_SEARCH_EXCLUDED_EXTENSIONS, []),
317
- fuzzy_search_cache: safe_const_get(:FUZZY_SEARCH_CACHE, {})
346
+ # SEARCH_EXCLUDED_EXTENSIONS が新しい名前。旧名の設定もそのまま使える
347
+ search_excluded_extensions: safe_const_get(:SEARCH_EXCLUDED_EXTENSIONS,
348
+ safe_const_get(:GLOBAL_SEARCH_EXCLUDED_EXTENSIONS, [])),
349
+ table_preview: safe_const_get(:TABLE_PREVIEW, {}),
350
+ clipboard_command: safe_const_get(:CLIPBOARD_COMMAND, nil)
318
351
  }
319
352
 
320
353
  if Object.const_defined?(:LANGUAGE)
@@ -363,9 +396,11 @@ module Rufio
363
396
  selected: { hsl: [50, 90, 70] },
364
397
  preview: { hsl: [180, 60, 65] }
365
398
  },
366
- global_search_excluded_extensions: [],
367
- keybinds: {}, # ユーザーの上書きのみ格納(デフォルトはdefault_keybindsを参照)
368
- ui_options: {} # ユーザーの上書きのみ格納(デフォルトはdefault_ui_optionsを参照)
399
+ search_excluded_extensions: [],
400
+ keybinds: {}, # ユーザーの上書きのみ格納(デフォルトはdefault_keybindsを参照)
401
+ ui_options: {}, # ユーザーの上書きのみ格納(デフォルトはdefault_ui_optionsを参照)
402
+ table_preview: {}, # ユーザーの上書きのみ格納(デフォルトはDEFAULT_TABLE_PREVIEWを参照)
403
+ clipboard_command: nil # 未設定なら OS 既定のコマンド → OSC 52
369
404
  }
370
405
  end
371
406
  end