Skip to main content

App

Struct App 

Source
pub struct App {
Show 17 fields pub mode: Mode, pub list_source: ListSource, pub query: String, pub results: Vec<Video>, pub history: History, pub selected: usize, pub queue: Vec<Video>, pub playlist_pos: Option<i64>, pub now_playing: Option<Video>, pub position: Option<f64>, pub duration_secs: Option<f64>, pub paused: bool, pub video_enabled: bool, pub status: String, pub should_quit: bool, pub mpv: Mpv, pub search_rx: UnboundedReceiver<Video>, /* private fields */
}
Expand description

All state needed to drive the TUI: what’s on screen, what’s playing, and the handle to the single long-lived mpv process.

Fields§

§mode: Mode

Whether the search box or the list is currently focused.

§list_source: ListSource

Which list (App::results or App::history) is being shown.

§query: String

Current contents of the search box.

§results: Vec<Video>

Results of the most recent search, filled in incrementally as yt-dlp streams them back.

§history: History

Persisted history of played/queued videos, loaded on startup and saved back to disk after every selection.

§selected: usize

Index of the highlighted item in the currently active list.

§queue: Vec<Video>

Videos sent to mpv so far, in the order mpv’s own playlist should have them (mirrors mpv’s internal playlist).

§playlist_pos: Option<i64>

mpv’s current playlist-pos, polled every tick; None before the first successful poll.

§now_playing: Option<Video>

The video mpv is currently on, if any.

§position: Option<f64>

Current playback position in seconds, polled from mpv every tick.

§duration_secs: Option<f64>

Duration of the current track in seconds, polled from mpv every tick.

§paused: bool

Whether mpv is currently paused.

§video_enabled: bool

Whether the video track is currently enabled (vs. audio-only).

§status: String

Free-form message shown in the status bar.

§should_quit: bool

Set to true to make the main loop exit on the next iteration.

§mpv: Mpv

The single, long-lived mpv instance this app controls.

§search_rx: UnboundedReceiver<Video>

Receiving end of the channel yt-dlp search results stream over; drained into App::results by App::drain_search_results.

Implementations§

Source§

impl App

Source

pub async fn new() -> Result<Self>

Loads the saved history and spawns the single mpv instance used for the lifetime of the app. Fails only if mpv itself can’t start (see crate::mpv::Mpv::spawn).

Source

pub fn drain_search_results(&mut self)

Drains the search channel; called on every turn of the main loop.

Kicks off a new search for App::query in the background, clearing any previous results and switching to ListSource::Search. Does nothing if the query is blank.

Source

pub fn toggle_history_view(&mut self)

Toggles between viewing the last search’s results and the saved history, without needing to search YouTube again.

Source

pub fn move_selection(&mut self, delta: i32)

Moves the selection cursor in the active list by delta, clamped to the list’s bounds. Negative values move up.

Source

pub async fn enqueue_selected(&mut self)

Enter/‘a’: joins mpv’s queue (append-play) without interrupting whatever’s already playing; if mpv is idle, starts playing right away. This is the default behavior when selecting a video.

Source

pub async fn replace_selected(&mut self)

‘r’: plays now, replacing mpv’s entire playlist (clears the queue).

Source

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

Clears the entire queue and stops playback.

Source

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

Toggles play/pause on the currently loaded track.

Source

pub async fn seek(&mut self, seconds: f64) -> Result<()>

Seeks by seconds relative to the current position (negative seeks backward).

Source

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

Skips to the next track in mpv’s playlist, if any.

Source

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

Skips to the previous track in mpv’s playlist, if any.

Source

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

Toggles video on/off at runtime (without reopening mpv or the stream) — works because the format resolved by mpv’s hook already includes the video track by default; this just enables/disables it.

Source

pub async fn refresh_progress(&mut self)

Called on every tick of the main loop to keep position, duration, playlist index, and pause state synced with the real mpv (via get_property over the IPC socket).

Auto Trait Implementations§

§

impl !RefUnwindSafe for App

§

impl !UnwindSafe for App

§

impl Freeze for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

Blanket Implementations§

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> 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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, <T as TryFrom<U>>::Error>

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.