mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
WIP [no ci]
This commit is contained in:
parent
208baffddd
commit
530f8ca317
3 changed files with 41 additions and 8 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
|
use tokio::fs;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||||
|
|
||||||
use crate::completion::Completion;
|
use crate::{completion::Completion, emit};
|
||||||
|
|
||||||
pub struct Opt<'a> {
|
pub struct Opt<'a> {
|
||||||
word: &'a str,
|
word: &'a str,
|
||||||
|
|
@ -11,7 +12,7 @@ pub struct Opt<'a> {
|
||||||
impl<'a> From<&'a Exec> for Opt<'a> {
|
impl<'a> From<&'a Exec> for Opt<'a> {
|
||||||
fn from(e: &'a Exec) -> Self {
|
fn from(e: &'a Exec) -> Self {
|
||||||
Self {
|
Self {
|
||||||
word: e.args.get(0).map(|w| w.as_str()).unwrap_or_default(),
|
word: e.args.first().map(|w| w.as_str()).unwrap_or_default(),
|
||||||
ticket: e.named.get("ticket").and_then(|v| v.parse().ok()).unwrap_or(0),
|
ticket: e.named.get("ticket").and_then(|v| v.parse().ok()).unwrap_or(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,8 +28,34 @@ impl Completion {
|
||||||
self.close(false);
|
self.close(false);
|
||||||
self.ticket = opt.ticket;
|
self.ticket = opt.ticket;
|
||||||
|
|
||||||
info!("trigger completion: {}", opt.word);
|
let word = opt.word.to_owned();
|
||||||
tokio::spawn(async move {});
|
let ticket = self.ticket;
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let (parent, child) = word.rsplit_once('/').unwrap_or((".", word.as_str()));
|
||||||
|
|
||||||
|
let mut dir = fs::read_dir(parent).await?;
|
||||||
|
let mut cands = Vec::new();
|
||||||
|
while let Ok(Some(f)) = dir.next_entry().await {
|
||||||
|
let name = f.file_name().to_string_lossy().into_owned();
|
||||||
|
if !name.starts_with(child) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cands.push(name);
|
||||||
|
if cands.len() >= 20 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cands.is_empty() {
|
||||||
|
emit!(Call(
|
||||||
|
Exec::call("show", cands).with("ticket", ticket).vec(),
|
||||||
|
KeymapLayer::Completion
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok::<(), anyhow::Error>(())
|
||||||
|
});
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Cell, Clear, Row, Table, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Cell, Clear, List, ListItem, Row, Table, Widget}};
|
||||||
use yazi_core::Ctx;
|
use yazi_core::Ctx;
|
||||||
|
|
||||||
pub(crate) struct Completion<'a> {
|
pub(crate) struct Completion<'a> {
|
||||||
|
|
@ -11,7 +11,13 @@ impl<'a> Completion<'a> {
|
||||||
|
|
||||||
impl<'a> Widget for Completion<'a> {
|
impl<'a> Widget for Completion<'a> {
|
||||||
fn render(self, _: Rect, buf: &mut Buffer) {
|
fn render(self, _: Rect, buf: &mut Buffer) {
|
||||||
todo!()
|
let items =
|
||||||
|
self.cx.completion.items.iter().map(|x| ListItem::new(x.as_str())).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
Clear.render(Rect { x: 10, y: 10, width: 10, height: 20 }, buf);
|
||||||
|
List::new(items).render(Rect { x: 10, y: 10, width: 10, height: 20 }, buf);
|
||||||
|
|
||||||
// let completion = &self.cx.input.completion;
|
// let completion = &self.cx.input.completion;
|
||||||
// let area = self.cx.area(&completion.position);
|
// let area = self.cx.area(&completion.position);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ impl Executor {
|
||||||
"close" => cx.completion.close(exec.named.contains_key("submit")),
|
"close" => cx.completion.close(exec.named.contains_key("submit")),
|
||||||
|
|
||||||
"arrow" => {
|
"arrow" => {
|
||||||
let step: isize = exec.args.get(0).and_then(|s| s.parse().ok()).unwrap_or(0);
|
let step: isize = exec.args.first().and_then(|s| s.parse().ok()).unwrap_or(0);
|
||||||
if step > 0 {
|
if step > 0 {
|
||||||
cx.completion.next(step as usize)
|
cx.completion.next(step as usize)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue