Skip to content

Commit

Permalink
Add state.escape to go back to normal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Jan 27, 2024
1 parent 9abae18 commit 382a911
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 55 deletions.
74 changes: 19 additions & 55 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

_ => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
}
}
}
Expand Down Expand Up @@ -702,9 +700,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
{
match (code, modifiers) {
(KeyCode::Esc, KeyModifiers::NONE) => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'zoxide;
}

Expand All @@ -729,9 +725,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
(KeyCode::Backspace, KeyModifiers::NONE)
| (KeyCode::Char('h'), KeyModifiers::CONTROL) => {
if current_pos == INITIAL_POS_Z + 1 {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'zoxide;
};
command.remove(
Expand Down Expand Up @@ -933,9 +927,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

(KeyCode::Esc, KeyModifiers::NONE) => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'insert;
}

Expand Down Expand Up @@ -1193,9 +1185,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}
}
_ => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
}
}
}
Expand Down Expand Up @@ -1238,20 +1228,17 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
None,
false,
);
go_to_info_line_and_reset();
hide_cursor();
state.escape();
print_info("1 item yanked.", state.layout.y);
}
}

_ => {
go_to_info_line_and_reset();
hide_cursor();
state.escape();
}
}
}
}
state.move_cursor(state.layout.y);
}

//put
Expand Down Expand Up @@ -1345,9 +1332,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

(KeyCode::Esc, KeyModifiers::NONE) => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break;
}

Expand Down Expand Up @@ -1697,9 +1682,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
{
match code {
KeyCode::Esc => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'reg;
}

Expand All @@ -1724,9 +1707,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {

KeyCode::Backspace => {
if current_pos == INITIAL_POS_COMMAND_LINE {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'reg;
} else {
command.remove(
Expand Down Expand Up @@ -1771,13 +1752,11 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
"p" => {
//In read-only directory, put disabled
if state.is_ro {
go_to_info_line_and_reset();
state.escape();
print_warning(
"Cannot put item in this directory.",
state.layout.y,
);
hide_cursor();
state.move_cursor(state.layout.y);
break 'reg;
}
if state.v_start.is_some() {
Expand Down Expand Up @@ -1856,13 +1835,11 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
state.move_cursor(state.layout.y);
break 'reg;
}
go_to_info_line_and_reset();
hide_cursor();
state.escape();
print_info(
"1 item yanked.",
state.layout.y,
);
state.move_cursor(state.layout.y);
break 'reg;
}
//yank (visual mode)
Expand Down Expand Up @@ -1920,13 +1897,11 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
//In read-only directory, delete
//disabled
if state.is_ro {
go_to_info_line_and_reset();
state.escape();
print_warning(
"Cannot delete item in this directory.",
state.layout.y,
);
hide_cursor();
state.move_cursor(state.layout.y);
break 'reg;
}
if state.v_start.is_some() {
Expand Down Expand Up @@ -1971,13 +1946,11 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
//In read-only directory, delete
//disabled
if state.is_ro {
go_to_info_line_and_reset();
state.escape();
print_warning(
"Cannot delete item in this directory.",
state.layout.y,
);
hide_cursor();
state.move_cursor(state.layout.y);
break 'reg;
}
if state.v_start.is_none() {
Expand Down Expand Up @@ -2128,9 +2101,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

(KeyCode::Esc, KeyModifiers::NONE) => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
break 'command;
}

Expand Down Expand Up @@ -2216,8 +2187,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let commands: Vec<&str> =
commands.split_whitespace().collect();
if commands.is_empty() {
go_to_info_line_and_reset();
state.move_cursor(state.layout.y);
state.escape();
break;
}
let command = commands[0];
Expand Down Expand Up @@ -2263,9 +2233,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
state.layout.show_reg();
state.redraw(state.layout.y);
} else if state.layout.is_reg() {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
} else {
state.layout.show_reg();
let (new_column, new_row) = state
Expand All @@ -2276,9 +2244,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
new_row,
state.layout.y,
)?;
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
}
break 'command;
}
Expand Down Expand Up @@ -2493,9 +2459,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
}

_ => {
go_to_info_line_and_reset();
hide_cursor();
state.move_cursor(state.layout.y);
state.escape();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,13 @@ impl State {
}
}

/// Escape to normal mode.
pub fn escape(&mut self) {
go_to_info_line_and_reset();
hide_cursor();
self.move_cursor(self.layout.y);
}

/// Print an item in the directory.
fn print_item(&self, item: &ItemInfo) {
let name = if item.file_name.bytes().len() <= self.layout.name_max_len {
Expand Down

0 comments on commit 382a911

Please sign in to comment.