This commit is contained in:
sxyazi 2023-11-16 09:14:05 +08:00
parent 75dc1ec8a3
commit 437757f4d6
No known key found for this signature in database
4 changed files with 88 additions and 22 deletions

View file

@ -75,10 +75,9 @@ preload = []
[input]
# cd
cd_title = "Change directory:"
cd_origin = "top-center"
cd_offset = [ 0, 2, 50, 3 ]
cd_completion = 1
cd_title = "Change directory:"
cd_origin = "top-center"
cd_offset = [ 0, 2, 50, 3 ]
# create
create_title = "Create:"
@ -101,10 +100,9 @@ delete_origin = "top-center"
delete_offset = [ 0, 2, 50, 3 ]
# find
find_title = [ "Find previous:", "Find next:" ]
find_origin = "top-center"
find_offset = [ 0, 2, 50, 3 ]
find_realtime = true
find_title = [ "Find next:", "Find previous:" ]
find_origin = "top-center"
find_offset = [ 0, 2, 50, 3 ]
# search
search_title = "Search:"
@ -112,10 +110,9 @@ search_origin = "top-center"
search_offset = [ 0, 2, 50, 3 ]
# shell
shell_title = [ "Shell:", "Shell (block):" ]
shell_origin = "top-center"
shell_offset = [ 0, 2, 50, 3 ]
shell_highlight = true
shell_title = [ "Shell:", "Shell (block):" ]
shell_origin = "top-center"
shell_offset = [ 0, 2, 50, 3 ]
# overwrite
overwrite_title = "Overwrite an existing file? (y/N)"

View file

@ -44,6 +44,11 @@ pub struct Input {
pub shell_title: [String; 2],
pub shell_origin: Origin,
pub shell_offset: Offset,
// overwrite
pub overwrite_title: String,
pub overwrite_origin: Origin,
pub overwrite_offset: Offset,
}
impl Default for Input {

View file

@ -1,5 +1,7 @@
use super::Position;
use crate::INPUT;
#[derive(Default)]
pub struct InputOpt {
pub title: String,
pub value: String,
@ -9,6 +11,7 @@ pub struct InputOpt {
pub highlight: bool,
}
#[derive(Default)]
pub struct SelectOpt {
pub title: String,
pub items: Vec<String>,
@ -17,32 +20,90 @@ pub struct SelectOpt {
impl InputOpt {
#[inline]
pub fn cd() -> Self { todo!() }
pub fn cd() -> Self {
Self {
title: INPUT.cd_title.to_owned(),
position: Position::new(INPUT.cd_origin, INPUT.cd_offset),
completion: true,
..Default::default()
}
}
#[inline]
pub fn create() -> Self { todo!() }
pub fn create() -> Self {
Self {
title: INPUT.create_title.to_owned(),
position: Position::new(INPUT.create_origin, INPUT.create_offset),
..Default::default()
}
}
#[inline]
pub fn rename() -> Self { todo!() }
pub fn rename() -> Self {
Self {
title: INPUT.rename_title.to_owned(),
position: Position::new(INPUT.rename_origin, INPUT.rename_offset),
..Default::default()
}
}
#[inline]
pub fn trash(n: usize) -> Self { todo!() }
pub fn trash(n: usize) -> Self {
let title = INPUT.trash_title.replace("{n}", &n.to_string());
Self {
title: title.replace("{s}", if n > 1 { "s" } else { "" }),
position: Position::new(INPUT.trash_origin, INPUT.trash_offset),
..Default::default()
}
}
#[inline]
pub fn delete(n: usize) -> Self { todo!() }
pub fn delete(n: usize) -> Self {
let title = INPUT.delete_title.replace("{n}", &n.to_string());
Self {
title: title.replace("{s}", if n > 1 { "s" } else { "" }),
position: Position::new(INPUT.delete_origin, INPUT.delete_offset),
..Default::default()
}
}
#[inline]
pub fn find(prev: bool) -> Self { todo!() }
pub fn find(prev: bool) -> Self {
Self {
title: INPUT.find_title[prev as usize].to_owned(),
position: Position::new(INPUT.find_origin, INPUT.find_offset),
realtime: true,
..Default::default()
}
}
#[inline]
pub fn search() -> Self { todo!() }
pub fn search() -> Self {
Self {
title: INPUT.search_title.to_owned(),
position: Position::new(INPUT.search_origin, INPUT.search_offset),
..Default::default()
}
}
#[inline]
pub fn shell(block: bool) -> Self { todo!() }
pub fn shell(block: bool) -> Self {
Self {
title: INPUT.shell_title[block as usize].to_owned(),
position: Position::new(INPUT.shell_origin, INPUT.shell_offset),
highlight: true,
..Default::default()
}
}
#[inline]
pub fn overwrite() -> Self { todo!() }
pub fn overwrite() -> Self {
Self {
title: INPUT.overwrite_title.to_owned(),
position: Position::new(INPUT.overwrite_origin, INPUT.overwrite_offset),
..Default::default()
}
}
#[inline]
pub fn with_value(mut self, value: impl Into<String>) -> Self {

View file

@ -11,6 +11,9 @@ pub struct Position {
}
impl Position {
#[inline]
pub fn new(origin: Origin, offset: Offset) -> Self { Self { origin, offset } }
pub fn rect(&self) -> Rect {
let Offset { x, y, width, height } = self.offset;
let WindowSize { columns, rows, .. } = Term::size();