Skip to main content

Skim

Struct Skim 

Source
pub struct Skim<Backend = CrosstermBackend<BufWriter<Stderr>>>
where Backend: Backend, Backend::Error: Send + Sync + 'static,
{ /* private fields */ }
Expand description

Main entry point for running skim

Implementations§

Source§

impl Skim

Source

pub fn run_with( options: SkimOptions, source: Option<SkimItemReceiver>, ) -> Result<SkimOutput>

Run skim, collecting items from the source and using options

§Params
  • options: the “complex” options that control how skim behaves
  • source: a stream of items to be passed to skim for filtering. If None is given, skim will invoke the command given to fetch the items.
§Returns
  • None: on internal errors.
  • SkimOutput: the collected key, event, query, selected items, etc.
§Errors

Returns an error if skim initialization or the TUI loop fails.

§Panics

Panics if the tui fails to initialize

Source

pub fn run_items<I, T>(options: SkimOptions, items: I) -> Result<SkimOutput>
where I: IntoIterator<Item = T>, T: SkimItem,

Run skim with a Vec of items

§Errors

Returns an error if sending items to the channel or running skim fails.

use skim::prelude::*;

let opts = SkimOptionsBuilder::default().multi(true).build().unwrap();
Skim::run_items(opts, ["foo", "bar"]);
Source

pub fn init_tui(&mut self) -> Result<()>

Initialize the TUI with the default crossterm backend, but do not enter it yet

§Errors

Returns an error if the TUI backend cannot be initialized.

Source

pub fn new( options: SkimOptions, source: Option<SkimItemReceiver>, ) -> Result<Self>

Initialize and start skim without entering the terminal UI.

§Errors

Returns an error if skim or the TUI backend cannot be initialized.

Source

pub fn new_items<I, T>(options: SkimOptions, items: I) -> Result<Self>
where I: IntoIterator<Item = T>, T: SkimItem,

Initialize and start skim with items without entering the terminal UI.

§Errors

Returns an error if sending items or initializing skim or its TUI fails.

Source§

impl<Backend: Backend + 'static> Skim<Backend>
where Backend::Error: Send + Sync + 'static,

Source

pub fn init( options: SkimOptions, source: Option<SkimItemReceiver>, ) -> Result<Self>

Initialize skim, without starting anything yet

§Errors

Returns an error if parsing the height or other options fails.

Source

pub fn start(&mut self)

Start the reader and matcher, but do not enter the TUI yet

Source

pub fn handle_reload(&mut self, new_cmd: &str)

Handle a reload event by killing the current reader, clearing items, and starting a new reader.

This encapsulates the reload logic from the main event loop so it can be reused by test harnesses without reimplementing it.

Source

pub fn check_reader(&mut self) -> bool

Check if the reader has finished and restart the matcher if needed.

This encapsulates the reader-status check from the main event loop so it can be reused by test harnesses.

Returns true if the reader has completed.

Source

pub fn reader_done(&self) -> bool

Returns true if the reader is done (has finished producing items).

Source

pub fn matcher_stopped(&self) -> bool

Returns true if the matcher is stopped

Source

pub fn init_tui_with(&mut self, tui: Tui<Backend>)

Initialize the TUI with a caller-provided instance.

Use this instead of init_tui() when you need a non-default backend (e.g. TestBackend for snapshot tests).

Source

pub fn app(&self) -> &App

Returns a shared reference to the application state.

Source

pub fn app_mut(&mut self) -> &mut App

Returns a mutable reference to the application state.

Source

pub fn tui_ref(&self) -> &Tui<Backend>

Returns a shared reference to the TUI.

§Panics

Panics if the TUI has not been initialized yet.

Source

pub fn tui_mut(&mut self) -> &mut Tui<Backend>

Returns a mutable reference to the TUI.

§Panics

Panics if the TUI has not been initialized yet.

Source

pub fn app_and_tui(&mut self) -> (&mut App, &mut Tui<Backend>)

Returns mutable references to both the app and the TUI simultaneously.

This is useful when you need to call app.handle_event(tui, ...) or tui.draw(|frame| frame.render_widget(app, ...)), which require disjoint mutable borrows of both fields.

§Panics

Panics if the TUI has not been initialized yet.

Source

pub fn final_event(&self) -> &Event

Returns a shared reference to the final event that caused skim to quit.

Source

pub fn event_sender(&self) -> Sender<Event>

Returns a clone of the TUI event sender.

Use this to send events (e.g. Event::Render, Event::Action) to the running skim instance from outside the event loop. The sender is cheap to clone and can be moved into async blocks or other tasks.

Must be called after init_tui().

§Panics

Panics if init_tui has not been called before this method.

Source

pub async fn enter(&mut self) -> Result<()>

Enter the TUI

§Errors

Returns an error if the TUI cannot be entered or the input listener fails.

§Panics

Panics if init_tui has not been called before this method.

§Async

This will call init_listener, which requires a tokio runtime Though it is not technically async code, this is a good hint.

Source

pub fn should_enter(&mut self) -> bool

Checks read-0 select-1, filter, and sync to wait and returns whether or not we should enter

§Panics

Panics if start has not been called before this method.

Source

pub fn output(self) -> SkimOutput

Capture self and extract the output This will perform cleanup

§Panics

Panics if the selected items or current item cannot be retrieved.

Source

pub fn should_quit(&self) -> bool

Returns true if skim has finished (the user accepted or aborted)

Source

pub async fn tick(&mut self) -> Result<bool>

Process a single event loop iteration.

This awaits the next event from the TUI, matcher, or IPC listener, processes it, and returns. Use this in your own event loop when you need fine-grained control over the application lifecycle.

Returns Ok(true) if skim should quit, Ok(false) to continue.

§Errors

Returns an error if the TUI cannot produce the next event or if event handling fails.

§Panics

Panics if init_tui has not been called before this method.

§Example
ⓘ
while !skim.tick().await? {
    // do your own work between ticks
}
Source

pub async fn run(&mut self) -> Result<()>

Run the event loop on the current task until skim quits.

This is a convenience wrapper around tick() that loops until the user accepts or aborts. Use tick() directly if you need to interleave your own logic between iterations.

§Errors

Returns an error if any tick in the event loop fails.

Source

pub async fn run_until<F: Future + 'static>( self, user_task: F, ) -> Result<SkimOutput>

Spawn the event loop and run a user-provided future concurrently.

This consumes self, spawns the event loop as a local task, and runs user_task alongside it. When the user accepts or aborts in the TUI, the event loop completes and the SkimOutput is returned — regardless of whether user_task has finished.

Use this when you need to send items or do other work concurrently while the TUI is running.

§Errors

Returns an error if the event loop or the task join fails.

§Example
ⓘ
let output = skim.run_until(async {
    for i in 1..=10 {
        tx.send(vec![Arc::new(format!("item {i}"))]);
        tokio::time::sleep(Duration::from_millis(100)).await;
    }
}).await?;

Auto Trait Implementations§

§

impl<Backend = CrosstermBackend<BufWriter<Stderr>>> !Freeze for Skim<Backend>

§

impl<Backend = CrosstermBackend<BufWriter<Stderr>>> !RefUnwindSafe for Skim<Backend>

§

impl<Backend = CrosstermBackend<BufWriter<Stderr>>> !Send for Skim<Backend>

§

impl<Backend = CrosstermBackend<BufWriter<Stderr>>> !Sync for Skim<Backend>

§

impl<Backend = CrosstermBackend<BufWriter<Stderr>>> !UnwindSafe for Skim<Backend>

§

impl<Backend> Unpin for Skim<Backend>
where Option<Tui<Backend>>: Unpin,

§

impl<Backend> UnsafeUnpin for Skim<Backend>
where Option<Tui<Backend>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the value as Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns a mutable reference to the value as Any
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> QuoteExt for T
where T: ?Sized,

Source§

fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)
where Q: QuoteInto<T>, S: Into<Quotable<'q>>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V