summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyohei Uto <im@kyoheiu.dev>2022-12-12 09:54:16 +0900
committerGitHub <noreply@github.com>2022-12-12 09:54:16 +0900
commit541377485e4823e7871a098fb30c3672fda7f9a1 (patch)
tree030ae3b875e3d3235ed7ca3c76392b15a92242bb
parente71e5a22cb5326418142cc2a9ce1c5d4de142cfe (diff)
parentd7ea2f246772ebd84ec9f7062c3b9dfe9fb224b7 (diff)
Merge pull request #156 from kyoheiu/developv2.2.0
v2.2.0
-rw-r--r--CHANGELOG.md21
-rw-r--r--Cargo.lock50
-rw-r--r--Cargo.toml2
-rw-r--r--README.md70
-rw-r--r--config.yaml4
-rw-r--r--src/config.rs4
-rw-r--r--src/functions.rs38
-rw-r--r--src/help.rs3
-rw-r--r--src/run.rs415
-rw-r--r--src/session.rs20
-rw-r--r--src/state.rs155
-rw-r--r--src/term.rs12
12 files changed, 417 insertions, 377 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b637736..5b3dfc8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,26 @@
## Unreleased
+## v2.2.0 (2022-12-12)
+
+### Changed
+
+- **IMPORTANT**: Trash and log directory path changed.
+ - from v2.2.0, felix will use `dirs::data_local_dir()` to store the deleted items and log files, instead of `dirs::config_dir()`.
+ - Due to this change, the path for linux will be `$XDG_DATA_HOME/felix/{Trash, log}`, in most case `/home/user/.local/share/felix/{Trash, log}`. For Windows `{FOLDERID_LocalAppData}\felix\{Trash, log}`, typically `C:\Users\user\AppData\Local\felix\{Trash, log}`. No change for macOS users.
+ - Note that config file path is unchanged for any OS!
+ - Please don't forget deleting old trash diretory and log files if you don't want them anymore.
+- Refactoring overall.
+
+### Added
+
+- `:trash` to go to the trash directory.
+
+### Fixed
+
+- Support NetBSD to open file in a new window.
+- Properly remove broken symlink in Windows as well. Also, when deleting/puttiing a directory, broken symlink(s) in it won't cause any error and will be removed from the file system after deleting/putting.
+
## v2.1.1 (2022-12-02)
### Fixed
@@ -16,6 +36,7 @@
- Some refactoring around text-printing in the preview space.
- When you change the sort key, felix refresh the list more efficiently than ever by avoiding to read all the items.
+- Item order(Name): Case-insensitive instead of sensitive.
## v2.1.0 (2022-11-19)
diff --git a/Cargo.lock b/Cargo.lock
index 224a0a4..4e7f98f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -250,9 +250,9 @@ dependencies = [
[[package]]
name = "cxx"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453"
+checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf"
dependencies = [
"cc",
"cxxbridge-flags",
@@ -262,9 +262,9 @@ dependencies = [
[[package]]
name = "cxx-build"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0"
+checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39"
dependencies = [
"cc",
"codespan-reporting",
@@ -277,15 +277,15 @@ dependencies = [
[[package]]
name = "cxxbridge-flags"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71"
+checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12"
[[package]]
name = "cxxbridge-macro"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470"
+checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6"
dependencies = [
"proc-macro2",
"quote",
@@ -325,7 +325,7 @@ dependencies = [
[[package]]
name = "felix"
-version = "2.1.1"
+version = "2.2.0"
dependencies = [
"chrono",
"content_inspector",
@@ -348,9 +348,9 @@ dependencies = [
[[package]]
name = "filetime"
-version = "0.2.18"
+version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3"
+checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
dependencies = [
"cfg-if",
"libc",
@@ -470,9 +470,9 @@ dependencies = [
[[package]]
name = "libc"
-version = "0.2.137"
+version = "0.2.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
+checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "line-wrap"
@@ -571,9 +571,9 @@ checksum = "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c"
[[package]]
name = "nix"
-version = "0.25.0"
+version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
+checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
dependencies = [
"autocfg",
"bitflags",
@@ -657,9 +657,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
-version = "0.9.4"
+version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0"
+checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
dependencies = [
"cfg-if",
"libc",
@@ -802,18 +802,18 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
[[package]]
name = "serde"
-version = "1.0.148"
+version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
+checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.148"
+version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
+checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4"
dependencies = [
"proc-macro2",
"quote",
@@ -921,9 +921,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
-version = "1.0.104"
+version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce"
+checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
dependencies = [
"proc-macro2",
"quote",
@@ -1021,9 +1021,9 @@ dependencies = [
[[package]]
name = "typenum"
-version = "1.15.0"
+version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
+checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "unicode-ident"
diff --git a/Cargo.toml b/Cargo.toml
index 4c45bb7..9e94277 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "felix"
-version = "2.1.1"
+version = "2.2.0"
authors = ["Kyohei Uto <im@kyoheiu.dev>"]
edition = "2021"
description = "tui file manager with vim-like key mapping"
diff --git a/README.md b/README.md
index a6bff56..72bf3d5 100644
--- a/README.md
+++ b/README.md
@@ -2,25 +2,50 @@
# _felix_
-A tui file manager with vim-like key mapping, written in Rust.
+A tui file manager with Vim-like key mapping, written in Rust.
Fast, simple, and easy to configure & use.
-For the detailed document, please see https://kyoheiu.dev/felix.
+For an overview of this app, take a look at this README, especially [key manual](#key-manual).
+For more detailed document, visit https://kyoheiu.dev/felix.
+
+- [New release](#new-release)
+- [Status](#status)
+- [Installation](#installation)
+- [Integrations](#integrations)
+- [Usage](#usage)
+ - [Key manual](#key-manual)
+- [Preview feature](#preview)
+- [Configuration](#configuration)
![sample](screenshots/sample.gif)
-## New Release
+<a id="new-release"></a>
+
+## New release
+
+## v2.2.0 (2022-12-12)
+
+### Changed
-## v2.1.1 (2022-12-02)
+- **IMPORTANT**: Trash and log directory path changed.
+ - from v2.2.0, felix will use `dirs::data_local_dir()` to store the deleted items and log files, instead of `dirs::config_dir()`.
+ - Due to this change, the path for linux will be `$XDG_DATA_HOME/felix/{Trash, log}`, in most case `/home/user/.local/share/felix/{Trash, log}`. For Windows `{FOLDERID_LocalAppData}\felix\{Trash, log}`, typically `C:\Users\user\AppData\Local\felix\{Trash, log}`. No change for macOS users.
+ - Note that config file path is unchanged for any OS!
+ - Please don't forget deleting old trash diretory and log files if you don't want them anymore.
+
+### Added
+
+- `:trash` to go to the trash directory.
### Fixed
-- You can now open a file in a new window on Wayland environment too.
-- Proper handling of wide characters: Even if e.g. file name includes some wide charatcters such as CJK, the layout won't break anymore.
-- Fix cursor color after printing the text preview.
+- Support NetBSD to open file in a new window.
+- Properly remove broken symlink in Windows as well. Also, when deleting/puttiing a directory, broken symlink(s) in it won't cause any error and will be removed from the file system after deleting/putting.
For more details, see `CHANGELOG.md`.
+<a id="status"></a>
+
## Status
| OS | Status |
@@ -32,6 +57,8 @@ For more details, see `CHANGELOG.md`.
_For Windows users: From v1.3.0, it can be at least compiled on Windows (see `.github/workflows/install_test.yml`.) If you're interested, please try and report any problems._
+<a id="installation"></a>
+
## Installation
### Prerequisites
@@ -59,7 +86,7 @@ yay -S felix-rs
### NetBSD
-available from the official repositories:
+Available from the official repositories.
```
pkgin install felix
@@ -73,6 +100,8 @@ cd felix
cargo install --path .
```
+<a id="integrations"></a>
+
## Integrations
In addition, you can use felix more conveniently by installing these two apps:
@@ -82,6 +111,8 @@ In addition, you can use felix more conveniently by installing these two apps:
These apps do not need any configuration to use with felix!
+<a id="usage"></a>
+
## Usage
```
@@ -90,7 +121,7 @@ These apps do not need any configuration to use with felix!
Both relative and absolute path available.
```
-## Options
+### Options
```
`-h` | `--help` => Print help.
@@ -98,7 +129,9 @@ Both relative and absolute path available.
`-l [path]` | `--log [path]` => Launch the app and create a log file.
```
-## Key Manual
+<a id="key-manual"></a>
+
+### Key manual
```
j / Down :Go down.
@@ -134,40 +167,45 @@ Esc :Return to the normal mode.
:cd / :z :Go to the home directory.
:z <keyword> :Same as `z <keyword>`.
:e :Reload the current directory.
+:trash :Go to the trash directory.
:empty :Empty the trash directory.
:h :Show help.
:q / ZZ :Exit.
```
+<a id="preview"></a>
+
## Preview feature
By default, text files and directories can be previewed.
Install `chafa` and you can preview images without any configuration.
+<a id="configuration"></a>
+
## Configuration
### Linux
```
config file : $XDG_CONFIG_HOME/felix/config.yaml
-trash directory : $XDG_CONFIG_HOME/felix/trash
-log files : \$XDG_CONFIG_HOME/felix/log
+trash directory : $XDG_DATA_HOME/felix/Trash
+log files : $XDG_DATA_HOME/felix/log
```
### macOS
```
config file : $HOME/Library/Application Support/felix/config.yaml
-trash directory : $HOME/Library/Application Support/felix/trash
-log files : \$HOME/Library/Application Support/felix/log
+trash directory : $HOME/Library/Application Support/felix/Trash
+log files : $HOME/Library/Application Support/felix/log
```
### Windows
```
config file : $PROFILE\AppData\Roaming\felix\config.yaml
-trash directory : $PROFILE\AppData\Roaming\felix\trash
-log files : $PROFILE\AppData\Roaming\felix\log
+trash directory : $PROFILE\AppData\Local\felix\Trash
+log files : $PROFILE\AppData\Local\felix\log
```
For more details, visit https://kyoheiu.dev/felix.
diff --git a/config.yaml b/config.yaml
index 60c4da4..9832fe7 100644
--- a/config.yaml
+++ b/config.yaml
@@ -1,12 +1,12 @@
# v2.1.1
# (Optional)
-# Default exec command when opening files.
+# Default exec command when opening file.
# If not set, will default to $EDITOR.
# default: nvim
# (Optional)
-# key (the command you want to use when opening certain files): [values] (extensions)
+# key (the command you want to use when opening file): [values] (extensions)
# exec:
# feh:
# [jpg, jpeg, png, gif, svg]
diff --git a/src/config.rs b/src/config.rs
index 2465197..25cf4b7 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,5 +1,5 @@
use super::errors::FxError;
-use super::state::FX_CONFIG_DIR;
+use super::state::FELIX;
use serde::Deserialize;
use std::collections::BTreeMap;
@@ -200,7 +200,7 @@ pub fn make_config_if_not_exists(config_file: &Path, trash_dir: &Path) -> Result
fn config_file_path() -> Result<PathBuf, FxError> {
let mut config =
dirs::config_dir().ok_or_else(|| FxError::Dirs("Cannot read config dir.".to_string()))?;
- config.push(FX_CONFIG_DIR);
+ config.push(FELIX);
config.push(CONFIG_FILE);
Ok(config)
}
diff --git a/src/functions.rs b/src/functions.rs
index eccb436..869ce8f 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -1,3 +1,5 @@
+use crate::state::FELIX;
+
use super::config::Colorname;
use super::errors::FxError;
use super::term::*;
@@ -11,6 +13,9 @@ use std::path::{Path, PathBuf};
use std::time::Duration;
pub const PROCESS_INDICATOR_LENGTH: u16 = 7;
+const KB: u64 = 1000;
+const MB: u64 = 1_000_000;
+const GB: u64 = 1_000_000_000;
/// Generate modified time as `String`.
pub fn format_time(time: &Option<String>) -> String {
@@ -67,18 +72,6 @@ pub fn rename_dir(dir_name: &str, name_set: &BTreeSet<String>) -> String {
new_name
}
-/// Move to information bar.
-pub fn go_to_and_rest_info() {
- to_info_bar();
- clear_current_line();
-}
-
-/// Delele cursor.
-pub fn delete_cursor() {
- print!(" ");
- move_left(1);
-}
-
/// Print the result of operation, such as put/delete/redo/undo.
pub fn print_info<T: std::fmt::Display>(message: T, then: u16) {
delete_cursor();
@@ -158,17 +151,17 @@ pub fn duration_to_string(duration: Duration) -> String {
/// Get the size format of item.
pub fn to_proper_size(byte: u64) -> String {
let mut result: String;
- if byte < 1000 {
+ if byte < KB {
result = byte.to_string();
result.push('B');
- } else if byte < 1_000_000 {
- result = (byte / 1_000).to_string();
+ } else if byte < MB {
+ result = (byte / KB).to_string();
result.push_str("KB");
- } else if byte < 1_000_000_000 {
- result = (byte / 1_000_000).to_string();
+ } else if byte < GB {
+ result = (byte / MB).to_string();
result.push_str("MB");
} else {
- result = (byte / 1_000_000_000).to_string();
+ result = (byte / GB).to_string();
result.push_str("GB");
}
result
@@ -256,14 +249,19 @@ pub fn is_editable(s: &str) -> bool {
}
/// Initialize the log if `-l` option is added.
-pub fn init_log(config_dir_path: &Path) -> Result<(), FxError> {
+pub fn init_log(data_local_path: &Path) -> Result<(), FxError> {
let mut log_name = chrono::Local::now().format("%F-%H-%M-%S").to_string();
log_name.push_str(".log");
let config = ConfigBuilder::new()
.set_time_offset_to_local()
.unwrap()
.build();
- let log_path = config_dir_path.join("log");
+ let log_path = {
+ let mut path = data_local_path.to_path_buf();
+ path.push(FELIX);
+ path.push("log");
+ path
+ };
if !log_path.exists() {
std::fs::create_dir(&log_path)?;
}
diff --git a/src/help.rs b/src/help.rs
index d4911b4..be869a6 100644
--- a/src/help.rs
+++ b/src/help.rs
@@ -1,5 +1,5 @@
/// Help text.
-pub const HELP: &str = "# felix v2.1.1
+pub const HELP: &str = "# felix v2.2.0
A simple TUI file manager with vim-like keymapping.
## Usage
@@ -46,6 +46,7 @@ Esc :Return to the normal mode.
:cd / :z :Go to the home directory.
:z <keyword> :Same as `z <keyword>`.
:e :Reload the current directory.
+:trash :Go to the trash directory.
:empty :Empty the trash directory.
:h :Show help.
:q / ZZ :Exit.
diff --git a/src/run.rs b/src/run.rs
index cacb4a5..fe361e6 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,7 +1,6 @@
use super::config::{make_config_if_not_exists, CONFIG_FILE};
use super::errors::FxError;
use super::functions::*;
-use super::help::HELP;
use super::layout::Split;
use super::nums::*;
use super::op::*;
@@ -19,46 +18,67 @@ use std::fmt::Write as _;
use std::io::{stdout, Write};
use std::panic;
use std::path::PathBuf;
-use std::time::{Duration, Instant};
+use std::time::Instant;
+pub const TRASH: &str = "Trash";
/// Where the item list starts to scroll.
const SCROLL_POINT: u16 = 3;
+const CLRSCR: &str = "\x1B[2J";
+const INITIAL_POS_RENAME: u16 = 12;
+const INITIAL_POS_SEARCH: usize = 3;
+const INITIAL_POS_SHELL: u16 = 3;
/// Launch the app. If initializing goes wrong, return error.
pub fn run(arg: PathBuf, log: bool) -> Result<(), FxError> {
- //Prepare config file and trash directory path.
+ //Check if argument path is valid.
+ if !&arg.exists() {
+ println!(
+ "Invalid path or argument: {}\n`fx -h` shows help.",
+ &arg.display()
+ );
+ return Ok(());
+ }
+
+ //Prepare config and data local path.
let config_dir_path = {
let mut path = dirs::config_dir()
- .ok_or_else(|| FxError::Dirs("Cannot read config dir.".to_string()))?;
- path.push(FX_CONFIG_DIR);
+ .ok_or_else(|| FxError::Dirs("Cannot read config directory.".to_string()))?;
+ path.push(FELIX);
path
};
- let config_file_path = config_dir_path.join(PathBuf::from(CONFIG_FILE));
- let trash_dir_path = config_dir_path.join(PathBuf::from(TRASH));
+ let data_local_path = dirs::data_local_dir()
+ .ok_or_else(|| FxError::Dirs("Cannot read data local directory.".to_string()))?;
- if log {
- init_log(&config_dir_path)?;
- }
+ //Set config file and trash dir path.
+ let config_file_path = config_dir_path.join(PathBuf::from(CONFIG_FILE));
+ let trash_dir_path = {
+ let mut path = data_local_path.clone();
+ path.push(FELIX);
+ path.push(TRASH);
+ path
+ };
//Make config file and trash directory if not exists.
make_config_if_not_exists(&config_file_path, &trash_dir_path)?;
- //If session file, which stores sortkey and whether to show hidden items, does not exist (i.e. first launch), make it.
- let session_file_path = config_dir_path.join(PathBuf::from(SESSION_FILE));
- if !session_file_path.exists() {
- make_session(&session_file_path)?;
+ //If `-l / --log` is set, initialize logger.
+ if log {
+ init_log(&data_local_path)?;
}
- if !&arg.exists() {
- println!(
- "Invalid path or argument: {}\n`fx -h` shows help.",
- &arg.display()
- );
- return Ok(());
+ //If session file does not exist (i.e. first launch), make it.
+ let session_file_path = {
+ let mut path = data_local_path;
+ path.push(FELIX);
+ path.push(SESSION_FILE);
+ path
+ };
+ if !session_file_path.exists() {
+ make_session(&session_file_path)?;
}
- //Initialize app state
- let mut state = State::new(&config_file_path)?;
+ //Initialize app state.
+ let mut state = State::new(&config_file_path, &session_file_path)?;
state.trash_dir = trash_dir_path;
state.current_dir = if cfg!(not(windows)) {
// If executed this on windows, "//?" will be inserted at the beginning of the path.
@@ -67,6 +87,7 @@ pub fn run(arg: PathBuf, log: bool) -> Result<(), FxError> {
arg
};
+ //If the main function causes panic, catch it.
let result = panic::catch_unwind(|| _run(state, session_file_path));
leave_raw_mode();
@@ -119,9 +140,9 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
Event::Key(KeyEvent {
code, modifiers, ..
}) => {
- //If you use kitty, you must clear the screen or the previewed image remains.
+ //If you use kitty, you must clear the screen by the escape sequence or the previewed image remains.
if state.layout.is_kitty && state.layout.preview {
- print!("\x1B[2J");
+ print!("{}", CLRSCR);
state.clear_and_show_headline();
state.list_up();
screen.flush()?;
@@ -169,8 +190,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
//Go to top
KeyCode::Char('g') => {
- to_info_bar();
- clear_current_line();
+ go_to_and_rest_info();
print!("g");
show_cursor();
screen.flush()?;
@@ -222,10 +242,6 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
execute!(screen, EnterAlternateScreen)?;
hide_cursor();
- //Add thread sleep time after state.open_file().
- // This is necessary because, with tiling window managers, the window resizing is sometimes slow and felix reloads the layout so quickly that the display may become broken.
- //By the sleep (50ms for now and I think it's not easy to recognize this sleep), this will be avoided.
- std::thread::sleep(Duration::from_millis(50));
state.reload(state.layout.y)?;
continue;
}
@@ -268,8 +284,8 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
//Open a file in a new window
- //This works only if [exec] is set in config file
- //and the extension of the item matches the key.
+ //This works only if i) [exec] is set in config file
+ //and ii) the extension of the item matches the key.
//If not, warning message appears.
KeyCode::Char('o') => {
if let Ok(item) = state.get_item() {
@@ -292,8 +308,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
}
- //Go to parent directory if exists.
- //If the list is filtered, reload current directory.
+ //Go to the parent directory if exists.
KeyCode::Char('h') | KeyCode::Left => {
let pre = state.current_dir.clone();
@@ -326,8 +341,8 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
//Jumps to the directory that matches the keyword (zoxide required).
KeyCode::Char('z') => {
- print!(" ");
- to_info_bar();
+ delete_cursor();
+ to_info_line();
clear_current_line();
print!("z");
show_cursor();
@@ -376,7 +391,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
current_pos -= 1;
clear_current_line();
- to_info_bar();
+ to_info_line();
print!("{}", &command.iter().collect::<String>(),);
move_to(current_pos, 2);
}
@@ -404,7 +419,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let output = output.stdout;
if output.is_empty() {
print_warning(
- "Keyword cannot match the database.",
+ "Keyword does not match the database.",
state.layout.y,
);
break 'zoxide;
@@ -457,7 +472,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
command.insert((current_pos - initial_pos).into(), c);
current_pos += 1;
clear_current_line();
- to_info_bar();
+ to_info_line();
print!("{}", &command.iter().collect::<String>(),);
move_to(current_pos, 2);
}
@@ -556,7 +571,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
if state.layout.nums.index == 0 {
continue;
} else {
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("g");
show_cursor();
@@ -698,7 +713,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
state.reorder(BEGINNING_ROW);
}
- // Show/hide hidden files or directories
+ //Show/hide hidden items.
KeyCode::Backspace => {
match state.layout.show_hidden {
true => {
@@ -714,7 +729,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
state.redraw(BEGINNING_ROW);
}
- //toggle whether to show preview of text file
+ //Toggle whether to show preview.
KeyCode::Char('v') => {
state.layout.preview = !state.layout.preview;
if state.layout.preview {
@@ -736,7 +751,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
}
- //toggle vertical or horizontal split
+ //Toggle vertical <-> horizontal split.
KeyCode::Char('s') => match state.layout.split {
Split::Vertical => {
state.layout.split = Split::Horizontal;
@@ -761,7 +776,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
if len == 0 {
continue;
} else {
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("d");
show_cursor();
@@ -816,7 +831,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
if len == 0 {
continue;
}
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("y");
show_cursor();
@@ -859,7 +874,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let duration = duration_to_string(start.elapsed());
let registered_len = state.registered.len();
- let mut put_message: String = registered_len.to_string();
+ let mut put_message = registered_len.to_string();
if registered_len == 1 {
let _ = write!(put_message, " item inserted [{}]", duration);
} else {
@@ -884,13 +899,11 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
show_cursor();
let mut rename = item.file_name.chars().collect::<Vec<char>>();
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("New name: {}", &rename.iter().collect::<String>(),);
screen.flush()?;
- // position after "New name: "
- let initial_pos = 12;
let mut current_pos: u16 = 12 + item.file_name.len() as u16;
loop {
if let Event::Key(KeyEvent { code, .. }) = event::read()? {
@@ -925,7 +938,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
KeyCode::Left => {
- if current_pos == initial_pos {
+ if current_pos == INITIAL_POS_RENAME {
continue;
};
current_pos -= 1;
@@ -934,7 +947,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
KeyCode::Right => {
if current_pos as usize
- == rename.len() + initial_pos as usize
+ == rename.len() + INITIAL_POS_RENAME as usize
{
continue;
};
@@ -943,23 +956,24 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
KeyCode::Char(c) => {
- rename.insert((current_pos - initial_pos).into(), c);
+ rename.insert((current_pos - INITIAL_POS_RENAME).into(), c);
current_pos += 1;
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("New name: {}", &rename.iter().collect::<String>(),);
move_to(current_pos, 2);
}
KeyCode::Backspace => {
- if current_pos == initial_pos {
+ if current_pos == INITIAL_POS_RENAME {
continue;
};
- rename.remove((current_pos - initial_pos - 1).into());
+ rename
+ .remove((current_pos - INITIAL_POS_RENAME - 1).into());
current_pos -= 1;
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("New name: {}", &rename.iter().collect::<String>(),);
move_to(current_pos, 2);
@@ -977,9 +991,9 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
if len == 0 {
continue;
}
- print!(" ");
+ delete_cursor();
show_cursor();
- to_info_bar();
+ to_info_line();
clear_current_line();
print!("/");
screen.flush()?;
@@ -987,9 +1001,8 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let original_nums = state.layout.nums;
let original_y = state.layout.y;
let mut keyword: Vec<char> = Vec::new();
- // position after " /"
- let initial_pos = 3;
- let mut current_pos = initial_pos;
+
+ let mut current_pos = INITIAL_POS_SEARCH;
loop {
let keyword_len = keyword.len();
if let Event::Key(KeyEvent { code, .. }) = event::read()? {
@@ -1008,7 +1021,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {