mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor(input): COW ID as first field
This commit is contained in:
parent
34c6ec887d
commit
b6ee279c2d
4 changed files with 16 additions and 16 deletions
|
|
@ -1,11 +1,12 @@
|
|||
use ratatui::{text::{Line, Text}, widgets::{Paragraph, Wrap}};
|
||||
use yazi_shared::{scheme::Encode as EncodeScheme, strand::ToStrand, url::{Url, UrlBuf}};
|
||||
use yazi_shared::{SStr, scheme::Encode as EncodeScheme, strand::ToStrand, url::{Url, UrlBuf}};
|
||||
|
||||
use super::{Offset, Position};
|
||||
use crate::{YAZI, popup::Origin};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct InputCfg {
|
||||
pub id: SStr,
|
||||
pub title: String,
|
||||
pub value: String,
|
||||
pub cursor: Option<usize>,
|
||||
|
|
@ -13,7 +14,6 @@ pub struct InputCfg {
|
|||
pub position: Position,
|
||||
pub realtime: bool,
|
||||
pub completion: bool,
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
|
@ -34,39 +34,39 @@ pub struct ConfirmCfg {
|
|||
impl InputCfg {
|
||||
pub fn cd(cwd: Url) -> Self {
|
||||
Self {
|
||||
id: "cd".into(),
|
||||
title: YAZI.input.cd_title.clone(),
|
||||
value: if cwd.kind().is_local() { String::new() } else { EncodeScheme(cwd).to_string() },
|
||||
position: Position::new(YAZI.input.cd_origin, YAZI.input.cd_offset),
|
||||
completion: true,
|
||||
id: "cd".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create(dir: bool) -> Self {
|
||||
Self {
|
||||
id: "create".into(),
|
||||
title: YAZI.input.create_title[dir as usize].clone(),
|
||||
position: Position::new(YAZI.input.create_origin, YAZI.input.create_offset),
|
||||
id: "create".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename() -> Self {
|
||||
Self {
|
||||
id: "rename".into(),
|
||||
title: YAZI.input.rename_title.clone(),
|
||||
position: Position::new(YAZI.input.rename_origin, YAZI.input.rename_offset),
|
||||
id: "rename".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter() -> Self {
|
||||
Self {
|
||||
id: "filter".into(),
|
||||
title: YAZI.input.filter_title.clone(),
|
||||
position: Position::new(YAZI.input.filter_origin, YAZI.input.filter_offset),
|
||||
realtime: true,
|
||||
id: "filter".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -83,23 +83,24 @@ impl InputCfg {
|
|||
pub fn search(name: &str) -> Self {
|
||||
Self {
|
||||
title: YAZI.input.search_title.replace("{n}", name),
|
||||
id: "search".into(),
|
||||
position: Position::new(YAZI.input.search_origin, YAZI.input.search_offset),
|
||||
id: "search".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shell(block: bool) -> Self {
|
||||
Self {
|
||||
id: "shell".into(),
|
||||
title: YAZI.input.shell_title[block as usize].clone(),
|
||||
position: Position::new(YAZI.input.shell_origin, YAZI.input.shell_offset),
|
||||
id: "shell".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tab_rename() -> Self {
|
||||
Self {
|
||||
id: "tab_rename".into(),
|
||||
title: "Rename tab:".to_owned(),
|
||||
position: Position::new(Origin::TopCenter, Offset {
|
||||
x: 0,
|
||||
|
|
@ -107,7 +108,6 @@ impl InputCfg {
|
|||
width: 50,
|
||||
height: 3,
|
||||
}),
|
||||
id: "tab_rename".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ use std::ops::{Deref, DerefMut};
|
|||
use anyhow::Result;
|
||||
use yazi_config::popup::Position;
|
||||
use yazi_macro::{render, succ};
|
||||
use yazi_shared::{data::Data, event::ActionCow};
|
||||
use yazi_shared::{data::Data, event::ActionCow, SStr};
|
||||
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Input {
|
||||
pub(super) inner: yazi_widgets::input::Input,
|
||||
pub history: std::collections::HashMap<String, yazi_widgets::input::InputHistory>,
|
||||
pub history: std::collections::HashMap<SStr, yazi_widgets::input::InputHistory>,
|
||||
|
||||
pub visible: bool,
|
||||
pub title: String,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use mlua::{ExternalError, ExternalResult, Function, IntoLuaMulti, Lua, Table, Value};
|
||||
use mlua::{ExternalError, ExternalResult, Function, IntoLuaMulti, Lua, Table, Value, prelude::LuaError};
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
use yazi_binding::{InputRx, elements::{Line, Pos, Text}, runtime};
|
||||
use yazi_config::{Platform, keymap::{Chord, ChordCow, Key}, popup::{ConfirmCfg, InputCfg}};
|
||||
|
|
@ -52,6 +52,7 @@ impl Utils {
|
|||
|
||||
let realtime = t.raw_get("realtime")?;
|
||||
let rx = UnboundedReceiverStream::new(InputProxy::show(InputCfg {
|
||||
id: (t.raw_get("id") as Result<String, LuaError>).unwrap_or_default().into(),
|
||||
title: t.raw_get("title")?,
|
||||
value: t.raw_get("value").unwrap_or_default(),
|
||||
cursor: None, // TODO
|
||||
|
|
@ -59,7 +60,6 @@ impl Utils {
|
|||
position: t.raw_get::<Pos>("pos")?.with_height(3).into(),
|
||||
realtime,
|
||||
completion: false,
|
||||
id: t.raw_get("id").unwrap_or_default(),
|
||||
}));
|
||||
|
||||
if !realtime {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crossterm::cursor::SetCursorStyle;
|
|||
use tokio::sync::mpsc;
|
||||
use yazi_config::YAZI;
|
||||
use yazi_macro::act;
|
||||
use yazi_shared::Ids;
|
||||
use yazi_shared::{Ids, SStr};
|
||||
use yazi_shim::path::CROSS_SEPARATOR;
|
||||
|
||||
use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp};
|
||||
|
|
@ -13,12 +13,12 @@ use crate::{CLIPBOARD, input::{InputEvent, InputOpt}};
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct Input {
|
||||
pub id: SStr,
|
||||
pub snaps: InputSnaps,
|
||||
pub limit: usize,
|
||||
pub obscure: bool,
|
||||
pub realtime: bool,
|
||||
pub completion: bool,
|
||||
pub id: String,
|
||||
|
||||
pub tx: Option<mpsc::UnboundedSender<InputEvent>>,
|
||||
pub ticket: Ids,
|
||||
|
|
@ -28,12 +28,12 @@ impl Input {
|
|||
pub fn new(opt: InputOpt) -> Result<Self> {
|
||||
let limit = opt.cfg.position.offset.width.saturating_sub(YAZI.input.border()) as usize;
|
||||
let mut input = Self {
|
||||
id: opt.cfg.id,
|
||||
snaps: InputSnaps::new(opt.cfg.value, opt.cfg.obscure, limit),
|
||||
limit,
|
||||
obscure: opt.cfg.obscure,
|
||||
realtime: opt.cfg.realtime,
|
||||
completion: opt.cfg.completion,
|
||||
id: opt.cfg.id,
|
||||
|
||||
tx: Some(opt.tx),
|
||||
..Default::default()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue