diff options
| author | divens <divens@users.noreply.github.com> | 2026-03-21 19:20:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-21 19:20:32 +0100 |
| commit | 3fa7744906d5704bdec771c74829841bd06cf7fc (patch) | |
| tree | 6c4f0bd64c2e6087ce069a466cca942f4669f513 /default-plugins/strider/src/shared.rs | |
| parent | Release notes and fixes (#4879) (diff) | |
| download | sl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.tar.gz sl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.tar.xz sl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.zip | |
Add windows support in strider (#4854)
* Add Windows path support to strider plugin
Strider is a WASM plugin where std::path::PathBuf uses Unix semantics,
so Windows backslash paths break parent(), join(), strip_prefix(), etc.
Fix by normalizing all incoming paths to forward slashes at plugin
boundaries and converting back to native backslashes for display. A new
platform.rs module detects the host OS at runtime from the initial_cwd
format and centralizes all platform-aware logic.
Also fix scan_host_folder on the server side: canonicalize
plugin_host_folder so the starts_with security check works on Windows,
where canonicalize() adds the \?\ prefix.
* Add virtual root view for drive and WSL navigation in strider
On Windows, navigating up from a drive root (e.g. C:\) now shows a
"Computer" view listing all available drives and WSL distributions.
Drives are enumerated via GetLogicalDriveStringsW and WSL distros
via `wsl -l -q` (since read_dir on \wsl.localhost fails with OS
error 64/67). Drive letters appear before WSL entries, which are
displayed as "Ubuntu-24.04 (WSL)" etc. On non-Windows platforms,
behavior is unchanged.
* Rename ListHostEntries to ListWindowsVolumes and gate behind FullHdAccess
The old name was misleading — on Unix it just returned `/`, which isn't
"listing host entries." Rename to ListWindowsVolumes to make the
Windows-specific intent explicit, gate behind FullHdAccess permission,
and replace the Unix implementation with a log::error since the command
is not meaningful on non-Windows platforms.
* Replace direct array indexing with .get() in strider platform detection
Use safe accessors and matches! macro instead of direct byte indexing
for bounds-checked access patterns.
---------
Co-authored-by: divens <divens.dev@gmail.com>
Diffstat (limited to 'default-plugins/strider/src/shared.rs')
| -rw-r--r-- | default-plugins/strider/src/shared.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/default-plugins/strider/src/shared.rs b/default-plugins/strider/src/shared.rs index 19728034..a8539e86 100644 --- a/default-plugins/strider/src/shared.rs +++ b/default-plugins/strider/src/shared.rs @@ -1,3 +1,4 @@ +use crate::platform::Platform; use std::path::PathBuf; use unicode_width::UnicodeWidthStr; use zellij_tile::prelude::*; @@ -78,14 +79,28 @@ pub fn render_search_term(search_term: &str) { println!("") } +pub fn render_virtual_root_header(_cols: usize) { + let prompt = "PATH: "; + let title = "Computer"; + let prompt_len = prompt.width(); + let path_end = prompt_len + title.width(); + let text = Text::new(format!("{}{}", prompt, title)) + .color_range(2, 0..prompt_len) + .color_range(0, prompt_len..path_end); + print_text(text); + println!(); + println!(); +} + pub fn render_current_path( full_path: &PathBuf, path_is_dir: bool, handling_filepick: bool, max_cols: usize, + platform: Platform, ) { let prompt = "PATH: "; - let current_path = full_path.display().to_string(); + let current_path = Platform::to_host_display(full_path, platform); let prompt_len = prompt.width(); let current_path_len = current_path.width(); @@ -117,6 +132,7 @@ pub fn render_current_path( truncate_path( full_path.clone(), current_path_len.saturating_sub(max_path_len), + platform, ) }; let current_path_len = current_path.width(); @@ -131,7 +147,8 @@ pub fn render_current_path( println!(); } -fn truncate_path(path: PathBuf, mut char_count_to_remove: usize) -> String { +fn truncate_path(path: PathBuf, mut char_count_to_remove: usize, platform: Platform) -> String { + let sep = platform.separator(); let mut truncated = String::new(); let component_count = path.iter().count(); for (i, component) in path.iter().enumerate() { @@ -139,13 +156,13 @@ fn truncate_path(path: PathBuf, mut char_count_to_remove: usize) -> String { if char_count_to_remove > 0 { truncated.push(component_str.remove(0)); if i != 0 && i + 1 != component_count { - truncated.push('/'); + truncated.push(sep); } char_count_to_remove = char_count_to_remove.saturating_sub(component_str.width() + 1); } else { truncated.push_str(&component_str); if i != 0 && i + 1 != component_count { - truncated.push('/'); + truncated.push(sep); } } } |
