From 053615b0415caae1159297718223f2a3b46a3827 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Sun, 13 Nov 2022 01:39:24 +0530 Subject: [PATCH] Fix linting errors --- .envrc | 1 + .gitignore | 3 +++ flake.nix | 33 +++++++++++++++++++++++++++++++-- src/app.rs | 6 +++--- src/explorer.rs | 2 +- src/input.rs | 2 +- src/node.rs | 2 +- src/pipe.rs | 2 +- src/runner.rs | 5 +++-- src/ui.rs | 20 ++++++-------------- 10 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 01773a9..863591b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ book/ .idea/ .venv/ + +# direnv +.direnv/ diff --git a/flake.nix b/flake.nix index 31e1fb9..5a70e8a 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,13 @@ outputs = { self, nixpkgs, nix, ... }: let - systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + systems = [ + "x86_64-linux" + "i686-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" + ]; forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems); in { @@ -28,7 +34,30 @@ lockFile = ./Cargo.lock; }; }; - }); + } + ); defaultPackage = forAllSystems (system: self.packages.${system}.xplr); + devShells = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + devRequirements = with pkgs; [ + gcc + gnumake + clippy + rustc + cargo + rustfmt + rust-analyzer + ]; + in + { + default = pkgs.mkShell { + RUST_BACKTRACE = 1; + + buildInputs = devRequirements; + packages = devRequirements; + }; + } + ); }; } diff --git a/src/app.rs b/src/app.rs index 48c4811..4d35f4a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -305,7 +305,7 @@ impl App { let hostname = gethostname().to_string_lossy().to_string(); if let Some(vroot) = vroot.as_ref() { - if !pwd.starts_with(&vroot) { + if !pwd.starts_with(vroot) { bail!( "{:?} is outside of virtual root {:?}", pwd.to_string_lossy(), @@ -822,7 +822,7 @@ impl App { let dir = PathBuf::from(dir).absolutize()?.to_path_buf(); if let Some(vroot) = &self.vroot.clone() { - if !dir.starts_with(&vroot) { + if !dir.starts_with(vroot) { return self.log_error(format!( "{:?} is outside of virtual root {:?}", dir.to_string_lossy(), @@ -1742,7 +1742,7 @@ impl App { pub fn write_pipes(&self, delimiter: char) -> Result<()> { fs::create_dir_all(self.pipe.path.clone())?; - fs::write(&self.pipe.msg_in, &[delimiter as u8])?; + fs::write(&self.pipe.msg_in, [delimiter as u8])?; let selection_str = self.selection_str(delimiter); fs::write(&self.pipe.selection_out, selection_str)?; diff --git a/src/explorer.rs b/src/explorer.rs index f99f725..fb4a996 100644 --- a/src/explorer.rs +++ b/src/explorer.rs @@ -15,7 +15,7 @@ lazy_static! { } pub fn explore(parent: &PathBuf, config: &ExplorerConfig) -> Result> { - let dirs = fs::read_dir(&parent)?; + let dirs = fs::read_dir(parent)?; let mut nodes = dirs .filter_map(|d| { d.ok().map(|e| { diff --git a/src/input.rs b/src/input.rs index 30bdf7a..a9fe216 100644 --- a/src/input.rs +++ b/src/input.rs @@ -197,7 +197,7 @@ impl std::fmt::Display for Key { _ => c.to_string(), }) .unwrap_or_else(|| { - serde_yaml::to_value(&self) + serde_yaml::to_value(self) .ok() .and_then(|v| v.as_str().map(|v| v.to_string())) .unwrap_or_default() diff --git a/src/node.rs b/src/node.rs index aee6c34..b6547f4 100644 --- a/src/node.rs +++ b/src/node.rs @@ -14,7 +14,7 @@ fn mime_essence(path: &Path, is_dir: bool) -> String { if is_dir { String::from("inode/directory") } else { - mime_guess::from_path(&path) + mime_guess::from_path(path) .first() .map(|m| m.essence_str().to_string()) .unwrap_or_default() diff --git a/src/pipe.rs b/src/pipe.rs index f8c7879..db7a450 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -60,7 +60,7 @@ pub fn read_all(pipe: &str, delimiter: char) -> Result> { .read(true) .write(true) .create(false) - .open(&pipe)?; + .open(pipe)?; let mut in_str = String::new(); file.read_to_string(&mut in_str)?; diff --git a/src/runner.rs b/src/runner.rs index a6417cb..fb8fd7e 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -28,7 +28,7 @@ use tui_input::Input; pub fn get_tty() -> Result { let tty = "/dev/tty"; - match fs::OpenOptions::new().read(true).write(true).open(&tty) { + match fs::OpenOptions::new().read(true).write(true).open(tty) { Ok(f) => Ok(f), Err(e) => { bail!(format!("Failed to open {}. {}", tty, e)) @@ -323,6 +323,7 @@ impl Runner { let backend = CrosstermBackend::new(stdout); let mut terminal = Terminal::new(backend)?; terminal.hide_cursor()?; + terminal.clear()?; // Threads pwd_watcher::keep_watching(app.pwd.as_ref(), tx_msg_in.clone(), rx_pwd_watcher)?; @@ -334,7 +335,7 @@ impl Runner { tx_msg_in.send(app::Task::new(app::MsgIn::External(msg.clone()), None))?; } - // Refresh once after loading + // Refresh screen once after loading tx_msg_in.send(app::Task::new( app::MsgIn::External(app::ExternalMsg::Refresh), None, diff --git a/src/ui.rs b/src/ui.rs index 4500aea..253d1a1 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -809,27 +809,19 @@ fn draw_input_buffer( .to_owned() .extend(&panel_config.input_and_logs); - let cursor_offset_left = if config + let cursor_offset_left = config .borders .as_ref() .map(|b| b.contains(&Border::Left)) - .unwrap_or(false) - { - 1 - } else { - 0 - } + app.input.prompt.chars().count() as u16; + .unwrap_or(false) as u16 + + app.input.prompt.chars().count() as u16; - let cursor_offset_right = if config + let cursor_offset_right = config .borders .as_ref() .map(|b| b.contains(&Border::Right)) - .unwrap_or(false) - { - 2 - } else { - 1 - }; + .unwrap_or(false) as u16 + + 1; let offset_width = cursor_offset_left + cursor_offset_right; let width = layout_size.width.max(offset_width) - offset_width;