mirror of
https://github.com/lotabout/skim.git
synced 2026-09-10 07:16:23 -04:00
feat: add set-preview-cmd action to change preview (#969)
* feat: add set-preview-cmd action to change preview * chore: update manpage * chore: generate completions & manpage --------- Co-authored-by: Skim bot <skim-bot@skim-rs.github.io>
This commit is contained in:
parent
de7eab7619
commit
98a9184055
|
|
@ -778,6 +778,8 @@ Actions can take arguments, specified either between parentheses `reload(ls)` or
|
|||
.br
|
||||
* select\-row
|
||||
.br
|
||||
* set\-preview\-cmd(...): *arg will be a expanded expression, see COMMAND EXPANSION for details
|
||||
.br
|
||||
* set\-query(...): *arg will be a expanded expression, see COMMAND EXPANSION for details
|
||||
.br
|
||||
* toggle
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use clap::CommandFactory;
|
|||
use crate::SkimOptions;
|
||||
|
||||
/// Available shells for completion generation
|
||||
#[derive(Clone, clap::ValueEnum, PartialEq)]
|
||||
#[derive(Clone, clap::ValueEnum, PartialEq, Debug)]
|
||||
pub enum Shell {
|
||||
/// Bourne Again SHell
|
||||
Bash,
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ const ACTIONS_SS: &str = "
|
|||
* reload(...)
|
||||
* select-all
|
||||
* select-row
|
||||
* set-preview-cmd(...): *arg will be a expanded expression, see COMMAND EXPANSION for details
|
||||
* set-query(...): *arg will be a expanded expression, see COMMAND EXPANSION for details
|
||||
* toggle
|
||||
* toggle-all
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ fn parse_delimiter_value(s: &str) -> Result<Regex, String> {
|
|||
feature = "cli",
|
||||
command(name = "sk", args_override_self = true, verbatim_doc_comment, version, about)
|
||||
)]
|
||||
#[derive(derive_more::Debug)]
|
||||
pub struct SkimOptions {
|
||||
// --- Search ---
|
||||
/// Show results in reverse order
|
||||
|
|
@ -470,6 +471,7 @@ pub struct SkimOptions {
|
|||
feature = "cli",
|
||||
arg(long, default_missing_value = "plain", help_heading = "Display", num_args=0..)
|
||||
)]
|
||||
#[debug(skip)]
|
||||
pub border: Option<BorderType>,
|
||||
|
||||
/// Wrap items in the item list
|
||||
|
|
@ -867,6 +869,7 @@ pub struct SkimOptions {
|
|||
/// Command collector for reading items from commands
|
||||
#[cfg_attr(feature = "cli", clap(skip = Rc::new(RefCell::new(SkimItemReader::default())) as Rc<RefCell<dyn CommandCollector>>))]
|
||||
#[builder(setter(into = false))]
|
||||
#[debug(skip)]
|
||||
pub cmd_collector: Rc<RefCell<dyn CommandCollector>>,
|
||||
/// Query history entries loaded from history file
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
|
|
@ -877,6 +880,7 @@ pub struct SkimOptions {
|
|||
/// Selector for pre-selecting items
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
#[builder(setter(into = false))]
|
||||
#[debug(skip)]
|
||||
pub selector: Option<Rc<dyn Selector>>,
|
||||
/// Preview Callback
|
||||
///
|
||||
|
|
@ -885,6 +889,7 @@ pub struct SkimOptions {
|
|||
/// The function will take a `Vec<Arc<dyn SkimItem>>>` containing the currently selected items
|
||||
/// and return a Vec<String> with the lines to display in UTF-8
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
#[debug(skip)]
|
||||
pub preview_fn: Option<PreviewCallback>,
|
||||
|
||||
/// The internal (parsed) keymap
|
||||
|
|
|
|||
|
|
@ -1044,6 +1044,10 @@ impl App {
|
|||
self.item_list.select();
|
||||
return self.on_selection_changed();
|
||||
}
|
||||
SetPreviewCmd(cmd) => {
|
||||
self.options.preview = Some(cmd.to_owned());
|
||||
return Ok(vec![Event::RunPreview]);
|
||||
}
|
||||
SetQuery(value) => {
|
||||
self.input.value = self.expand_cmd(value, false);
|
||||
self.input.move_to_end();
|
||||
|
|
|
|||
|
|
@ -190,6 +190,8 @@ pub enum Action {
|
|||
SelectRow(usize),
|
||||
/// Select current item
|
||||
Select,
|
||||
/// Set the preview cmd and rerun preview
|
||||
SetPreviewCmd(String),
|
||||
/// Set the query to the expanded value
|
||||
SetQuery(String),
|
||||
/// Toggle selection of current item
|
||||
|
|
@ -326,6 +328,7 @@ pub fn parse_action(raw_action: &str) -> Option<Action> {
|
|||
"select" => Some(Select),
|
||||
"select-all" => Some(SelectAll),
|
||||
"select-row" => Some(SelectRow(arg.and_then(|s| s.parse().ok()).unwrap_or_default())),
|
||||
"set-preview-cmd" => Some(SetPreviewCmd(arg.expect("set-preview-cmd action needs a value"))),
|
||||
"set-query" => Some(SetQuery(arg.expect("set-query action needs a value"))),
|
||||
"toggle" => Some(Toggle),
|
||||
"toggle-all" => Some(ToggleAll),
|
||||
|
|
|
|||
|
|
@ -97,3 +97,11 @@ insta_test!(bind_toggle_interactive_queries, @interactive, &["--bind", "ctrl-a:t
|
|||
@ctrl 'a';
|
||||
@snap;
|
||||
});
|
||||
|
||||
insta_test!(bind_set_preview_cmd, ["a", "b", "c"], &["--preview", "echo initial {}", "--bind", "ctrl-a:set-preview-cmd(echo new {})"], {
|
||||
@snap;
|
||||
@ctrl 'a';
|
||||
@snap;
|
||||
@key Up;
|
||||
@snap;
|
||||
});
|
||||
|
|
|
|||
30
tests/snapshots/binds__bind_set_preview_cmd-2.snap
Normal file
30
tests/snapshots/binds__bind_set_preview_cmd-2.snap
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
source: tests/binds.rs
|
||||
assertion_line: 101
|
||||
expression: buf + & cursor_pos
|
||||
---
|
||||
" │new a "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" c │ "
|
||||
" b │ "
|
||||
"> a │ "
|
||||
" 3/3 0/0│ "
|
||||
"> │ "
|
||||
cursor: (24, 3)
|
||||
30
tests/snapshots/binds__bind_set_preview_cmd-3.snap
Normal file
30
tests/snapshots/binds__bind_set_preview_cmd-3.snap
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
source: tests/binds.rs
|
||||
assertion_line: 101
|
||||
expression: buf + & cursor_pos
|
||||
---
|
||||
" │new b "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" c │ "
|
||||
"> b │ "
|
||||
" a │ "
|
||||
" 3/3 1/0│ "
|
||||
"> │ "
|
||||
cursor: (24, 3)
|
||||
30
tests/snapshots/binds__bind_set_preview_cmd.snap
Normal file
30
tests/snapshots/binds__bind_set_preview_cmd.snap
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
source: tests/binds.rs
|
||||
assertion_line: 101
|
||||
expression: buf + & cursor_pos
|
||||
---
|
||||
" │initial a "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" │ "
|
||||
" c │ "
|
||||
" b │ "
|
||||
"> a │ "
|
||||
" 3/3 0/0│ "
|
||||
"> │ "
|
||||
cursor: (24, 3)
|
||||
Loading…
Reference in a new issue