Skip to content

Commit

Permalink
Use 89 chars line length
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Jun 2, 2022
1 parent 21b8c3e commit e04b096
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 419 deletions.
6 changes: 2 additions & 4 deletions benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const PWD: &str = "/tmp/xplr_bench";
fn navigation_benchmark(c: &mut Criterion) {
fs::create_dir_all(PWD).unwrap();
(1..10000).for_each(|i| {
fs::File::create(std::path::Path::new(PWD).join(i.to_string()))
.unwrap();
fs::File::create(std::path::Path::new(PWD).join(i.to_string())).unwrap();
});

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

let lua = mlua::Lua::new();
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
edition = "2021"
max_width = 80
max_width = 89
tab_spaces = 4
use_field_init_shorthand = true
105 changes: 26 additions & 79 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ impl App {
None
}
} else {
let path =
PathBuf::from("/").join("etc").join("xplr").join("init.lua");
let path = PathBuf::from("/").join("etc").join("xplr").join("init.lua");
if path.exists() {
Some(path)
} else {
Expand Down Expand Up @@ -342,10 +341,7 @@ impl App {
self
}

pub fn handle_batch_external_msgs(
mut self,
msgs: Vec<ExternalMsg>,
) -> Result<Self> {
pub fn handle_batch_external_msgs(mut self, msgs: Vec<ExternalMsg>) -> Result<Self> {
for task in msgs
.into_iter()
.map(|msg| Task::new(MsgIn::External(msg), None))
Expand Down Expand Up @@ -376,11 +372,7 @@ impl App {
}
}

fn handle_external(
self,
msg: ExternalMsg,
key: Option<Key>,
) -> Result<Self> {
fn handle_external(self, msg: ExternalMsg, key: Option<Key>) -> Result<Self> {
if self.config.general.read_only && !msg.is_read_only() {
self.log_error("Cannot execute code in read-only mode.".into())
} else {
Expand All @@ -402,9 +394,7 @@ impl App {
self.focus_previous_by_relative_index_from_input()
}
FocusNext => self.focus_next(),
FocusNextByRelativeIndex(i) => {
self.focus_next_by_relative_index(i)
}
FocusNextByRelativeIndex(i) => self.focus_next_by_relative_index(i),
FocusNextByRelativeIndexFromInput => {
self.focus_next_by_relative_index_from_input()
}
Expand All @@ -421,18 +411,14 @@ impl App {
FollowSymlink => self.follow_symlink(),
SetInputPrompt(p) => self.set_input_prompt(p),
UpdateInputBuffer(op) => self.update_input_buffer(op),
UpdateInputBufferFromKey => {
self.update_input_buffer_from_key(key)
}
UpdateInputBufferFromKey => self.update_input_buffer_from_key(key),
BufferInput(input) => self.buffer_input(&input),
BufferInputFromKey => self.buffer_input_from_key(key),
SetInputBuffer(input) => self.set_input_buffer(input),
RemoveInputBufferLastCharacter => {
self.remove_input_buffer_last_character()
}
RemoveInputBufferLastWord => {
self.remove_input_buffer_last_word()
}
RemoveInputBufferLastWord => self.remove_input_buffer_last_word(),
ResetInputBuffer => self.reset_input_buffer(),
SwitchMode(mode) => self.switch_mode(&mode),
SwitchModeKeepingInputBuffer(mode) => {
Expand All @@ -447,9 +433,7 @@ impl App {
self.switch_mode_custom_keeping_input_buffer(&mode)
}
PopMode => self.pop_mode(),
PopModeKeepingInputBuffer => {
self.pop_mode_keeping_input_buffer()
}
PopModeKeepingInputBuffer => self.pop_mode_keeping_input_buffer(),
SwitchLayout(mode) => self.switch_layout(&mode),
SwitchLayoutBuiltin(mode) => self.switch_layout_builtin(&mode),
SwitchLayoutCustom(mode) => self.switch_layout_custom(&mode),
Expand All @@ -474,9 +458,7 @@ impl App {
AddNodeFilter(f) => self.add_node_filter(f),
AddNodeFilterFromInput(f) => self.add_node_filter_from_input(f),
RemoveNodeFilter(f) => self.remove_node_filter(f),
RemoveNodeFilterFromInput(f) => {
self.remove_node_filter_from_input(f)
}
RemoveNodeFilterFromInput(f) => self.remove_node_filter_from_input(f),
ToggleNodeFilter(f) => self.toggle_node_filter(f),
RemoveLastNodeFilter => self.remove_last_node_filter(),
ResetNodeFilters => self.reset_node_filters(),
Expand Down Expand Up @@ -650,10 +632,7 @@ impl App {
Ok(self)
}

fn focus_previous_by_relative_index(
mut self,
index: usize,
) -> Result<Self> {
fn focus_previous_by_relative_index(mut self, index: usize) -> Result<Self> {
let mut history = self.history.clone();
if let Some(dir) = self.directory_buffer_mut() {
if let Some(n) = dir.focused_node() {
Expand Down Expand Up @@ -737,11 +716,7 @@ impl App {
}
}

fn change_directory(
mut self,
dir: &str,
save_history: bool,
) -> Result<Self> {
fn change_directory(mut self, dir: &str, save_history: bool) -> Result<Self> {
let mut dir = PathBuf::from(dir);
if dir.is_relative() {
dir = PathBuf::from(self.pwd.clone()).join(dir);
Expand All @@ -750,8 +725,7 @@ impl App {
match env::set_current_dir(&dir) {
Ok(()) => {
let pwd = self.pwd.clone();
let focus =
self.focused_node().map(|n| n.relative_path.clone());
let focus = self.focused_node().map(|n| n.relative_path.clone());
self = self.add_last_focus(pwd, focus)?;
self.pwd = dir.to_string_lossy().to_string();
if save_history {
Expand Down Expand Up @@ -922,11 +896,7 @@ impl App {
}
}

pub fn focus_by_file_name(
mut self,
name: &str,
save_history: bool,
) -> Result<Self> {
pub fn focus_by_file_name(mut self, name: &str, save_history: bool) -> Result<Self> {
let mut history = self.history.clone();
if let Some(dir_buf) = self.directory_buffer_mut() {
if let Some(focus) = dir_buf
Expand Down Expand Up @@ -964,14 +934,11 @@ impl App {
}
if let Some(parent) = pathbuf.parent() {
if let Some(filename) = pathbuf.file_name() {
self.change_directory(
&parent.to_string_lossy().to_string(),
false,
)?
.focus_by_file_name(
&filename.to_string_lossy().to_string(),
save_history,
)
self.change_directory(&parent.to_string_lossy().to_string(), false)?
.focus_by_file_name(
&filename.to_string_lossy().to_string(),
save_history,
)
} else {
self.log_error(format!("{} not found", path))
}
Expand Down Expand Up @@ -1033,10 +1000,7 @@ impl App {
.and_then(App::reset_input_buffer)
}

fn switch_mode_builtin_keeping_input_buffer(
mut self,
mode: &str,
) -> Result<Self> {
fn switch_mode_builtin_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
if let Some(mode) = self.config.modes.builtin.get(mode).cloned() {
self = self.push_mode();
self.mode = mode.sanitized(self.config.general.read_only);
Expand All @@ -1051,10 +1015,7 @@ impl App {
.and_then(App::reset_input_buffer)
}

fn switch_mode_custom_keeping_input_buffer(
mut self,
mode: &str,
) -> Result<Self> {
fn switch_mode_custom_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
if let Some(mode) = self.config.modes.custom.get(mode).cloned() {
self = self.push_mode();
self.mode = mode.sanitized(self.config.general.read_only);
Expand Down Expand Up @@ -1174,8 +1135,7 @@ impl App {
path = PathBuf::from(self.pwd.clone()).join(path);
}
let parent = path.parent().map(|p| p.to_string_lossy().to_string());
let filename =
path.file_name().map(|p| p.to_string_lossy().to_string());
let filename = path.file_name().map(|p| p.to_string_lossy().to_string());
if let (Some(p), Some(n)) = (parent, filename) {
self.selection.insert(Node::new(p, n));
}
Expand Down Expand Up @@ -1265,33 +1225,21 @@ impl App {
Ok(self)
}

fn add_node_filter_from_input(
mut self,
filter: NodeFilter,
) -> Result<Self> {
fn add_node_filter_from_input(mut self, filter: NodeFilter) -> Result<Self> {
if let Some(input) = self.input.buffer.as_ref() {
self.explorer_config
.filters
.insert(NodeFilterApplicable::new(
filter,
input.value().into(),
));
.insert(NodeFilterApplicable::new(filter, input.value().into()));
};
Ok(self)
}

fn remove_node_filter(
mut self,
filter: NodeFilterApplicable,
) -> Result<Self> {
fn remove_node_filter(mut self, filter: NodeFilterApplicable) -> Result<Self> {
self.explorer_config.filters.retain(|f| f != &filter);
Ok(self)
}

fn remove_node_filter_from_input(
mut self,
filter: NodeFilter,
) -> Result<Self> {
fn remove_node_filter_from_input(mut self, filter: NodeFilter) -> Result<Self> {
if let Some(input) = self.input.buffer.as_ref() {
let nfa = NodeFilterApplicable::new(filter, input.value().into());
self.explorer_config.filters.retain(|f| f != &nfa);
Expand Down Expand Up @@ -1486,9 +1434,8 @@ impl App {

fn refresh_selection(mut self) -> Result<Self> {
// Should be able to select broken symlink
self.selection.retain(|n| {
PathBuf::from(&n.absolute_path).symlink_metadata().is_ok()
});
self.selection
.retain(|n| PathBuf::from(&n.absolute_path).symlink_metadata().is_ok());
Ok(self)
}

Expand Down
Loading

0 comments on commit e04b096

Please sign in to comment.