Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yazi-actor/src/pick/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yazi_macro::mod_flat!(arrow close show);
yazi_macro::mod_flat!(arrow close show select);
31 changes: 31 additions & 0 deletions yazi-actor/src/pick/select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use anyhow::Result;
use yazi_macro::{render, succ};
use yazi_parser::pick::SelectOpt;
use yazi_shared::data::Data;

use crate::{Actor, Ctx};

pub struct Select;

impl Actor for Select {
type Options = SelectOpt;

const NAME: &str = "select";

fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> {
let pick = &mut cx.pick;
if opt.index >= pick.items.len() {
succ!();
}

if let Some(cb) = pick.callback.take() {
_ = cb.send(Ok(opt.index));
}

pick.cursor = 0;
pick.offset = 0;
pick.visible = false;

succ!(render!());
}
}
10 changes: 10 additions & 0 deletions yazi-config/preset/keymap-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ keymap = [
{ on = "<Up>", run = "arrow prev", desc = "Previous option" },
{ on = "<Down>", run = "arrow next", desc = "Next option" },

{ on = "1", run = "select 0", desc = "Select first option" },
{ on = "2", run = "select 1", desc = "Select second option" },
{ on = "3", run = "select 2", desc = "Select third option" },
{ on = "4", run = "select 3", desc = "Select fourth option" },
{ on = "5", run = "select 4", desc = "Select fifth option" },
{ on = "6", run = "select 5", desc = "Select sixth option" },
{ on = "7", run = "select 6", desc = "Select seventh option" },
{ on = "8", run = "select 7", desc = "Select eighth option" },
{ on = "9", run = "select 8", desc = "Select ninth option" },

# Help
{ on = "~", run = "help", desc = "Open help" },
{ on = "<F1>", run = "help", desc = "Open help" },
Expand Down
1 change: 1 addition & 0 deletions yazi-config/preset/yazi-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ quit_offset = [ 0, 0, 50, 15 ]
open_title = "Open with:"
open_origin = "hovered"
open_offset = [ 0, 1, 50, 7 ]
line_numbers = true

[which]
sort_by = "none"
Expand Down
7 changes: 4 additions & 3 deletions yazi-config/src/popup/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use super::{Offset, Origin};
#[derive(Deserialize, DeserializeOver2)]
pub struct Pick {
// open
pub open_title: String,
pub open_origin: Origin,
pub open_offset: Offset,
pub open_title: String,
pub open_origin: Origin,
pub open_offset: Offset,
pub line_numbers: bool,
}

impl Pick {
Expand Down
3 changes: 3 additions & 0 deletions yazi-dds/src/spark/spark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum Spark<'a> {
// Pick
PickClose(yazi_parser::pick::CloseOpt),
PickShow(yazi_parser::pick::ShowOpt),
PickSelect(yazi_parser::pick::SelectOpt),

// Spot
SpotCopy(yazi_parser::spot::CopyOpt),
Expand Down Expand Up @@ -224,6 +225,7 @@ impl<'a> IntoLua for Spark<'a> {
// Pick
Self::PickClose(b) => b.into_lua(lua),
Self::PickShow(b) => b.into_lua(lua),
Self::PickSelect(b) => b.into_lua(lua),

// Spot
Self::SpotCopy(b) => b.into_lua(lua),
Expand Down Expand Up @@ -320,6 +322,7 @@ try_from_spark!(mgr::YankOpt, mgr:yank);
try_from_spark!(notify::TickOpt, notify:tick);
try_from_spark!(pick::CloseOpt, pick:close);
try_from_spark!(pick::ShowOpt, pick:show);
try_from_spark!(pick::SelectOpt, pick:select);
try_from_spark!(spot::CopyOpt, spot:copy);
try_from_spark!(tasks::ProcessOpenOpt, tasks:process_open);
try_from_spark!(tasks::UpdateSucceedOpt, tasks:update_succeed);
Expand Down
1 change: 1 addition & 0 deletions yazi-fm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<'a> Executor<'a> {
on!(show);
on!(close);
on!(arrow);
on!(select);

match cmd.name.as_ref() {
// Help
Expand Down
15 changes: 10 additions & 5 deletions yazi-fm/src/pick/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{ListItem, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget}};
use yazi_config::THEME;
use yazi_config::{THEME, YAZI};
use yazi_core::Core;
use yazi_widgets::Scrollable;

Expand Down Expand Up @@ -27,11 +27,16 @@ impl Widget for List<'_> {
// List content
let inner = area.inner(Margin::new(1, 0));
let items = pick.window().map(|(i, v)| {
if i == pick.cursor {
ListItem::new(format!(" {v}")).style(THEME.pick.active)
let (prefix, style) =
if i == pick.cursor { ("", THEME.pick.active) } else { (" ", THEME.pick.inactive) };

let index_str = if !YAZI.pick.line_numbers {
"".to_string()
} else {
ListItem::new(format!(" {v}")).style(THEME.pick.inactive)
}
if i < 9 { format!("{:>2}", i + 1) } else { " ".to_string() }
};

ListItem::new(format!("{prefix}{index_str} {v}")).style(style)
});
Widget::render(ratatui::widgets::List::new(items), inner, buf);
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-parser/src/pick/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yazi_macro::mod_flat!(close show);
yazi_macro::mod_flat!(close show select);
23 changes: 23 additions & 0 deletions yazi-parser/src/pick/select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
use yazi_shared::event::CmdCow;

#[derive(Debug)]
pub struct SelectOpt {
pub index: usize,
}

impl From<CmdCow> for SelectOpt {
fn from(c: CmdCow) -> Self { Self { index: c.first().unwrap_or(0) } }
}

impl From<usize> for SelectOpt {
fn from(index: usize) -> Self { Self { index } }
}

impl FromLua for SelectOpt {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
}

impl IntoLua for SelectOpt {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
}
Loading