mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: improve search input title (#559)
This commit is contained in:
parent
e1d7f79191
commit
acb8b47eee
3 changed files with 31 additions and 15 deletions
|
|
@ -156,7 +156,7 @@ find_origin = "top-center"
|
||||||
find_offset = [ 0, 2, 50, 3 ]
|
find_offset = [ 0, 2, 50, 3 ]
|
||||||
|
|
||||||
# search
|
# search
|
||||||
search_title = "Search:"
|
search_title = "Search via {n}:"
|
||||||
search_origin = "top-center"
|
search_origin = "top-center"
|
||||||
search_offset = [ 0, 2, 50, 3 ]
|
search_offset = [ 0, 2, 50, 3 ]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,9 @@ impl InputCfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn search() -> Self {
|
pub fn search(name: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: INPUT.search_title.to_owned(),
|
title: INPUT.search_title.replace("{n}", name),
|
||||||
position: Position::new(INPUT.search_origin, INPUT.search_offset),
|
position: Position::new(INPUT.search_origin, INPUT.search_offset),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@ use yazi_shared::{event::Exec, fs::FilesOp, render};
|
||||||
|
|
||||||
use crate::{input::Input, manager::Manager, tab::Tab};
|
use crate::{input::Input, manager::Manager, tab::Tab};
|
||||||
|
|
||||||
pub struct Opt {
|
|
||||||
pub type_: OptType,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub enum OptType {
|
pub enum OptType {
|
||||||
None,
|
None,
|
||||||
|
|
@ -20,15 +16,34 @@ pub enum OptType {
|
||||||
Fd,
|
Fd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&str> for OptType {
|
||||||
|
fn from(value: &str) -> Self {
|
||||||
|
match value {
|
||||||
|
"rg" => Self::Rg,
|
||||||
|
"fd" => Self::Fd,
|
||||||
|
_ => Self::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for OptType {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Rg => "rg",
|
||||||
|
Self::Fd => "fd",
|
||||||
|
Self::None => "none",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Opt {
|
||||||
|
pub type_: OptType,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&Exec> for Opt {
|
impl From<&Exec> for Opt {
|
||||||
fn from(e: &Exec) -> Self {
|
fn from(e: &Exec) -> Self {
|
||||||
Self {
|
Self { type_: e.args.first().map(|s| s.as_str()).unwrap_or_default().into() }
|
||||||
type_: match e.args.first().map(|s| s.as_str()) {
|
|
||||||
Some("fd") => OptType::Fd,
|
|
||||||
Some("rg") => OptType::Rg,
|
|
||||||
_ => OptType::None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +62,8 @@ impl Tab {
|
||||||
let hidden = self.conf.show_hidden;
|
let hidden = self.conf.show_hidden;
|
||||||
|
|
||||||
self.search = Some(tokio::spawn(async move {
|
self.search = Some(tokio::spawn(async move {
|
||||||
let Some(Ok(subject)) = Input::_show(InputCfg::search()).recv().await else { bail!("") };
|
let mut input = Input::_show(InputCfg::search(&opt.type_.to_string()));
|
||||||
|
let Some(Ok(subject)) = input.recv().await else { bail!("") };
|
||||||
|
|
||||||
cwd = cwd.into_search(subject.clone());
|
cwd = cwd.into_search(subject.clone());
|
||||||
let rx = if opt.type_ == OptType::Rg {
|
let rx = if opt.type_ == OptType::Rg {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue