Skip to content

Commit

Permalink
Merge pull request #182 from kyoheiu/develop
Browse files Browse the repository at this point in the history
v2.2.5
  • Loading branch information
kyoheiu authored Feb 11, 2023
2 parents 43923f2 + bf06a8a commit 053c4df
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 97 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

## Unreleased

## v2.2.5 (2023-02-12)

### Added
- Allow renaming even when item name contains non-ascii chars (i.e. wide chars).
- Key command with arguments is now supported: For example,
```
exec:
'feh -.':
[jpg, jpeg, png, gif, svg, hdr]
```
this configuration enables you to execute `feh -. <item path>` by `Enter | l | Right`, or `o`.
- Check for out-of-boundary of the cursor at the top of loop.

### Fixed
- Display when using in kitty: Correctly show the cursor and preview.

## v2.2.4 (2023-02-01)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "felix"
version = "2.2.4"
version = "2.2.5"
authors = ["Kyohei Uto <[email protected]>"]
edition = "2021"
description = "tui file manager with vim-like key mapping"
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ For more detailed document, visit https://kyoheiu.dev/felix.

## New release

## v2.2.4 (2023-02-01)
## v2.2.5 (2023-02-12)

### Fixed
- Disable remove_and_yank in the trash dir.
- Clear selection in the select mode if something fails.
- Cursor move after deleting multiple items in select mode.

## v2.2.3 (2023-01-20)
### Added
- Allow renaming even when item name contains non-ascii chars (i.e. wide chars).
- Key command with arguments is now supported: For example,
```
exec:
'feh -.':
[jpg, jpeg, png, gif, svg, hdr]
```
this configuration enables you to execute `feh -. <item path>` by `Enter | l | Right`, or `o`.
- Check for out-of-boundary of the cursor at the top of loop.

### Fixed
- Wide chars handling: Using unicode_width, now felix can properly split file name or previewed texts.
- Preview space height: When horizontally split, image preview could break the layout. Fixed this by adjusting the height.

### Added
- `chafa`'s minimal supported version: >= v1.10.0
- Add pacman installation.
- Display when using in kitty: Correctly show the cursor and preview.

For more details, see `CHANGELOG.md`.

Expand Down
5 changes: 3 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

# (Optional)
# key (the command you want to use when opening file): [values] (extensions)
# In the key, You can use arguments.
# exec:
# feh:
# [jpg, jpeg, png, gif, svg]
# zathura:
# [pdf]
# 'feh -.':
# [jpg, jpeg, png, gif, svg, hdr]

# (Optional)
# Whether to use syntax highlighting in the preview mode.
Expand Down
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pub const CONFIG_EXAMPLE: &str = "# (Optional)
# default: nvim
# (Optional)
# key (the command you want to use): [values] (extensions)
# key (the command you want to use when opening files): [values] (extensions)
# In the key, You can use arguments.
# exec:
# feh:
# [jpg, jpeg, png, gif, svg]
# zathura:
# [pdf]
# 'feh -.':
# [jpg, jpeg, png, gif, svg, hdr]
# (Optional)
# Whether to use syntax highlighting in the preview mode.
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum FxError {
Io(String),
Dirs(String),
GetItem,
OpenItem,
OpenItem(String),
OpenNewWindow(String),
Yaml(String),
WalkDir(String),
Expand All @@ -33,7 +33,7 @@ impl std::fmt::Display for FxError {
FxError::Io(s) => s.to_owned(),
FxError::Dirs(s) => s.to_owned(),
FxError::GetItem => "Error: Cannot get item info".to_owned(),
FxError::OpenItem => "Error: Cannot open item".to_owned(),
FxError::OpenItem(s) => s.to_owned(),
FxError::OpenNewWindow(s) => s.to_owned(),
FxError::Yaml(s) => s.to_owned(),
FxError::WalkDir(s) => s.to_owned(),
Expand Down
17 changes: 0 additions & 17 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,6 @@ pub fn print_help(v: &[String], skip_number: usize, row: u16) {
}
}

/// Check if we can edit the file name safely.
pub fn is_editable(s: &str) -> bool {
s.is_ascii()
}

/// Initialize the log if `-l` option is added.
pub fn init_log(data_local_path: &Path) -> Result<(), FxError> {
let mut log_name = chrono::Local::now().format("%F-%H-%M-%S").to_string();
Expand Down Expand Up @@ -367,18 +362,6 @@ mod tests {
assert_eq!(tree, "├ archives\n└ images".to_string());
}

#[test]
fn test_is_editable() {
let s1 = "Hello, world!";
let s2 = "image.jpg";
let s3 = "a̐éö̲\r\n";
let s4 = "日本の首都は東京です";
assert!(is_editable(s1));
assert!(is_editable(s2));
assert!(!is_editable(s3));
assert!(!is_editable(s4));
}

#[test]
fn test_convert_to_permissions() {
let file = 33188;
Expand Down
2 changes: 1 addition & 1 deletion src/help.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Help text.
pub const HELP: &str = "# felix v2.2.4
pub const HELP: &str = "# felix v2.2.5
A simple TUI file manager with vim-like keymapping.
## Usage
Expand Down
99 changes: 57 additions & 42 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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;

Expand Down Expand Up @@ -149,6 +148,10 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
screen.flush()?;

'main: loop {
if state.is_out_of_bounds() {
state.layout.nums.reset();
state.redraw(BEGINNING_ROW);
}
screen.flush()?;
let len = state.list.len();

Expand Down Expand Up @@ -987,22 +990,15 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
continue;
}
let item = state.get_item()?.clone();
if !is_editable(&item.file_name) {
print_warning(
"Item name cannot be renamed due to the character type.",
state.layout.y,
);
continue;
}

show_cursor();
let mut rename = item.file_name.chars().collect::<Vec<char>>();
to_info_line();
clear_current_line();
print!("New name: {}", &rename.iter().collect::<String>(),);
screen.flush()?;

let mut current_pos: u16 = 12 + item.file_name.len() as u16;
let (mut current_pos, _) = cursor_pos()?;
let mut current_char_pos = rename.len();
loop {
if let Event::Key(KeyEvent { code, .. }) = event::read()? {
match code {
Expand Down Expand Up @@ -1040,55 +1036,73 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

KeyCode::Left => {
if current_pos == INITIAL_POS_RENAME {
if current_char_pos == 0 {
continue;
};
current_pos -= 1;
move_left(1);
if let Some(to_be_skipped) =
unicode_width::UnicodeWidthChar::width(
rename[current_char_pos - 1],
)
{
current_char_pos -= 1;
current_pos -= to_be_skipped as u16;
move_left(to_be_skipped as u16);
}
}

KeyCode::Right => {
if current_pos as usize
== rename.len() + INITIAL_POS_RENAME as usize
{
if current_char_pos as usize == rename.len() {
continue;
};
current_pos += 1;
move_right(1);
if let Some(to_be_skipped) =
unicode_width::UnicodeWidthChar::width(
rename[current_char_pos],
)
{
current_char_pos += 1;
current_pos += to_be_skipped as u16;
move_right(to_be_skipped as u16);
}
}

KeyCode::Char(c) => {
rename.insert(
(current_pos - INITIAL_POS_RENAME).into(),
c,
);
current_pos += 1;
if let Some(to_be_added) =
unicode_width::UnicodeWidthChar::width(c)
{
rename.insert((current_char_pos).into(), c);
current_char_pos += 1;
current_pos += to_be_added as u16;

to_info_line();
clear_current_line();
print!(
"New name: {}",
&rename.iter().collect::<String>(),
);
move_to(current_pos, 2);
to_info_line();
clear_current_line();
print!(
"New name: {}",
&rename.iter().collect::<String>(),
);
move_to(current_pos + 1, 2);
}
}

KeyCode::Backspace => {
if current_pos == INITIAL_POS_RENAME {
if current_char_pos == 0 {
continue;
};
rename.remove(
(current_pos - INITIAL_POS_RENAME - 1).into(),
);
current_pos -= 1;
let removed =
rename.remove((current_char_pos - 1).into());
if let Some(to_be_removed) =
unicode_width::UnicodeWidthChar::width(removed)
{
current_char_pos -= 1;
current_pos -= to_be_removed as u16;

to_info_line();
clear_current_line();
print!(
"New name: {}",
&rename.iter().collect::<String>(),
);
move_to(current_pos, 2);
to_info_line();
clear_current_line();
print!(
"New name: {}",
&rename.iter().collect::<String>(),
);
move_to(current_pos + 1, 2);
}
}

_ => continue,
Expand Down Expand Up @@ -1618,6 +1632,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
print!("{}", CLRSCR);
state.clear_and_show_headline();
state.list_up();
state.move_cursor(state.layout.y);
screen.flush()?;
}
}
Expand Down
Loading

0 comments on commit 053c4df

Please sign in to comment.