summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-03-16 10:52:03 +0100
committerAram Drevekenin <aram@poor.dev>2024-03-16 10:52:03 +0100
commite9528fb0e7215796b30dec9b24df7d0fc5fbcb74 (patch)
treebf8675d57499b6278e8c89b84c8141969cc2ce3f
parent08748218f14998b891cd766627785f2b68e7bd37 (diff)
style(fmt): rustfmtsession-manager-cwd
-rw-r--r--default-plugins/session-manager/src/main.rs14
-rw-r--r--default-plugins/session-manager/src/ui/components.rs72
-rw-r--r--default-plugins/strider/src/file_list_view.rs47
-rw-r--r--default-plugins/strider/src/main.rs36
-rw-r--r--default-plugins/strider/src/search_view.rs37
-rw-r--r--default-plugins/strider/src/shared.rs38
-rw-r--r--default-plugins/strider/src/state.rs61
-rw-r--r--zellij-client/src/os_input_output.rs10
-rw-r--r--zellij-server/src/plugins/mod.rs2
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs4
-rw-r--r--zellij-server/src/plugins/watch_filesystem.rs30
-rw-r--r--zellij-server/src/plugins/zellij_exports.rs59
-rw-r--r--zellij-tile/src/shim.rs3
-rw-r--r--zellij-utils/src/data.rs6
-rw-r--r--zellij-utils/src/errors.rs2
-rw-r--r--zellij-utils/src/input/actions.rs8
-rw-r--r--zellij-utils/src/plugin_api/event.rs72
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs4
18 files changed, 329 insertions, 176 deletions
diff --git a/default-plugins/session-manager/src/main.rs b/default-plugins/session-manager/src/main.rs
index 5e4ab5e19..7015144fd 100644
--- a/default-plugins/session-manager/src/main.rs
+++ b/default-plugins/session-manager/src/main.rs
@@ -2,9 +2,9 @@ mod new_session_info;
mod resurrectable_sessions;
mod session_list;
mod ui;
-use zellij_tile::prelude::*;
-use uuid::Uuid;
use std::collections::BTreeMap;
+use uuid::Uuid;
+use zellij_tile::prelude::*;
use new_session_info::NewSessionInfo;
use ui::{
@@ -79,10 +79,10 @@ impl ZellijPlugin for State {
},
None => {
eprintln!("request id not found");
- }
+ },
}
},
- _ => {}
+ _ => {},
}
true
} else {
@@ -225,8 +225,10 @@ impl State {
MessageToPlugin::new("filepicker")
.with_plugin_url("filepicker")
.with_plugin_config(config)
- .new_plugin_instance_should_have_pane_title("Select folder for the new session...")
- .with_args(args)
+ .new_plugin_instance_should_have_pane_title(
+ "Select folder for the new session...",
+ )
+ .with_args(args),
);
should_render = true;
} else if let Key::Ctrl('c') = key {
diff --git a/default-plugins/session-manager/src/ui/components.rs b/default-plugins/session-manager/src/ui/components.rs
index c2177ca7a..d44fddf44 100644
--- a/default-plugins/session-manager/src/ui/components.rs
+++ b/default-plugins/session-manager/src/ui/components.rs
@@ -1,7 +1,7 @@
+use std::path::PathBuf;
use unicode_width::UnicodeWidthChar;
use unicode_width::UnicodeWidthStr;
use zellij_tile::prelude::*;
-use std::path::PathBuf;
use crate::ui::{PaneUiInfo, SessionUiInfo, TabUiInfo};
use crate::{ActiveScreen, NewSessionInfo};
@@ -550,7 +550,13 @@ pub fn render_screen_toggle(active_screen: ActiveScreen, x: usize, y: usize, max
print_ribbon_with_coordinates(exited_sessions_text, third_ribbon_x, y, None, None);
}
-fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: Colors, x: usize, y: usize, max_cols: usize) {
+fn render_new_session_folder_prompt(
+ new_session_info: &NewSessionInfo,
+ colors: Colors,
+ x: usize,
+ y: usize,
+ max_cols: usize,
+) {
match new_session_info.new_session_folder.as_ref() {
Some(new_session_folder) => {
let folder_prompt = "New session folder:";
@@ -563,7 +569,15 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
let reset_folder_shortcut_text = "<Ctrl c>";
let reset_folder_shortcut = colors.magenta(reset_folder_shortcut_text);
let to_reset = "to reset";
- if max_cols >= folder_prompt.width() + new_session_folder.width() + change_folder_shortcut_text.width() + to_change.width() + reset_folder_shortcut_text.width() + to_reset.width() + 8 {
+ if max_cols
+ >= folder_prompt.width()
+ + new_session_folder.width()
+ + change_folder_shortcut_text.width()
+ + to_change.width()
+ + reset_folder_shortcut_text.width()
+ + to_reset.width()
+ + 8
+ {
print!(
"\u{1b}[m{}{} {} ({} {}, {} {})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -574,7 +588,15 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
reset_folder_shortcut,
to_reset,
);
- } else if max_cols >= short_folder_prompt.width() + new_session_folder.width() + change_folder_shortcut_text.width() + to_change.width() + reset_folder_shortcut_text.width() + to_reset.width() + 8 {
+ } else if max_cols
+ >= short_folder_prompt.width()
+ + new_session_folder.width()
+ + change_folder_shortcut_text.width()
+ + to_change.width()
+ + reset_folder_shortcut_text.width()
+ + to_reset.width()
+ + 8
+ {
print!(
"\u{1b}[m{}{} {} ({} {}, {} {})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -585,7 +607,13 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
reset_folder_shortcut,
to_reset,
);
- } else if max_cols >= short_folder_prompt.width() + new_session_folder.width() + change_folder_shortcut_text.width() + reset_folder_shortcut_text.width() + 5 {
+ } else if max_cols
+ >= short_folder_prompt.width()
+ + new_session_folder.width()
+ + change_folder_shortcut_text.width()
+ + reset_folder_shortcut_text.width()
+ + 5
+ {
print!(
"\u{1b}[m{}{} {} ({}/{})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -595,9 +623,15 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
reset_folder_shortcut,
);
} else {
- let total_len = short_folder_prompt.width() + change_folder_shortcut_text.width() + reset_folder_shortcut_text.width() + 5;
+ let total_len = short_folder_prompt.width()
+ + change_folder_shortcut_text.width()
+ + reset_folder_shortcut_text.width()
+ + 5;
let max_path_len = max_cols.saturating_sub(total_len);
- let truncated_path = truncate_path(new_session_path, new_session_folder.width().saturating_sub(max_path_len));
+ let truncated_path = truncate_path(
+ new_session_path,
+ new_session_folder.width().saturating_sub(max_path_len),
+ );
print!(
"\u{1b}[m{}{} {} ({}/{})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -615,7 +649,9 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
let change_folder_shortcut = colors.magenta(change_folder_shortcut_text);
let to_set = "to set";
- if max_cols >= folder_prompt.width() + change_folder_shortcut_text.width() + to_set.width() + 4 {
+ if max_cols
+ >= folder_prompt.width() + change_folder_shortcut_text.width() + to_set.width() + 4
+ {
print!(
"\u{1b}[m{}{} ({} {})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -623,7 +659,12 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
change_folder_shortcut,
to_set,
);
- } else if max_cols >= short_folder_prompt.width() + change_folder_shortcut_text.width() + to_set.width() + 4 {
+ } else if max_cols
+ >= short_folder_prompt.width()
+ + change_folder_shortcut_text.width()
+ + to_set.width()
+ + 4
+ {
print!(
"\u{1b}[m{}{} ({} {})",
format!("\u{1b}[{};{}H", y + 1, x + 1),
@@ -639,7 +680,7 @@ fn render_new_session_folder_prompt(new_session_info: &NewSessionInfo, colors: C
change_folder_shortcut,
);
}
- }
+ },
}
}
@@ -777,7 +818,13 @@ pub fn render_layout_selection_list(
}
let table_y = y + 3;
print_table_with_coordinates(table, x, table_y, None, None);
- render_new_session_folder_prompt(new_session_info, colors, x, (y + max_rows_of_new_session_block).saturating_sub(3), max_cols_of_new_session_block);
+ render_new_session_folder_prompt(
+ new_session_info,
+ colors,
+ x,
+ (y + max_rows_of_new_session_block).saturating_sub(3),
+ max_cols_of_new_session_block,
+ );
}
pub fn render_error(error_text: &str, rows: usize, columns: usize, x: usize, y: usize) {
@@ -919,7 +966,8 @@ fn truncate_path(path: PathBuf, mut char_count_to_remove: usize) -> String {
if i != 0 && i + 1 != component_count {
truncated.push('/');
}
- char_count_to_remove = char_count_to_remove.saturating_sub(component_str.width().saturating_sub(1));
+ char_count_to_remove =
+ char_count_to_remove.saturating_sub(component_str.width().saturating_sub(1));
} else {
truncated.push_str(&component_str);
if i != 0 && i + 1 != component_count {
diff --git a/default-plugins/strider/src/file_list_view.rs b/default-plugins/strider/src/file_list_view.rs
index 9b497a1fd..e16c66b3f 100644
--- a/default-plugins/strider/src/file_list_view.rs
+++ b/default-plugins/strider/src/file_list_view.rs
@@ -1,10 +1,10 @@
use crate::shared::{calculate_list_bounds, render_list_tip};
use crate::state::{refresh_directory, ROOT};
-use std::collections::{HashMap};
+use pretty_bytes::converter::convert as pretty_bytes;
+use std::collections::HashMap;
use std::path::PathBuf;
-use zellij_tile::prelude::*;
use unicode_width::UnicodeWidthStr;
-use pretty_bytes::converter::convert as pretty_bytes;
+use zellij_tile::prelude::*;
#[derive(Debug, Clone)]
pub struct FileListView {
@@ -12,7 +12,6 @@ pub struct FileListView {
pub path_is_dir: bool,
pub files: Vec<FsEntry>,
pub cursor_hist: HashMap<PathBuf, usize>,
-
}
impl Default for FileListView {
@@ -52,7 +51,11 @@ impl FileListView {
pub fn reset_selected(&mut self) {
*self.selected_mut() = self.selected().unwrap_or(0);
}
- pub fn update_files(&mut self, paths: Vec<(PathBuf, Option<FileMetadata>)>, hide_hidden_files: bool) {
+ pub fn update_files(
+ &mut self,
+ paths: Vec<(PathBuf, Option<FileMetadata>)>,
+ hide_hidden_files: bool,
+ ) {
let mut files = vec![];
for (entry, entry_metadata) in paths {
if entry_metadata.map(|e| e.is_symlink).unwrap_or(false) {
@@ -94,21 +97,28 @@ impl FileListView {
}
}
pub fn render(&mut self, rows: usize, cols: usize) {
- let (start_index, selected_index_in_range, end_index) = calculate_list_bounds(self.files.len(), rows.saturating_sub(1), self.selected());
+ let (start_index, selected_index_in_range, end_index) =
+ calculate_list_bounds(self.files.len(), rows.saturating_sub(1), self.selected());
render_list_tip(3, cols);
for i in start_index..end_index {
if let Some(entry) = self.files.get(i) {
let is_selected = Some(i) == selected_index_in_range;
let mut file_or_folder_name = entry.name();
- let size = entry.size().map(|s| pretty_bytes(s as f64)).unwrap_or("".to_owned());
+ let size = entry
+ .size()
+ .map(|s| pretty_bytes(s as f64))
+ .unwrap_or("".to_owned());
if entry.is_folder() {
file_or_folder_name.push('/');
}
let file_or_folder_name_width = file_or_folder_name.width();
let size_width = size.width();
let text = if file_or_folder_name_width + size_width < cols {
- let padding = " ".repeat(cols.saturating_sub(file_or_folder_name_width).saturating_sub(size_width));
+ let padding = " ".repeat(
+ cols.saturating_sub(file_or_folder_name_width)
+ .saturating_sub(size_width),
+ );
format!("{}{}{}", file_or_folder_name, padding, size)
} else {
// drop the size, no room for it
@@ -123,7 +133,13 @@ impl FileListView {
if entry.is_folder() {
text_element = text_element.color_range(0, ..);
}
- print_text_with_coordinates(text_element, 0, 4 + i.saturating_sub(start_index), Some(cols), None);
+ print_text_with_coordinates(
+ text_element,
+ 0,
+ 4 + i.saturating_sub(start_index),
+ Some(cols),
+ None,
+ );
}
}
}
@@ -151,8 +167,14 @@ impl FsEntry {
}
pub fn get_pathbuf_without_root_prefix(&self) -> PathBuf {
match self {
- FsEntry::Dir(p) => p.strip_prefix(ROOT).map(|p| p.to_path_buf()).unwrap_or_else(|_| p.clone()),
- FsEntry::File(p, _) => p.strip_prefix(ROOT).map(|p| p.to_path_buf()).unwrap_or_else(|_| p.clone()),
+ FsEntry::Dir(p) => p
+ .strip_prefix(ROOT)
+ .map(|p| p.to_path_buf())
+ .unwrap_or_else(|_| p.clone()),
+ FsEntry::File(p, _) => p
+ .strip_prefix(ROOT)
+ .map(|p| p.to_path_buf())
+ .unwrap_or_else(|_| p.clone()),
}
}
@@ -163,8 +185,7 @@ impl FsEntry {
pub fn is_folder(&self) -> bool {
match self {
FsEntry::Dir(_) => true,
- _ => false
+ _ => false,
}
}
}
-
diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs
index 9a843cc65..ce9a5273a 100644
--- a/default-plugins/strider/src/main.rs
+++ b/default-plugins/strider/src/main.rs
@@ -1,11 +1,11 @@
-mod state;
-mod search_view;
mod file_list_view;
+mod search_view;
mod shared;
+mod state;
-use shared::{render_instruction_line, render_current_path, render_search_term};
-use state::{refresh_directory, State};
use crate::file_list_view::FsEntry;
+use shared::{render_current_path, render_instruction_line, render_search_term};
+use state::{refresh_directory, State};
use std::collections::BTreeMap;
use std::path::PathBuf;
use zellij_tile::prelude::*;
@@ -38,9 +38,13 @@ impl ZellijPlugin for State {
// from an individual pane somewhere inside this broad scope - in this case, we want to
// start in the same cwd as the caller, giving them the full access we were granted
match configuration
- .get("caller_cwd")
- .map(|c| PathBuf::from(c))
- .and_then(|c| c.strip_prefix(&self.initial_cwd).ok().map(|c| PathBuf::from(c))) {
+ .get("caller_cwd")
+ .map(|c| PathBuf::from(c))
+ .and_then(|c| {
+ c.strip_prefix(&self.initial_cwd)
+ .ok()
+ .map(|c| PathBuf::from(c))
+ }) {
Some(relative_caller_path) => {
let relative_caller_path = FsEntry::Dir(relative_caller_path.to_path_buf());
self.file_list_view.enter_dir(&relative_caller_path);
@@ -48,7 +52,7 @@ impl ZellijPlugin for State {
},
None => {
refresh_directory(&std::path::Path::new("/"));
- }
+ },
}
}
@@ -58,20 +62,20 @@ impl ZellijPlugin for State {
Event::FileSystemUpdate(paths) => {
self.update_files(paths);
should_render = true;
- }
+ },
Event::Key(key) => match key {
Key::Char(character) if character != '\n' => {
self.update_search_term(character);
should_render = true;
- }
+ },
Key::Backspace => {
self.handle_backspace();
should_render = true;
- }
+ },
Key::Esc | Key::Ctrl('c') => {
self.clear_search_term_or_descend();
should_render = true;
- }
+ },
Key::Up => {
self.move_selection_up();
should_render = true;
@@ -82,10 +86,10 @@ impl ZellijPlugin for State {
},
Key::Char('\n') if self.handling_filepick_request_from.is_some() => {
self.send_filepick_response();
- }
+ },
Key::Char('\n') => {
self.open_selected_path();
- }
+ },
Key::Right | Key::BackTab => {
self.traverse_dir();
should_render = true;
@@ -113,7 +117,7 @@ impl ZellijPlugin for State {
Mouse::LeftClick(line, _) => {
self.handle_left_click(line);
should_render = true;
- }
+ },
_ => {},
},
_ => {
@@ -146,7 +150,7 @@ impl ZellijPlugin for State {
&self.file_list_view.path,
self.file_list_view.path_is_dir,
self.handling_filepick_request_from.is_some(),
- cols
+ cols,
);
if self.is_searching {
self.search_view.render(rows_for_list, cols);
diff --git a/default-plugins/strider/src/search_view.rs b/default-plugins/strider/src/search_view.rs
index 0170ed919..bcc38bc82 100644
--- a/default-plugins/strider/src/search_view.rs
+++ b/default-plugins/strider/src/search_view.rs
@@ -1,10 +1,9 @@
-
use crate::shared::{calculate_list_bounds, render_list_tip};
-use zellij_tile::prelude::*;
-use unicode_width::UnicodeWidthStr;
use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
use pretty_bytes::converter::convert as pretty_bytes;
+use unicode_width::UnicodeWidthStr;
+use zellij_tile::prelude::*;
use crate::file_list_view::FsEntry;
@@ -48,16 +47,25 @@ impl SearchView {
}
}
pub fn get_selected_entry(&self) -> Option<FsEntry> {
- self.search_results.get(self.selected_search_result).map(|s| s.entry.clone())
+ self.search_results
+ .get(self.selected_search_result)
+ .map(|s| s.entry.clone())
}
pub fn render(&mut self, rows: usize, cols: usize) {
- let (start_index, selected_index_in_range, end_index) = calculate_list_bounds(self.search_results.len(), rows.saturating_sub(1), Some(self.selected_search_result));
+ let (start_index, selected_index_in_range, end_index) = calculate_list_bounds(
+ self.search_results.len(),
+ rows.saturating_sub(1),
+ Some(self.selected_search_result),
+ );
render_list_tip(3, cols);
for i in start_index..end_index {
if let Some(search_result) = self.search_results.get(i) {
let is_selected = Some(i) == selected_index_in_range;
let mut search_result_text = search_result.name();
- let size = search_result.size().map(|s| pretty_bytes(s as f64)).unwrap_or("".to_owned());
+ let size = search_result
+ .size()
+ .map(|s| pretty_bytes(s as f64))
+ .unwrap_or("".to_owned());
if search_result.is_folder() {
search_result_text.push('/');
}
@@ -65,7 +73,10 @@ impl SearchView {
let search_result_text_width = search_result_text.width();
let size_width = size.width();
let text = if search_result_text_width + size_width < cols {
- let padding = " ".repeat(cols.saturating_sub(search_result_text_width).saturating_sub(size_width));
+ let padding = " ".repeat(
+ cols.saturating_sub(search_result_text_width)
+ .saturating_sub(size_width),
+ );
format!("{}{}{}", search_result_text, padding, size)
} else {
// drop the size, no room for it
@@ -81,7 +92,13 @@ impl SearchView {
text_element = text_element.color_range(0, ..);
}
text_element = text_element.color_indices(3, search_result.indices());
- print_text_with_coordinates(text_element, 0, i.saturating_sub(start_index) + 4, Some(cols), None);
+ print_text_with_coordinates(
+ text_element,
+ 0,
+ i.saturating_sub(start_index) + 4,
+ Some(cols),
+ None,
+ );
}
}
}
@@ -91,7 +108,7 @@ impl SearchView {
pub struct SearchResult {
pub entry: FsEntry,
pub score: i64,
- pub indices: Vec<usize>
+ pub indices: Vec<usize>,
}
impl SearchResult {
@@ -99,7 +116,7 @@ impl SearchResult {
SearchResult {
entry,
score,
- indices
+ indices,
}
}
pub fn name(&self) -> String {
diff --git a/default-plugins/strider/src/shared.rs b/default-plugins/strider/src/shared.rs
index 6407d0fc3..c51cb3123 100644
--- a/default-plugins/strider/src/shared.rs
+++ b/default-plugins/strider/src/shared.rs
@@ -1,6 +1,6 @@
-use zellij_tile::prelude::*;
use std::path::PathBuf;
use unicode_width::UnicodeWidthStr;
+use zellij_tile::prelude::*;
pub fn render_instruction_line(y: usize, max_cols: usize) {
if max_cols > 78 {
@@ -10,7 +10,6 @@ pub fn render_instruction_line(y: usize, max_cols: usize) {
.color_range(3, 45..46)
.color_range(3, 48..56);
print_text_with_coordinates(text, 0, y, Some(max_cols), None);
-
} else if max_cols > 56 {
let text = "Help: <Ctrl c> - back, / - root, <Ctrl e> - hidden files";
let text = Text::new(text)
@@ -20,9 +19,7 @@ pub fn render_instruction_line(y: usize, max_cols: usize) {
print_text_with_coordinates(text, 0, y, Some(max_cols), None);
} else if max_cols > 25 {
let text = "<Ctrl c> - back, / - root";
- let text = Text::new(text)
- .color_range(3, ..8)
- .color_range(3, 17..18);
+ let text = Text::new(text).color_range(3, ..8).color_range(3, 17..18);
print_text_with_coordinates(text, 0, y, Some(max_cols), None);
}
}
@@ -35,7 +32,11 @@ pub fn render_list_tip(y: usize, max_cols: usize) {
}
// returns the list (start_index, selected_index_in_range, end_index)
-pub fn calculate_list_bounds(result_count: usize, max_result_count: usize, selected_index_in_all_results: Option<usize>) -> (usize, Option<usize>, usize) {
+pub fn calculate_list_bounds(
+ result_count: usize,
+ max_result_count: usize,
+ selected_index_in_all_results: Option<usize>,
+) -> (usize, Option<usize>, usize) {
match selected_index_in_all_results {
Some(selected_index_in_all_results) => {
let mut room_in_list = max_result_count;
@@ -65,7 +66,7 @@ pub fn calculate_list_bounds(result_count: usize, max_result_count: usize, selec
}
(start_index, Some(selected_index_in_all_results), end_index)
},
- None => (0, None, max_result_count + 1)
+ None => (0, None, max_result_count + 1),
}
}
@@ -83,7 +