feat: Support entry renaming #3
4 changed files with 11 additions and 11 deletions
|
@ -8,7 +8,7 @@ use termion::event::Key as TKey;
|
||||||
use crate::controller::EventQueue;
|
use crate::controller::EventQueue;
|
||||||
|
|
||||||
impl<W: Write> EventQueue<W> {
|
impl<W: Write> EventQueue<W> {
|
||||||
/// TODO
|
/// Remove the last character from the string.
|
||||||
fn pop_char(name: &str) -> Cow<'_, str> {
|
fn pop_char(name: &str) -> Cow<'_, str> {
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
return Cow::Borrowed(name);
|
return Cow::Borrowed(name);
|
||||||
|
@ -18,7 +18,7 @@ impl<W: Write> EventQueue<W> {
|
||||||
Cow::Owned(chars.collect())
|
Cow::Owned(chars.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Add a character to the string, if it is not a control character.
|
||||||
fn push_char<'a>(name: &'a str, chr: &char) -> Cow<'a, str> {
|
fn push_char<'a>(name: &'a str, chr: &char) -> Cow<'a, str> {
|
||||||
if chr.is_control() {
|
if chr.is_control() {
|
||||||
return Cow::Borrowed(name);
|
return Cow::Borrowed(name);
|
||||||
|
@ -26,7 +26,7 @@ impl<W: Write> EventQueue<W> {
|
||||||
Cow::Owned(format!("{name}{chr}"))
|
Cow::Owned(format!("{name}{chr}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Rename the current file to the new name.
|
||||||
pub fn do_rename_current_file(&mut self, new_name: &str) -> Option<()> {
|
pub fn do_rename_current_file(&mut self, new_name: &str) -> Option<()> {
|
||||||
let new_path = self.pager.current_entry.with_file_name(new_name);
|
let new_path = self.pager.current_entry.with_file_name(new_name);
|
||||||
if !new_path.exists() {
|
if !new_path.exists() {
|
||||||
|
@ -35,7 +35,7 @@ impl<W: Write> EventQueue<W> {
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Handle the rename input, and return the new name.
|
||||||
pub fn do_handle_rename_input<'a>(&mut self, new_name: &'a str, key: &TKey) -> Cow<'a, str> {
|
pub fn do_handle_rename_input<'a>(&mut self, new_name: &'a str, key: &TKey) -> Cow<'a, str> {
|
||||||
match key {
|
match key {
|
||||||
TKey::Backspace => return Self::pop_char(new_name),
|
TKey::Backspace => return Self::pop_char(new_name),
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod key_event_handler;
|
||||||
mod key_event_matcher;
|
mod key_event_matcher;
|
||||||
mod resize_event_handler;
|
mod resize_event_handler;
|
||||||
|
|
||||||
/// TODO
|
/// Entrie, a struct that represents a file or directory.
|
||||||
pub struct Entrie {
|
pub struct Entrie {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub display_text: String,
|
pub display_text: String,
|
||||||
|
@ -115,7 +115,7 @@ impl<W: Write> EventQueue<W> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entrie {
|
impl Entrie {
|
||||||
/// TODO
|
/// Create a new `Entrie`.
|
||||||
pub fn new(path: impl AsRef<Path>, display_text: impl Into<String>) -> Self {
|
pub fn new(path: impl AsRef<Path>, display_text: impl Into<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl From<&String> for Key {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key {
|
impl Key {
|
||||||
/// TODO
|
/// Returns the inner termion key event.
|
||||||
pub fn inner(&self) -> &TKey {
|
pub fn inner(&self) -> &TKey {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
termion::event::Event::Key(tkey) => tkey,
|
termion::event::Event::Key(tkey) => tkey,
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||||
|
|
||||||
/// TODO
|
/// Mode of the pager.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
/// TODO
|
/// Normal mode. Exploring the file system.
|
||||||
Normal,
|
Normal,
|
||||||
/// TODO
|
/// Rename mode. Renaming a file.
|
||||||
Rename(String),
|
Rename(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mode {
|
impl Mode {
|
||||||
/// TODO
|
/// Returns the new name of the file, if in rename mode.
|
||||||
pub fn new_name(&self) -> Option<&str> {
|
pub fn new_name(&self) -> Option<&str> {
|
||||||
match &self {
|
match &self {
|
||||||
Mode::Rename(new_name) => Some(new_name),
|
Mode::Rename(new_name) => Some(new_name),
|
||||||
|
|
Loading…
Reference in a new issue