Use 89 chars line length

pull/486/head
Arijit Basu 2 years ago committed by Arijit Basu
parent 21b8c3e807
commit e04b0964ae

@ -14,8 +14,7 @@ const PWD: &str = "/tmp/xplr_bench";
fn navigation_benchmark(c: &mut Criterion) { fn navigation_benchmark(c: &mut Criterion) {
fs::create_dir_all(PWD).unwrap(); fs::create_dir_all(PWD).unwrap();
(1..10000).for_each(|i| { (1..10000).for_each(|i| {
fs::File::create(std::path::Path::new(PWD).join(i.to_string())) fs::File::create(std::path::Path::new(PWD).join(i.to_string())).unwrap();
.unwrap();
}); });
let lua = mlua::Lua::new(); let lua = mlua::Lua::new();
@ -94,8 +93,7 @@ fn navigation_benchmark(c: &mut Criterion) {
fn draw_benchmark(c: &mut Criterion) { fn draw_benchmark(c: &mut Criterion) {
fs::create_dir_all(PWD).unwrap(); fs::create_dir_all(PWD).unwrap();
(1..10000).for_each(|i| { (1..10000).for_each(|i| {
fs::File::create(std::path::Path::new(PWD).join(i.to_string())) fs::File::create(std::path::Path::new(PWD).join(i.to_string())).unwrap();
.unwrap();
}); });
let lua = mlua::Lua::new(); let lua = mlua::Lua::new();

@ -1,4 +1,4 @@
edition = "2021" edition = "2021"
max_width = 80 max_width = 89
tab_spaces = 4 tab_spaces = 4
use_field_init_shorthand = true use_field_init_shorthand = true

@ -200,8 +200,7 @@ impl App {
None None
} }
} else { } else {
let path = let path = PathBuf::from("/").join("etc").join("xplr").join("init.lua");
PathBuf::from("/").join("etc").join("xplr").join("init.lua");
if path.exists() { if path.exists() {
Some(path) Some(path)
} else { } else {
@ -342,10 +341,7 @@ impl App {
self self
} }
pub fn handle_batch_external_msgs( pub fn handle_batch_external_msgs(mut self, msgs: Vec<ExternalMsg>) -> Result<Self> {
mut self,
msgs: Vec<ExternalMsg>,
) -> Result<Self> {
for task in msgs for task in msgs
.into_iter() .into_iter()
.map(|msg| Task::new(MsgIn::External(msg), None)) .map(|msg| Task::new(MsgIn::External(msg), None))
@ -376,11 +372,7 @@ impl App {
} }
} }
fn handle_external( fn handle_external(self, msg: ExternalMsg, key: Option<Key>) -> Result<Self> {
self,
msg: ExternalMsg,
key: Option<Key>,
) -> Result<Self> {
if self.config.general.read_only && !msg.is_read_only() { if self.config.general.read_only && !msg.is_read_only() {
self.log_error("Cannot execute code in read-only mode.".into()) self.log_error("Cannot execute code in read-only mode.".into())
} else { } else {
@ -402,9 +394,7 @@ impl App {
self.focus_previous_by_relative_index_from_input() self.focus_previous_by_relative_index_from_input()
} }
FocusNext => self.focus_next(), FocusNext => self.focus_next(),
FocusNextByRelativeIndex(i) => { FocusNextByRelativeIndex(i) => self.focus_next_by_relative_index(i),
self.focus_next_by_relative_index(i)
}
FocusNextByRelativeIndexFromInput => { FocusNextByRelativeIndexFromInput => {
self.focus_next_by_relative_index_from_input() self.focus_next_by_relative_index_from_input()
} }
@ -421,18 +411,14 @@ impl App {
FollowSymlink => self.follow_symlink(), FollowSymlink => self.follow_symlink(),
SetInputPrompt(p) => self.set_input_prompt(p), SetInputPrompt(p) => self.set_input_prompt(p),
UpdateInputBuffer(op) => self.update_input_buffer(op), UpdateInputBuffer(op) => self.update_input_buffer(op),
UpdateInputBufferFromKey => { UpdateInputBufferFromKey => self.update_input_buffer_from_key(key),
self.update_input_buffer_from_key(key)
}
BufferInput(input) => self.buffer_input(&input), BufferInput(input) => self.buffer_input(&input),
BufferInputFromKey => self.buffer_input_from_key(key), BufferInputFromKey => self.buffer_input_from_key(key),
SetInputBuffer(input) => self.set_input_buffer(input), SetInputBuffer(input) => self.set_input_buffer(input),
RemoveInputBufferLastCharacter => { RemoveInputBufferLastCharacter => {
self.remove_input_buffer_last_character() self.remove_input_buffer_last_character()
} }
RemoveInputBufferLastWord => { RemoveInputBufferLastWord => self.remove_input_buffer_last_word(),
self.remove_input_buffer_last_word()
}
ResetInputBuffer => self.reset_input_buffer(), ResetInputBuffer => self.reset_input_buffer(),
SwitchMode(mode) => self.switch_mode(&mode), SwitchMode(mode) => self.switch_mode(&mode),
SwitchModeKeepingInputBuffer(mode) => { SwitchModeKeepingInputBuffer(mode) => {
@ -447,9 +433,7 @@ impl App {
self.switch_mode_custom_keeping_input_buffer(&mode) self.switch_mode_custom_keeping_input_buffer(&mode)
} }
PopMode => self.pop_mode(), PopMode => self.pop_mode(),
PopModeKeepingInputBuffer => { PopModeKeepingInputBuffer => self.pop_mode_keeping_input_buffer(),
self.pop_mode_keeping_input_buffer()
}
SwitchLayout(mode) => self.switch_layout(&mode), SwitchLayout(mode) => self.switch_layout(&mode),
SwitchLayoutBuiltin(mode) => self.switch_layout_builtin(&mode), SwitchLayoutBuiltin(mode) => self.switch_layout_builtin(&mode),
SwitchLayoutCustom(mode) => self.switch_layout_custom(&mode), SwitchLayoutCustom(mode) => self.switch_layout_custom(&mode),
@ -474,9 +458,7 @@ impl App {
AddNodeFilter(f) => self.add_node_filter(f), AddNodeFilter(f) => self.add_node_filter(f),
AddNodeFilterFromInput(f) => self.add_node_filter_from_input(f), AddNodeFilterFromInput(f) => self.add_node_filter_from_input(f),
RemoveNodeFilter(f) => self.remove_node_filter(f), RemoveNodeFilter(f) => self.remove_node_filter(f),
RemoveNodeFilterFromInput(f) => { RemoveNodeFilterFromInput(f) => self.remove_node_filter_from_input(f),
self.remove_node_filter_from_input(f)
}
ToggleNodeFilter(f) => self.toggle_node_filter(f), ToggleNodeFilter(f) => self.toggle_node_filter(f),
RemoveLastNodeFilter => self.remove_last_node_filter(), RemoveLastNodeFilter => self.remove_last_node_filter(),
ResetNodeFilters => self.reset_node_filters(), ResetNodeFilters => self.reset_node_filters(),
@ -650,10 +632,7 @@ impl App {
Ok(self) Ok(self)
} }
fn focus_previous_by_relative_index( fn focus_previous_by_relative_index(mut self, index: usize) -> Result<Self> {
mut self,
index: usize,
) -> Result<Self> {
let mut history = self.history.clone(); let mut history = self.history.clone();
if let Some(dir) = self.directory_buffer_mut() { if let Some(dir) = self.directory_buffer_mut() {
if let Some(n) = dir.focused_node() { if let Some(n) = dir.focused_node() {
@ -737,11 +716,7 @@ impl App {
} }
} }
fn change_directory( fn change_directory(mut self, dir: &str, save_history: bool) -> Result<Self> {
mut self,
dir: &str,
save_history: bool,
) -> Result<Self> {
let mut dir = PathBuf::from(dir); let mut dir = PathBuf::from(dir);
if dir.is_relative() { if dir.is_relative() {
dir = PathBuf::from(self.pwd.clone()).join(dir); dir = PathBuf::from(self.pwd.clone()).join(dir);
@ -750,8 +725,7 @@ impl App {
match env::set_current_dir(&dir) { match env::set_current_dir(&dir) {
Ok(()) => { Ok(()) => {
let pwd = self.pwd.clone(); let pwd = self.pwd.clone();
let focus = let focus = self.focused_node().map(|n| n.relative_path.clone());
self.focused_node().map(|n| n.relative_path.clone());
self = self.add_last_focus(pwd, focus)?; self = self.add_last_focus(pwd, focus)?;
self.pwd = dir.to_string_lossy().to_string(); self.pwd = dir.to_string_lossy().to_string();
if save_history { if save_history {
@ -922,11 +896,7 @@ impl App {
} }
} }
pub fn focus_by_file_name( pub fn focus_by_file_name(mut self, name: &str, save_history: bool) -> Result<Self> {
mut self,
name: &str,
save_history: bool,
) -> Result<Self> {
let mut history = self.history.clone(); let mut history = self.history.clone();
if let Some(dir_buf) = self.directory_buffer_mut() { if let Some(dir_buf) = self.directory_buffer_mut() {
if let Some(focus) = dir_buf if let Some(focus) = dir_buf
@ -964,14 +934,11 @@ impl App {
} }
if let Some(parent) = pathbuf.parent() { if let Some(parent) = pathbuf.parent() {
if let Some(filename) = pathbuf.file_name() { if let Some(filename) = pathbuf.file_name() {
self.change_directory( self.change_directory(&parent.to_string_lossy().to_string(), false)?
&parent.to_string_lossy().to_string(), .focus_by_file_name(
false, &filename.to_string_lossy().to_string(),
)? save_history,
.focus_by_file_name( )
&filename.to_string_lossy().to_string(),
save_history,
)
} else { } else {
self.log_error(format!("{} not found", path)) self.log_error(format!("{} not found", path))
} }
@ -1033,10 +1000,7 @@ impl App {
.and_then(App::reset_input_buffer) .and_then(App::reset_input_buffer)
} }
fn switch_mode_builtin_keeping_input_buffer( fn switch_mode_builtin_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
mut self,
mode: &str,
) -> Result<Self> {
if let Some(mode) = self.config.modes.builtin.get(mode).cloned() { if let Some(mode) = self.config.modes.builtin.get(mode).cloned() {
self = self.push_mode(); self = self.push_mode();
self.mode = mode.sanitized(self.config.general.read_only); self.mode = mode.sanitized(self.config.general.read_only);
@ -1051,10 +1015,7 @@ impl App {
.and_then(App::reset_input_buffer) .and_then(App::reset_input_buffer)
} }
fn switch_mode_custom_keeping_input_buffer( fn switch_mode_custom_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
mut self,
mode: &str,
) -> Result<Self> {
if let Some(mode) = self.config.modes.custom.get(mode).cloned() { if let Some(mode) = self.config.modes.custom.get(mode).cloned() {
self = self.push_mode(); self = self.push_mode();
self.mode = mode.sanitized(self.config.general.read_only); self.mode = mode.sanitized(self.config.general.read_only);
@ -1174,8 +1135,7 @@ impl App {
path = PathBuf::from(self.pwd.clone()).join(path); path = PathBuf::from(self.pwd.clone()).join(path);
} }
let parent = path.parent().map(|p| p.to_string_lossy().to_string()); let parent = path.parent().map(|p| p.to_string_lossy().to_string());
let filename = let filename = path.file_name().map(|p| p.to_string_lossy().to_string());
path.file_name().map(|p| p.to_string_lossy().to_string());
if let (Some(p), Some(n)) = (parent, filename) { if let (Some(p), Some(n)) = (parent, filename) {
self.selection.insert(Node::new(p, n)); self.selection.insert(Node::new(p, n));
} }
@ -1265,33 +1225,21 @@ impl App {
Ok(self) Ok(self)
} }
fn add_node_filter_from_input( fn add_node_filter_from_input(mut self, filter: NodeFilter) -> Result<Self> {
mut self,
filter: NodeFilter,
) -> Result<Self> {
if let Some(input) = self.input.buffer.as_ref() { if let Some(input) = self.input.buffer.as_ref() {
self.explorer_config self.explorer_config
.filters .filters
.insert(NodeFilterApplicable::new( .insert(NodeFilterApplicable::new(filter, input.value().into()));
filter,
input.value().into(),
));
}; };
Ok(self) Ok(self)
} }
fn remove_node_filter( fn remove_node_filter(mut self, filter: NodeFilterApplicable) -> Result<Self> {
mut self,
filter: NodeFilterApplicable,
) -> Result<Self> {
self.explorer_config.filters.retain(|f| f != &filter); self.explorer_config.filters.retain(|f| f != &filter);
Ok(self) Ok(self)
} }
fn remove_node_filter_from_input( fn remove_node_filter_from_input(mut self, filter: NodeFilter) -> Result<Self> {
mut self,
filter: NodeFilter,
) -> Result<Self> {
if let Some(input) = self.input.buffer.as_ref() { if let Some(input) = self.input.buffer.as_ref() {
let nfa = NodeFilterApplicable::new(filter, input.value().into()); let nfa = NodeFilterApplicable::new(filter, input.value().into());
self.explorer_config.filters.retain(|f| f != &nfa); self.explorer_config.filters.retain(|f| f != &nfa);
@ -1486,9 +1434,8 @@ impl App {
fn refresh_selection(mut self) -> Result<Self> { fn refresh_selection(mut self) -> Result<Self> {
// Should be able to select broken symlink // Should be able to select broken symlink
self.selection.retain(|n| { self.selection
PathBuf::from(&n.absolute_path).symlink_metadata().is_ok() .retain(|n| PathBuf::from(&n.absolute_path).symlink_metadata().is_ok());
});
Ok(self) Ok(self)
} }

@ -323,21 +323,16 @@ impl KeyBindings {
.filter_map(|(k, a)| a.sanitized(read_only).map(|a| (k, a))) .filter_map(|(k, a)| a.sanitized(read_only).map(|a| (k, a)))
.collect(); .collect();
self.on_alphabet = self.on_alphabet = self.on_alphabet.and_then(|a| a.sanitized(read_only));
self.on_alphabet.and_then(|a| a.sanitized(read_only)); self.on_number = self.on_number.and_then(|a| a.sanitized(read_only));
self.on_number =
self.on_number.and_then(|a| a.sanitized(read_only));
self.on_alphanumeric = self.on_alphanumeric =
self.on_alphanumeric.and_then(|a| a.sanitized(read_only)); self.on_alphanumeric.and_then(|a| a.sanitized(read_only));
self.on_special_character = self self.on_special_character = self
.on_special_character .on_special_character
.and_then(|a| a.sanitized(read_only)); .and_then(|a| a.sanitized(read_only));
self.on_character = self.on_character = self.on_character.and_then(|a| a.sanitized(read_only));
self.on_character.and_then(|a| a.sanitized(read_only)); self.on_navigation = self.on_navigation.and_then(|a| a.sanitized(read_only));
self.on_navigation = self.on_function = self.on_function.and_then(|a| a.sanitized(read_only));
self.on_navigation.and_then(|a| a.sanitized(read_only));
self.on_function =
self.on_function.and_then(|a| a.sanitized(read_only));
self.default = self.default.and_then(|a| a.sanitized(read_only)); self.default = self.default.and_then(|a| a.sanitized(read_only));
}; };
self self
@ -387,36 +382,32 @@ impl Mode {
let lines = extra_help_lines let lines = extra_help_lines
.unwrap_or_default() .unwrap_or_default()
.into_iter() .into_iter()
.chain(self.key_bindings.on_key.iter().filter_map( .chain(self.key_bindings.on_key.iter().filter_map(|(k, a)| {
|(k, a)| { let remaps = self
let remaps = self .key_bindings
.key_bindings .on_key
.on_key .iter()
.iter() .filter_map(|(rk, ra)| {
.filter_map(|(rk, ra)| { if rk == k {
if rk == k { None
None } else if a == ra {
} else if a == ra { Some(rk.clone())
Some(rk.clone()) } else {
} else { None
None }
}
})
.collect::<Vec<String>>();
a.help.clone().map(|h| {
HelpMenuLine::KeyMap(k.into(), remaps, h)
}) })
}, .collect::<Vec<String>>();
)) a.help
.clone()
.map(|h| HelpMenuLine::KeyMap(k.into(), remaps, h))
}))
.chain( .chain(
self.key_bindings self.key_bindings
.on_alphabet .on_alphabet
.iter() .iter()
.map(|a| ("[a-Z]", a.help.clone())) .map(|a| ("[a-Z]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -425,9 +416,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[0-9]", a.help.clone())) .map(|a| ("[0-9]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -436,9 +425,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[0-Z]", a.help.clone())) .map(|a| ("[0-Z]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -447,9 +434,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[^0-Z]", a.help.clone())) .map(|a| ("[^0-Z]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -458,9 +443,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[*]", a.help.clone())) .map(|a| ("[*]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -469,9 +452,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[nav]", a.help.clone())) .map(|a| ("[nav]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -480,9 +461,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[f1-f12]", a.help.clone())) .map(|a| ("[f1-f12]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
) )
.chain( .chain(
@ -491,9 +470,7 @@ impl Mode {
.iter() .iter()
.map(|a| ("[default]", a.help.clone())) .map(|a| ("[default]", a.help.clone()))
.filter_map(|(k, mh)| { .filter_map(|(k, mh)| {
mh.map(|h| { mh.map(|h| HelpMenuLine::KeyMap(k.into(), vec![], h))
HelpMenuLine::KeyMap(k.into(), vec![], h)
})
}), }),
); );

@ -49,8 +49,7 @@ fn keep_reading(
if rx_stopper.try_recv().unwrap_or(false) { if rx_stopper.try_recv().unwrap_or(false) {
tx_ack.send(()).unwrap(); tx_ack.send(()).unwrap();
break; break;
} else if event::poll(std::time::Duration::from_millis(150)) } else if event::poll(std::time::Duration::from_millis(150)).unwrap_or_default()
.unwrap_or_default()
{ {
// NOTE: The poll timeout need to stay low, else spawning sub subshell // NOTE: The poll timeout need to stay low, else spawning sub subshell
// and start typing immediately will cause panic. // and start typing immediately will cause panic.

@ -1,6 +1,5 @@
use crate::app::{ use crate::app::{
DirectoryBuffer, ExplorerConfig, ExternalMsg, InternalMsg, MsgIn, Node, DirectoryBuffer, ExplorerConfig, ExternalMsg, InternalMsg, MsgIn, Node, Task,
Task,
}; };
use anyhow::{Error, Result}; use anyhow::{Error, Result};
use std::fs; use std::fs;

@ -17,11 +17,8 @@ pub fn serialize<'lua, T: Serialize + Sized>(
lua: &'lua mlua::Lua, lua: &'lua mlua::Lua,
value: &T, value: &T,
) -> Result<mlua::Value<'lua>> { ) -> Result<mlua::Value<'lua>> {
lua.to_value_with( lua.to_value_with(value, SerializeOptions::new().serialize_none_to_null(false))
value, .map_err(Error::from)
SerializeOptions::new().serialize_none_to_null(false),
)
.map_err(Error::from)
} }
fn parse_version(version: &str) -> Result<(u16, u16, u16, Option<u16>)> { fn parse_version(version: &str) -> Result<(u16, u16, u16, Option<u16>)> {
@ -46,11 +43,7 @@ pub fn check_version(version: &str, path: &str) -> Result<()> {
let (rmajor, rminor, rbugfix, rbeta) = parse_version(VERSION)?; let (rmajor, rminor, rbugfix, rbeta) = parse_version(VERSION)?;
let (smajor, sminor, sbugfix, sbeta) = parse_version(version)?; let (smajor, sminor, sbugfix, sbeta) = parse_version(version)?;
if rmajor == smajor if rmajor == smajor && rminor == sminor && rbugfix >= sbugfix && rbeta == sbeta {
&& rminor == sminor
&& rbugfix >= sbugfix
&& rbeta == sbeta
{
Ok(()) Ok(())
} else { } else {
bail!( bail!(
@ -95,11 +88,10 @@ pub fn extend(lua: &Lua, path: &str) -> Result<Config> {
lua.load(&script).set_name("init")?.exec()?; lua.load(&script).set_name("init")?.exec()?;
let version: String = let version: String = match globals.get("version").and_then(|v| lua.from_value(v)) {
match globals.get("version").and_then(|v| lua.from_value(v)) { Ok(v) => v,
Ok(v) => v, Err(_) => bail!("'version' must be defined globally in {}", path),
Err(_) => bail!("'version' must be defined globally in {}", path), };
};
check_version(&version, path)?; check_version(&version, path)?;

@ -1085,18 +1085,16 @@ impl NodeSorterApplicable {
.unwrap_or_default(), .unwrap_or_default(),
), ),
NodeSorter::ByICanonicalAbsolutePath => { NodeSorter::ByICanonicalAbsolutePath => natord::compare_ignore_case(
natord::compare_ignore_case( &a.canonical
&a.canonical .as_ref()
.as_ref() .map(|s| s.absolute_path.clone())
.map(|s| s.absolute_path.clone()) .unwrap_or_default(),
.unwrap_or_default(), &b.canonical
&b.canonical .as_ref()
.as_ref() .map(|s| s.absolute_path.clone())
.map(|s| s.absolute_path.clone()) .unwrap_or_default(),
.unwrap_or_default(), ),
)
}
NodeSorter::ByCanonicalExtension => a NodeSorter::ByCanonicalExtension => a
.canonical .canonical
@ -1292,26 +1290,18 @@ impl NodeFilter {
fn apply(&self, node: &Node, input: &str, regex: Option<&Regex>) -> bool { fn apply(&self, node: &Node, input: &str, regex: Option<&Regex>) -> bool {
match self { match self {
Self::RelativePathIs => node.relative_path.eq(input), Self::RelativePathIs => node.relative_path.eq(input),
Self::IRelativePathIs => { Self::IRelativePathIs => node.relative_path.eq_ignore_ascii_case(input),
node.relative_path.eq_ignore_ascii_case(input)
}
Self::RelativePathIsNot => !node.relative_path.eq(input), Self::RelativePathIsNot => !node.relative_path.eq(input),
Self::IRelativePathIsNot => { Self::IRelativePathIsNot => !node.relative_path.eq_ignore_ascii_case(input),
!node.relative_path.eq_ignore_ascii_case(input)
}
Self::RelativePathDoesStartWith => { Self::RelativePathDoesStartWith => node.relative_path.starts_with(input),
node.relative_path.starts_with(input)
}
Self::IRelativePathDoesStartWith => node Self::IRelativePathDoesStartWith => node
.relative_path .relative_path
.to_lowercase() .to_lowercase()
.starts_with(&input.to_lowercase()), .starts_with(&input.to_lowercase()),
Self::RelativePathDoesNotStartWith => { Self::RelativePathDoesNotStartWith => !node.relative_path.starts_with(input),
!node.relative_path.starts_with(input)
}
Self::IRelativePathDoesNotStartWith => !node Self::IRelativePathDoesNotStartWith => !node
.relative_path .relative_path
.to_lowercase() .to_lowercase()
@ -1323,25 +1313,19 @@ impl NodeFilter {
.to_lowercase() .to_lowercase()
.contains(&input.to_lowercase()), .contains(&input.to_lowercase()),
Self::RelativePathDoesNotContain => { Self::RelativePathDoesNotContain => !node.relative_path.contains(input),
!node.relative_path.contains(input)
}
Self::IRelativePathDoesNotContain => !node Self::IRelativePathDoesNotContain => !node
.relative_path .relative_path
.to_lowercase() .to_lowercase()
.contains(&input.to_lowercase()), .contains(&input.to_lowercase()),
Self::RelativePathDoesEndWith => { Self::RelativePathDoesEndWith => node.relative_path.ends_with(input),
node.relative_path.ends_with(input)
}
Self::IRelativePathDoesEndWith => node Self::IRelativePathDoesEndWith => node
.relative_path .relative_path
.to_lowercase() .to_lowercase()
.ends_with(&input.to_lowercase()), .ends_with(&input.to_lowercase()),
Self::RelativePathDoesNotEndWith => { Self::RelativePathDoesNotEndWith => !node.relative_path.ends_with(input),
!node.relative_path.ends_with(input)
}
Self::IRelativePathDoesNotEndWith => !node Self::IRelativePathDoesNotEndWith => !node
.relative_path .relative_path
.to_lowercase() .to_lowercase()
@ -1362,26 +1346,18 @@ impl NodeFilter {
.unwrap_or(false), .unwrap_or(false),
Self::AbsolutePathIs => node.absolute_path.eq(input), Self::AbsolutePathIs => node.absolute_path.eq(input),
Self::IAbsolutePathIs => { Self::IAbsolutePathIs => node.absolute_path.eq_ignore_ascii_case(input),
node.absolute_path.eq_ignore_ascii_case(input)
}
Self::AbsolutePathIsNot => !node.absolute_path.eq(input), Self::AbsolutePathIsNot => !node.absolute_path.eq(input),
Self::IAbsolutePathIsNot => { Self::IAbsolutePathIsNot => !node.absolute_path.eq_ignore_ascii_case(input),
!node.absolute_path.eq_ignore_ascii_case(input)
}
Self::AbsolutePathDoesStartWith => { Self::AbsolutePathDoesStartWith => node.absolute_path.starts_with(input),
node.absolute_path.starts_with(input)
}
Self::IAbsolutePathDoesStartWith => node Self::IAbsolutePathDoesStartWith => node
.absolute_path .absolute_path
.to_lowercase() .to_lowercase()
.starts_with(&input.to_lowercase()), .starts_with(&input.to_lowercase()),
Self::AbsolutePathDoesNotStartWith => { Self::AbsolutePathDoesNotStartWith => !node.absolute_path.starts_with(input),
!node.absolute_path.starts_with(input)
}
Self::IAbsolutePathDoesNotStartWith => !node Self::IAbsolutePathDoesNotStartWith => !node
.absolute_path .absolute_path
.to_lowercase() .to_lowercase()
@ -1393,25 +1369,19 @@ impl NodeFilter {
.to_lowercase() .to_lowercase()
.contains(&input.to_lowercase()), .contains(&input.to_lowercase()),
Self::AbsolutePathDoesNotContain => { Self::AbsolutePathDoesNotContain => !node.absolute_path.contains(input),
!node.absolute_path.contains(input)
}
Self::IAbsolutePathDoesNotContain => !node Self::IAbsolutePathDoesNotContain => !node
.absolute_path .absolute_path
.to_lowercase() .to_lowercase()
.contains(&input.to_lowercase()), .contains(&input.to_lowercase()),
Self::AbsolutePathDoesEndWith => { Self::AbsolutePathDoesEndWith => node.absolute_path.ends_with(input),
node.absolute_path.ends_with(input)
}
Self::IAbsolutePathDoesEndWith => node Self::IAbsolutePathDoesEndWith => node
.absolute_path .absolute_path
.to_lowercase() .to_lowercase()
.ends_with(&input.to_lowercase()), .ends_with(&input.to_lowercase()),
Self::AbsolutePathDoesNotEndWith => { Self::AbsolutePathDoesNotEndWith => !node.absolute_path.ends_with(input),
!node.absolute_path.ends_with(input)
}
Self::IAbsolutePathDoesNotEndWith => !node Self::IAbsolutePathDoesNotEndWith => !node
.absolute_path .absolute_path
.to_lowercase() .to_lowercase()

@ -3,9 +3,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs::Metadata; use std::fs::Metadata;
#[derive( #[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize, Hash, Default)]
Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize, Hash, Default,
)]
pub struct Permissions { pub struct Permissions {
pub user_read: bool, pub user_read: bool,
pub user_write: bool, pub user_write: bool,

@ -23,8 +23,7 @@ impl Pipe {
let msg_in = path.join("msg_in").to_string_lossy().to_string(); let msg_in = path.join("msg_in").to_string_lossy().to_string();
let selection_out = let selection_out = path.join("selection_out").to_string_lossy().to_string();
path.join("selection_out").to_string_lossy().to_string();
let result_out = path.join("result_out").to_string_lossy().to_string(); let result_out = path.join("result_out").to_string_lossy().to_string();
@ -40,8 +39,7 @@ impl Pipe {
let logs_out = path.join("logs_out").to_string_lossy().to_string(); let logs_out = path.join("logs_out").to_string_lossy().to_string();
let history_out = let history_out = path.join("history_out").to_string_lossy().to_string();
path.join("history_out").to_string_lossy().to_string();
Ok(Self { Ok(Self {
path: path.to_string_lossy().to_string(), path: path.to_string_lossy().to_string(),

@ -172,12 +172,8 @@ impl Runner {
pub fn run(self) -> Result<Option<String>> { pub fn run(self) -> Result<Option<String>> {
// Why unsafe? See https://github.com/sayanarijit/xplr/issues/309 // Why unsafe? See https://github.com/sayanarijit/xplr/issues/309
let lua = unsafe { mlua::Lua::unsafe_new() }; let lua = unsafe { mlua::Lua::unsafe_new() };
let mut app = app::App::create( let mut app =
self.pwd, app::App::create(self.pwd, &lua, self.config_file, self.extra_config_files)?;
&lua,
self.config_file,
self.extra_config_files,
)?;
app.config.general.read_only = self.read_only; app.config.general.read_only = self.read_only;
fs::create_dir_all(app.session_path.clone())?; fs::create_dir_all(app.session_path.clone())?;
@ -250,11 +246,7 @@ impl Runner {
terminal.hide_cursor()?; terminal.hide_cursor()?;
// Threads // Threads
pwd_watcher::keep_watching( pwd_watcher::keep_watching(app.pwd.as_ref(), tx_msg_in.clone(), rx_pwd_watcher)?;
app.pwd.as_ref(),
tx_msg_in.clone(),
rx_pwd_watcher,
)?;
let mut event_reader = EventReader::new(tx_msg_in.clone()); let mut event_reader = EventReader::new(tx_msg_in.clone());
event_reader.start(); event_reader.start();
@ -328,9 +320,8 @@ impl Runner {
explorer::explore_async( explorer::explore_async(
app.explorer_config.clone(), app.explorer_config.clone(),
app.pwd.clone().into(), app.pwd.clone().into(),
app.focused_node().map(|n| { app.focused_node()
n.relative_path.clone().into() .map(|n| n.relative_path.clone().into()),
}),
app.directory_buffer app.directory_buffer
.as_ref() .as_ref()
.map(|d| d.focus) .map(|d| d.focus)
@ -344,9 +335,8 @@ impl Runner {
explorer::explore_recursive_async( explorer::explore_recursive_async(
app.explorer_config.clone(), app.explorer_config.clone(),
app.pwd.clone().into(), app.pwd.clone().into(),
app.focused_node().map(|n| { app.focused_node()
n.relative_path.clone().into() .map(|n| n.relative_path.clone().into()),
}),
app.directory_buffer app.directory_buffer
.as_ref() .as_ref()
.map(|d| d.focus) .map(|d| d.focus)
@ -361,11 +351,7 @@ impl Runner {
let focus = app.focused_node(); let focus = app.focused_node();
if focus != last_focus.as_ref() { if focus != last_focus.as_ref() {
if let Some(ref mut file) = fifo { if let Some(ref mut file) = fifo {
writeln!( writeln!(file, "{}", app.focused_node_str())?;
file,
"{}",
app.focused_node_str()
)?;
}; };
last_focus = focus.cloned(); last_focus = focus.cloned();
} }
@ -376,16 +362,12 @@ impl Runner {
// OSC 7: Change CWD // OSC 7: Change CWD
if !(*ui::NO_COLOR) { if !(*ui::NO_COLOR) {
terminal write!(
.backend_mut() terminal.backend_mut(),
.write( "\x1b]7;file://{}{}\x1b\\",
format!( &app.hostname,
"\x1b]7;file://{}{}\x1b\\", &app.pwd
&app.hostname, &app.pwd )?;
)
.as_bytes(),
)
.unwrap_or_default();
} }
last_pwd = app.pwd.clone(); last_pwd = app.pwd.clone();
@ -405,8 +387,7 @@ impl Runner {
mouse_enabled = true; mouse_enabled = true;
} }
Err(e) => { Err(e) => {
app = app = app.log_error(e.to_string())?;
app.log_error(e.to_string())?;
} }
} }
} }
@ -434,18 +415,14 @@ impl Runner {
mouse_enabled = false; mouse_enabled = false;
} }
Err(e) => { Err(e) => {
app = app = app.log_error(e.to_string())?;
app.log_error(e.to_string())?;
} }
} }
} }
} }
StartFifo(path) => { StartFifo(path) => {
fifo = match start_fifo( fifo = match start_fifo(&path, &app.focused_node_str()) {
&path,
&app.focused_node_str(),
) {
Ok(file) => Some(file), Ok(file) => Some(file),
Err(e) => { Err(e) => {
app = app.log_error(e.to_string())?; app = app.log_error(e.to_string())?;
@ -466,25 +443,22 @@ impl Runner {
fifo = None; fifo = None;
std::mem::drop(file); std::mem::drop(file);
} else { } else {
fifo = match start_fifo( fifo =
&path, match start_fifo(&path, &app.focused_node_str())
&app.focused_node_str(), {
) { Ok(file) => Some(file),
Ok(file) => Some(file), Err(e) => {
Err(e) => { app = app.log_error(e.to_string())?;
app = None
app.log_error(e.to_string())?; }
None
} }
}
} }
} }
CallLuaSilently(func) => { CallLuaSilently(func) => {
match call_lua_heavy(&app, &lua, &func, false) { match call_lua_heavy(&app, &lua, &func, false) {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app.handle_batch_external_msgs(msgs)?;
.handle_batch_external_msgs(msgs)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
@ -510,8 +484,7 @@ impl Runner {
match pipe::read_all(&app.pipe.msg_in) { match pipe::read_all(&app.pipe.msg_in) {
Ok(msgs) => { Ok(msgs) => {
app = app app = app.handle_batch_external_msgs(msgs)?;
.handle_batch_external_msgs(msgs)?;
} }
Err(err) => { Err(err) => {
app = app.log_error(err.to_string())?; app = app.log_error(err.to_string())?;
@ -541,8 +514,7 @@ impl Runner {
match call_lua_heavy(&app, &lua, &func, false) { match call_lua_heavy(&app, &lua, &func, false) {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app.handle_batch_external_msgs(msgs)?;
.handle_batch_external_msgs(msgs)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
@ -564,8 +536,7 @@ impl Runner {
mouse_enabled = true; mouse_enabled = true;
} }
Err(e) => { Err(e) => {
app = app = app.log_error(e.to_string())?;
app.log_error(e.to_string())?;
} }
} }
} }
@ -591,9 +562,7 @@ impl Runner {
match res { match res {
Ok(Value::Function(f)) => { Ok(Value::Function(f)) => {
let arg = app.to_lua_ctx_heavy(); let arg = app.to_lua_ctx_heavy();
let res: Result< let res: Result<Option<Vec<ExternalMsg>>> = lua
Option<Vec<ExternalMsg>>,
> = lua
.to_value(&arg) .to_value(&arg)
.and_then(|a| f.call(a)) .and_then(|a| f.call(a))
.and_then(|v| lua.from_value(v)) .and_then(|v| lua.from_value(v))
@ -601,36 +570,25 @@ impl Runner {
match res { match res {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app
.handle_batch_external_msgs( .handle_batch_external_msgs(msgs)?;
msgs,
)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error( app = app.log_error(err.to_string())?;
err.to_string(),
)?;
} }
} }
} }
Ok(v) => { Ok(v) => {
let res: Result< let res: Result<Option<Vec<ExternalMsg>>> =
Option<Vec<ExternalMsg>>, lua.from_value(v).map_err(Error::from);
> = lua
.from_value(v)
.map_err(Error::from);
match res { match res {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app
.handle_batch_external_msgs( .handle_batch_external_msgs(msgs)?;
msgs,
)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error( app = app.log_error(err.to_string())?;
err.to_string(),
)?;
} }
} }
} }
@ -653,8 +611,7 @@ impl Runner {
mouse_enabled = true; mouse_enabled = true;
} }
Err(e) => { Err(e) => {
app = app = app.log_error(e.to_string())?;
app.log_error(e.to_string())?;
} }
} }
} }
@ -667,9 +624,7 @@ impl Runner {
match res { match res {
Ok(Value::Function(f)) => { Ok(Value::Function(f)) => {
let arg = app.to_lua_ctx_heavy(); let arg = app.to_lua_ctx_heavy();
let res: Result< let res: Result<Option<Vec<ExternalMsg>>> = lua
Option<Vec<ExternalMsg>>,
> = lua
.to_value(&arg) .to_value(&arg)
.and_then(|a| f.call(a)) .and_then(|a| f.call(a))
.and_then(|v| lua.from_value(v)) .and_then(|v| lua.from_value(v))
@ -677,36 +632,25 @@ impl Runner {
match res { match res {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app
.handle_batch_external_msgs( .handle_batch_external_msgs(msgs)?;
msgs,
)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error( app = app.log_error(err.to_string())?;
err.to_string(),
)?;
} }
} }
} }
Ok(v) => { Ok(v) => {
let res: Result< let res: Result<Option<Vec<ExternalMsg>>> =
Option<Vec<ExternalMsg>>, lua.from_value(v).map_err(Error::from);
> = lua
.from_value(v)
.map_err(Error::from);
match res { match res {
Ok(Some(msgs)) => { Ok(Some(msgs)) => {
app = app app = app
.handle_batch_external_msgs( .handle_batch_external_msgs(msgs)?;
msgs,
)?;
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error( app = app.log_error(err.to_string())?;
err.to_string(),
)?;
} }
} }
} }
@ -747,8 +691,7 @@ impl Runner {
// TODO remove duplicate segment // TODO remove duplicate segment
match pipe::read_all(&app.pipe.msg_in) { match pipe::read_all(&app.pipe.msg_in) {
Ok(msgs) => { Ok(msgs) => {
app = app app = app.handle_batch_external_msgs(msgs)?;
.handle_batch_external_msgs(msgs)?;
} }
Err(err) => { Err(err) => {
app = app.log_error(err.to_string())?; app = app.log_error(err.to_string())?;
@ -775,8 +718,7 @@ impl Runner {
mouse_enabled = true; mouse_enabled = true;
} }
Err(e) => { Err(e) => {
app = app = app.log_error(e.to_string())?;
app.log_error(e.to_string())?;
} }
} }
} }
@ -795,8 +737,7 @@ impl Runner {
terminal.clear()?; terminal.clear()?;
terminal.set_cursor(0, 0)?; terminal.set_cursor(0, 0)?;
execute!(terminal.backend_mut(), term::LeaveAlternateScreen)?; execute!(terminal.backend_mut(), term::LeaveAlternateScreen)?;
execute!(terminal.backend_mut(), event::DisableMouseCapture) execute!(terminal.backend_mut(), event::DisableMouseCapture).unwrap_or_default();
.unwrap_or_default();
term::disable_raw_mode()?; term::disable_raw_mode()?;
terminal.show_cursor()?; terminal.show_cursor()?;

@ -15,14 +15,12 @@ use std::env;
use std::ops::BitXor; use std::ops::BitXor;
use tui::backend::Backend; use tui::backend::Backend;
use tui::layout::Rect as TuiRect; use tui::layout::Rect as TuiRect;
use tui::layout::{ use tui::layout::{Constraint as TuiConstraint, Direction, Layout as TuiLayout};
Constraint as TuiConstraint, Direction, Layout as TuiLayout,
};
use tui::style::{Color, Modifier as TuiModifier, Style as TuiStyle}; use tui::style::{Color, Modifier as TuiModifier, Style as TuiStyle};
use tui::text::{Span, Spans, Text}; use tui::text::{Span, Spans, Text};
use tui::widgets::{ use tui::widgets::{
Block, BorderType as TuiBorderType, Borders as TuiBorders, Cell, List, Block, BorderType as TuiBorderType, Borders as TuiBorders, Cell, List, ListItem,
ListItem, Paragraph, Row, Table, Paragraph, Row, Table,
}; };
use tui::Frame; use tui::Frame;
@ -43,8 +41,7 @@ fn string_to_text<'a>(string: String) -> Text<'a> {
if *NO_COLOR { if *NO_COLOR {
Text::raw(string) Text::raw(string)
} else { } else {
ansi_to_text(string.bytes()) ansi_to_text(string.bytes()).unwrap_or_else(|e| Text::raw(format!("{:?}", e)))
.unwrap_or_else(|e| Text::raw(format!("{:?}", e)))
} }
} }
@ -67,8 +64,7 @@ pub struct LayoutOptions {
impl LayoutOptions { impl LayoutOptions {
pub fn extend(mut self, other: &Self) -> Self { pub fn extend(mut self, other: &Self) -> Self {
self.margin = other.margin.or(self.margin); self.margin = other.margin.or(self.margin);
self.horizontal_margin = self.horizontal_margin = other.horizontal_margin.or(self.horizontal_margin);
other.horizontal_margin.or(self.horizontal_margin);
self.vertical_margin = other.vertical_margin.or(self.vertical_margin); self.vertical_margin = other.vertical_margin.or(self.vertical_margin);
self.constraints = other.constraints.to_owned().or(self.constraints); self.constraints = other.constraints.to_owned().or(self.constraints);
self self
@ -265,10 +261,8 @@ impl Style {
pub fn extend(mut self, other: &Self) -> Self { pub fn extend(mut self, other: &Self) -> Self {
self.fg = other.fg.or(self.fg); self.fg = other.fg.or(self.fg);
self.bg = other.bg.or(self.bg); self.bg = other.bg.or(self.bg);
self.add_modifiers = self.add_modifiers = other.add_modifiers.to_owned().or(self.add_modifiers);
other.add_modifiers.to_owned().or(self.add_modifiers); self.sub_modifiers = other.sub_modifiers.to_owned().or(self.sub_modifiers);
self.sub_modifiers =
other.sub_modifiers.to_owned().or(self.sub_modifiers);
self self
} }
} }
@ -288,12 +282,8 @@ impl Into<TuiStyle> for Style {
TuiStyle { TuiStyle {
fg: self.fg, fg: self.fg,
bg: self.bg, bg: self.bg,
add_modifier: TuiModifier::from_bits_truncate(xor( add_modifier: TuiModifier::from_bits_truncate(xor(self.add_modifiers)),
self.add_modifiers sub_modifier: TuiModifier::from_bits_truncate(xor(self.sub_modifiers)),
)),
sub_modifier: TuiModifier::from_bits_truncate(xor(
self.sub_modifiers
)),
} }
} }
} }
@ -322,11 +312,7 @@ pub enum Constraint {
} }
impl Constraint { impl Constraint {
pub fn to_tui( pub fn to_tui(self, screen_size: TuiRect, layout_size: TuiRect) -> TuiConstraint {
self,
screen_size: TuiRect,
layout_size: TuiRect,
) -> TuiConstraint {
match self { match self {
Self::Percentage(n) => TuiConstraint::Percentage(n), Self::Percentage(n) => TuiConstraint::Percentage(n),
Self::Ratio(x, y) => TuiConstraint::Ratio(x, y), Self::Ratio(x, y) => TuiConstraint::Ratio(x, y),
@ -518,9 +504,8 @@ fn draw_table<B: Backend>(
let config = panel_config.default.to_owned().extend(&panel_config.table); let config = panel_config.default.to_owned().extend(&panel_config.table);
let app_config = app.config.to_owned(); let app_config = app.config.to_owned();
let header_height = app_config.general.table.header.height.unwrap_or(1); let header_height = app_config.general.table.header.height.unwrap_or(1);
let height: usize = (layout_size.height.max(header_height + 2) let height: usize =
- (header_height + 2)) (layout_size.height.max(header_height + 2) - (header_height + 2)).into();
.into();
let rows = app let rows = app
.directory_buffer .directory_buffer
@ -595,25 +580,18 @@ fn draw_table<B: Backend>(
let (relative_index, is_before_focus, is_after_focus) = let (relative_index, is_before_focus, is_after_focus) =
match dir.focus.cmp(&index) { match dir.focus.cmp(&index) {
Ordering::Greater => { Ordering::Greater => (dir.focus - index, true, false),
(dir.focus - index, true, false)
}
Ordering::Less => (index - dir.focus, false, true), Ordering::Less => (index - dir.focus, false, true),
Ordering::Equal => (0, false, false), Ordering::Equal => (0, false, false),
}; };
let (mut prefix, mut suffix, mut style) = { let (mut prefix, mut suffix, mut style) = {
let ui = app_config.general.default_ui.to_owned(); let ui = app_config.general.default_ui.to_owned();
( (ui.prefix, ui.suffix, ui.style.extend(&node_type.style))
ui.prefix,
ui.suffix,
ui.style.extend(&node_type.style),
)
}; };
if is_focused && is_selected { if is_focused && is_selected {
let ui = let ui = app_config.general.focus_selection_ui.to_owned();
app_config.general.focus_selection_ui.to_owned();
prefix = ui.prefix.to_owned().or(prefix); prefix = ui.prefix.to_owned().or(prefix);
suffix = ui.suffix.to_owned().or(suffix); suffix = ui.suffix.to_owned().or(suffix);
style = style.extend(&ui.style); style = style.extend(&ui.style);
@ -688,9 +666,7 @@ fn draw_table<B: Backend>(
.widths(&table_constraints) .widths(&table_constraints)
.style(app_config.general.table.style.to_owned().into()) .style(app_config.general.table.style.to_owned().into())
.highlight_style(app_config.general.focus_ui.style.to_owned().into()) .highlight_style(app_config.general.focus_ui.style.to_owned().into())
.column_spacing( .column_spacing(app_config.general.table.col_spacing.unwrap_or_default())
app_config.general.table.col_spacing.unwrap_or_default(),
)
.block(block( .block(block(
config, config,
format!( format!(
@ -777,8 +753,7 @@ fn draw_help_menu<B: Backend>(
if app.config.general.hide_remaps_in_help_menu { if app.config.general.hide_remaps_in_help_menu {
[Cell::from(k), Cell::from(h)].to_vec() [Cell::from(k), Cell::from(h)].to_vec()
} else { } else {
[Cell::from(k), Cell::from(remaps.join("|")), Cell::from(h)] [Cell::from(k), Cell::from(remaps.join("|")), Cell::from(h)].to_vec()
.to_vec()
} }
}), }),
}) })
@ -857,9 +832,7 @@ fn draw_input_buffer<B: Backend>(
f.render_widget(input_buf, layout_size); f.render_widget(input_buf, layout_size);
f.set_cursor( f.set_cursor(
// Put cursor past the end of the input text // Put cursor past the end of the input text
layout_size.x layout_size.x + (input.cursor() as u16).min(width) + cursor_offset_left,
+ (input.cursor() as u16).min(width)
+ cursor_offset_left,
// Move one line down, from the border to the input line // Move one line down, from the border to the input line
layout_size.y + 1, layout_size.y + 1,
); );
@ -879,8 +852,7 @@ fn draw_sort_n_filter<B: Backend>(
.to_owned() .to_owned()
.extend(&panel_config.sort_and_filter); .extend(&panel_config.sort_and_filter);
let ui = app.config.general.sort_and_filter_ui.to_owned(); let ui = app.config.general.sort_and_filter_ui.to_owned();
let filter_by: &IndexSet<NodeFilterApplicable> = let filter_by: &IndexSet<NodeFilterApplicable> = &app.explorer_config.filters;
&app.explorer_config.filters;
let sort_by: &IndexSet<NodeSorterApplicable> = &app.explorer_config.sorters; let sort_by: &IndexSet<NodeSorterApplicable> = &app.explorer_config.sorters;
let defaultui = &ui.default_identifier; let defaultui = &ui.default_identifier;
let forwardui = defaultui let forwardui = defaultui
@ -977,11 +949,7 @@ fn draw_logs<B: Backend>(
app::LogLevel::Warning => ListItem::new(format!( app::LogLevel::Warning => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&logs_config &logs_config.warning.format.to_owned().unwrap_or_default(),
.warning
.format
.to_owned()
.unwrap_or_default(),
l.message l.message
)) ))
.style(logs_config.warning.style.to_owned().into()), .style(logs_config.warning.style.to_owned().into()),
@ -989,11 +957,7 @@ fn draw_logs<B: Backend>(
app::LogLevel::Success => ListItem::new(format!( app::LogLevel::Success => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&logs_config &logs_config.success.format.to_owned().unwrap_or_default(),
.success
.format
.to_owned()
.unwrap_or_default(),
l.message l.message
)) ))
.style(logs_config.success.style.to_owned().into()), .style(logs_config.success.style.to_owned().into()),
@ -1001,11 +965,7 @@ fn draw_logs<B: Backend>(
app::LogLevel::Error => ListItem::new(format!( app::LogLevel::Error => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&logs_config &logs_config.error.format.to_owned().unwrap_or_default(),
.error
.format
.to_owned()
.unwrap_or_default(),
l.message l.message
)) ))
.style(logs_config.error.style.to_owned().into()), .style(logs_config.error.style.to_owned().into()),
@ -1070,8 +1030,7 @@ pub fn draw_custom_content<B: Backend>(
let render = lua::serialize(lua, &ctx) let render = lua::serialize(lua, &ctx)
.map(|arg| { .map(|arg| {
lua::call(lua, &render, arg) lua::call(lua, &render, arg).unwrap_or_else(|e| format!("{:?}", e))
.unwrap_or_else(|e| format!("{:?}", e))
}) })
.unwrap_or_else(|e| e.to_string()); .unwrap_or_else(|e| e.to_string());
@ -1243,12 +1202,8 @@ pub fn draw_layout<B: Backend>(
Layout::SortAndFilter => { Layout::SortAndFilter => {
draw_sort_n_filter(f, screen_size, layout_size, app, lua) draw_sort_n_filter(f, screen_size, layout_size, app, lua)
} }
Layout::HelpMenu => { Layout::HelpMenu => draw_help_menu(f, screen_size, layout_size, app, lua),
draw_help_menu(f, screen_size, layout_size, app, lua) Layout::Selection => draw_selection(f, screen_size, layout_size, app, lua),
}
Layout::Selection => {
draw_selection(f, screen_size, layout_size, app, lua)
}
Layout::InputAndLogs => { Layout::InputAndLogs => {
if app.input.buffer.is_some() { if app.input.buffer.is_some() {
draw_input_buffer(f, screen_size, layout_size, app, lua); draw_input_buffer(f, screen_size, layout_size, app, lua);
@ -1256,15 +1211,9 @@ pub fn draw_layout<B: Backend>(
draw_logs(f, screen_size, layout_size, app, lua); draw_logs(f, screen_size, layout_size, app, lua);
}; };
} }
Layout::CustomContent { title, body } => draw_custom_content( Layout::CustomContent { title, body } => {
f, draw_custom_content(f, screen_size, layout_size, app, title, body, lua)
screen_size, }
layout_size,
app,
title,
body,
lua,
),
Layout::Horizontal { config, splits } => { Layout::Horizontal { config, splits } => {
let chunks = TuiLayout::default() let chunks = TuiLayout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
@ -1284,18 +1233,16 @@ pub fn draw_layout<B: Backend>(
.unwrap_or_default(), .unwrap_or_default(),
) )
.vertical_margin( .vertical_margin(
config config.vertical_margin.or(config.margin).unwrap_or_default(),
.vertical_margin
.or(config.margin)
.unwrap_or_default(),
) )
.split(layout_size); .split(layout_size);
splits.into_iter().zip(chunks.into_iter()).for_each( splits
|(split, chunk)| { .into_iter()
.zip(chunks.into_iter())
.for_each(|(split, chunk)| {
draw_layout(split, f, screen_size, chunk, app, lua) draw_layout(split, f, screen_size, chunk, app, lua)
}, });
);
} }
Layout::Vertical { config, splits } => { Layout::Vertical { config, splits } => {
@ -1317,18 +1264,16 @@ pub fn draw_layout<B: Backend>(
.unwrap_or_default(), .unwrap_or_default(),
) )
.vertical_margin( .vertical_margin(
config config.vertical_margin.or(config.margin).unwrap_or_default(),
.vertical_margin
.or(config.margin)
.unwrap_or_default(),
) )
.split(layout_size); .split(layout_size);
splits.into_iter().zip(chunks.into_iter()).for_each( splits
|(split, chunk)| { .into_iter()
.zip(chunks.into_iter())
.for_each(|(split, chunk)| {
draw_layout(split, f, screen_size, chunk, app, lua) draw_layout(split, f, screen_size, chunk, app, lua)
}, });
);
} }
} }
} }

Loading…
Cancel
Save