Skip to main content

Handoff

Struct Handoff 

Source
pub struct Handoff<Msg> { /* private fields */ }
Expand description

Hands the terminal to another program: leaves raw mode and the alternate screen, runs it attached to the real terminal, then takes the screen back and draws everything again.

The program runs on the drawing thread and the application waits for it, which is what the user expects: they are talking to another program. Background tasks keep running, but nothing is drawn until the program ends.

On Unix, when the application is the foreground of its controlling terminal, the program runs in a process group of its own that is made the terminal’s foreground until it ends, as a shell runs a job. The signals of the keys — Ctrl-C at a sudo prompt, Ctrl-\ — and resizes then reach the program and its children only: the application is never ended by them, and its own signal dispositions are never changed. Ctrl-Z does not suspend: a program that stops is continued at once, since the application offers no way back to it. A process group is not a session, so the program keeps the controlling terminal and the session a warm sudo ticket is kept for.

use qframe::prelude::*;
use qframe::runtime::{Handoff, HandoffOutcome};

enum Msg {
    Authorize,
    Authorized(HandoffOutcome),
}

fn update(msg: Msg) -> Command<Msg> {
    match msg {
        // `sudo -v` asks for the password itself, on the terminal it owns for those seconds.
        Msg::Authorize => Command::handoff(
            Handoff::new("sudo", Msg::Authorized).arg("-v").notice("Authorizing the installation…"),
        ),
        Msg::Authorized(_) => Command::none(),
    }
}

Implementations§

Source§

impl<Msg: Send + 'static> Handoff<Msg>

Source

pub fn new( program: impl Into<OsString>, on_finish: impl FnOnce(HandoffOutcome) -> Msg + Send + 'static, ) -> Self

Runs program, delivering on_finish(outcome) once the application has the screen back.

Source

pub fn arg(self, arg: impl Into<OsString>) -> Self

Adds one argument.

Source

pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self

Adds several arguments, in order.

Source

pub fn dir(self, dir: impl Into<PathBuf>) -> Self

Runs the program in dir instead of the application’s working directory.

Source

pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self

Sets an environment variable for the program. The rest of the environment is inherited.

Source

pub fn notice(self, text: impl Into<String>) -> Self

A line printed on the cleared screen before the program starts, so the user knows why the application stepped aside.

Source

pub fn pause(self, pause: bool) -> Self

Waits for a key press after the program ends, so its last output can be read. Off by default: a program that only takes a moment, such as sudo -v, has nothing to read.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Handoff<Msg>

§

impl<Msg> !Sync for Handoff<Msg>

§

impl<Msg> !UnwindSafe for Handoff<Msg>

§

impl<Msg> Freeze for Handoff<Msg>
where Box<dyn FnOnce(HandoffOutcome) -> Msg + Send>: Freeze,

§

impl<Msg> Send for Handoff<Msg>
where Box<dyn FnOnce(HandoffOutcome) -> Msg + Send>: Send,

§

impl<Msg> Unpin for Handoff<Msg>
where Box<dyn FnOnce(HandoffOutcome) -> Msg + Send>: Unpin,

§

impl<Msg> UnsafeUnpin for Handoff<Msg>
where Box<dyn FnOnce(HandoffOutcome) -> Msg + Send>: UnsafeUnpin,

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, !>

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.