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>
impl<Msg: Send + 'static> Handoff<Msg>
Sourcepub fn new(
program: impl Into<OsString>,
on_finish: impl FnOnce(HandoffOutcome) -> Msg + Send + 'static,
) -> Self
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.
Sourcepub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self
pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self
Adds several arguments, in order.
Sourcepub fn dir(self, dir: impl Into<PathBuf>) -> Self
pub fn dir(self, dir: impl Into<PathBuf>) -> Self
Runs the program in dir instead of the application’s working directory.
Sourcepub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self
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.
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>
impl<Msg> Send for Handoff<Msg>
impl<Msg> Unpin for Handoff<Msg>
impl<Msg> UnsafeUnpin for Handoff<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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