2019-11-09 06:55:12 +03:00
|
|
|
//! a tab hosting a termwiz terminal applet
|
|
|
|
//! The idea is to use these when wezterm needs to request
|
|
|
|
//! input from the user as part of eg: setting up an ssh
|
|
|
|
//! session.
|
|
|
|
|
2020-01-05 19:35:50 +03:00
|
|
|
use crate::config::configuration;
|
2019-11-09 06:55:12 +03:00
|
|
|
use crate::font::FontConfiguration;
|
2020-01-16 21:31:53 +03:00
|
|
|
use crate::frontend::front_end;
|
2019-11-09 06:55:12 +03:00
|
|
|
use crate::mux::domain::{alloc_domain_id, Domain, DomainId, DomainState};
|
2020-01-03 20:54:27 +03:00
|
|
|
use crate::mux::renderable::{Renderable, RenderableDimensions, StableCursorPosition};
|
2019-11-09 06:55:12 +03:00
|
|
|
use crate::mux::tab::{alloc_tab_id, Tab, TabId};
|
|
|
|
use crate::mux::window::WindowId;
|
|
|
|
use crate::mux::Mux;
|
2019-12-15 08:43:05 +03:00
|
|
|
use anyhow::{bail, Error};
|
2019-11-09 06:55:12 +03:00
|
|
|
use crossbeam_channel::{unbounded as channel, Receiver, Sender};
|
|
|
|
use filedescriptor::Pipe;
|
|
|
|
use portable_pty::*;
|
2020-01-08 19:34:22 +03:00
|
|
|
use rangeset::RangeSet;
|
2019-11-09 06:55:12 +03:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::cell::RefMut;
|
2020-01-03 05:44:50 +03:00
|
|
|
use std::convert::TryInto;
|
2019-11-09 06:55:12 +03:00
|
|
|
use std::ops::Range;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2020-01-05 19:35:50 +03:00
|
|
|
use std::sync::Arc;
|
2019-11-09 06:55:12 +03:00
|
|
|
use std::time::Duration;
|
|
|
|
use term::color::ColorPalette;
|
2020-01-04 19:56:47 +03:00
|
|
|
use term::{KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, TerminalHost};
|
2019-11-09 06:55:12 +03:00
|
|
|
use termwiz::input::{InputEvent, KeyEvent};
|
2019-11-09 08:11:22 +03:00
|
|
|
use termwiz::lineedit::*;
|
2019-11-09 06:55:12 +03:00
|
|
|
use termwiz::surface::{Change, SequenceNo, Surface};
|
2019-11-09 08:11:22 +03:00
|
|
|
use termwiz::terminal::{ScreenSize, Terminal, TerminalWaker};
|
2020-01-15 09:06:13 +03:00
|
|
|
use url::Url;
|
2019-11-09 06:55:12 +03:00
|
|
|
|
|
|
|
struct RenderableInner {
|
|
|
|
surface: Surface,
|
|
|
|
something_changed: Arc<AtomicBool>,
|
|
|
|
local_sequence: SequenceNo,
|
|
|
|
dead: bool,
|
|
|
|
render_rx: Receiver<Vec<Change>>,
|
|
|
|
input_tx: Sender<InputEvent>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RenderableState {
|
|
|
|
inner: RefCell<RenderableInner>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::io::Write for RenderableState {
|
|
|
|
fn write(&mut self, data: &[u8]) -> Result<usize, std::io::Error> {
|
|
|
|
if let Ok(s) = std::str::from_utf8(data) {
|
|
|
|
let paste = InputEvent::Paste(s.to_string());
|
|
|
|
self.inner.borrow_mut().input_tx.send(paste).ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(data.len())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> Result<(), std::io::Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Renderable for RenderableState {
|
2020-01-03 20:54:27 +03:00
|
|
|
fn get_cursor_position(&self) -> StableCursorPosition {
|
2019-12-22 19:52:51 +03:00
|
|
|
let surface = &self.inner.borrow().surface;
|
|
|
|
let (x, y) = surface.cursor_position();
|
|
|
|
let shape = surface.cursor_shape();
|
2020-01-03 20:54:27 +03:00
|
|
|
StableCursorPosition {
|
2019-12-22 19:52:51 +03:00
|
|
|
x,
|
2020-01-03 20:54:27 +03:00
|
|
|
y: y as StableRowIndex,
|
2019-12-22 19:52:51 +03:00
|
|
|
shape,
|
|
|
|
}
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
|
|
|
|
2020-01-04 21:05:34 +03:00
|
|
|
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {
|
2020-01-03 05:44:50 +03:00
|
|
|
let inner = self.inner.borrow_mut();
|
2020-01-04 21:05:34 +03:00
|
|
|
|
|
|
|
// Reset the dirty bit
|
|
|
|
inner.something_changed.store(false, Ordering::SeqCst);
|
|
|
|
|
2020-01-05 19:35:50 +03:00
|
|
|
let config = configuration();
|
|
|
|
|
2020-01-03 19:57:32 +03:00
|
|
|
(
|
|
|
|
lines.start,
|
|
|
|
inner
|
|
|
|
.surface
|
|
|
|
.screen_lines()
|
|
|
|
.into_iter()
|
|
|
|
.skip(lines.start.try_into().unwrap())
|
|
|
|
.take((lines.end - lines.start).try_into().unwrap())
|
2020-01-05 19:35:50 +03:00
|
|
|
.map(|line| {
|
|
|
|
let mut line = line.into_owned();
|
|
|
|
line.scan_and_create_hyperlinks(&config.hyperlink_rules);
|
|
|
|
line
|
|
|
|
})
|
2020-01-03 19:57:32 +03:00
|
|
|
.collect(),
|
|
|
|
)
|
2020-01-03 05:44:50 +03:00
|
|
|
}
|
|
|
|
|
2020-01-08 19:34:22 +03:00
|
|
|
fn get_dirty_lines(&self, lines: Range<StableRowIndex>) -> RangeSet<StableRowIndex> {
|
2019-11-09 06:55:12 +03:00
|
|
|
let mut inner = self.inner.borrow_mut();
|
2020-01-08 19:34:22 +03:00
|
|
|
let mut set = RangeSet::new();
|
2019-11-09 06:55:12 +03:00
|
|
|
|
|
|
|
loop {
|
|
|
|
match inner.render_rx.try_recv() {
|
|
|
|
Ok(changes) => {
|
|
|
|
inner.surface.add_changes(changes);
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
if err.is_disconnected() {
|
|
|
|
inner.dead = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-04 21:05:34 +03:00
|
|
|
if inner.something_changed.load(Ordering::SeqCst)
|
|
|
|
|| inner.surface.has_changes(inner.local_sequence)
|
|
|
|
{
|
2020-01-08 19:34:22 +03:00
|
|
|
set.add_range(lines);
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
2020-01-08 19:34:22 +03:00
|
|
|
set
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
|
|
|
|
2020-01-03 05:10:41 +03:00
|
|
|
fn get_dimensions(&self) -> RenderableDimensions {
|
|
|
|
let (cols, viewport_rows) = self.inner.borrow().surface.dimensions();
|
|
|
|
RenderableDimensions {
|
|
|
|
viewport_rows,
|
|
|
|
cols,
|
2020-01-04 04:15:15 +03:00
|
|
|
scrollback_rows: viewport_rows,
|
2020-01-03 19:57:32 +03:00
|
|
|
physical_top: 0,
|
|
|
|
scrollback_top: 0,
|
2020-01-03 05:10:41 +03:00
|
|
|
}
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TermWizTerminalDomain {
|
|
|
|
domain_id: DomainId,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TermWizTerminalDomain {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
let domain_id = alloc_domain_id();
|
|
|
|
Self { domain_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Domain for TermWizTerminalDomain {
|
|
|
|
fn spawn(
|
|
|
|
&self,
|
|
|
|
_size: PtySize,
|
|
|
|
_command: Option<CommandBuilder>,
|
2020-01-11 10:18:59 +03:00
|
|
|
_command_dir: Option<String>,
|
2019-11-09 06:55:12 +03:00
|
|
|
_window: WindowId,
|
2019-12-15 08:43:05 +03:00
|
|
|
) -> anyhow::Result<Rc<dyn Tab>> {
|
2019-11-09 06:55:12 +03:00
|
|
|
bail!("cannot spawn tabs in a TermWizTerminalTab");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn domain_id(&self) -> DomainId {
|
|
|
|
self.domain_id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn domain_name(&self) -> &str {
|
|
|
|
"TermWizTerminalDomain"
|
|
|
|
}
|
2020-01-07 09:41:59 +03:00
|
|
|
fn attach(&self) -> promise::Future<()> {
|
|
|
|
promise::Future::ok(())
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn detach(&self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
bail!("detach not implemented for TermWizTerminalDomain");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn state(&self) -> DomainState {
|
|
|
|
DomainState::Attached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TermWizTerminalTab {
|
|
|
|
tab_id: TabId,
|
|
|
|
domain_id: DomainId,
|
|
|
|
renderable: RefCell<RenderableState>,
|
|
|
|
reader: Pipe,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for TermWizTerminalTab {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
log::error!("Dropping TermWizTerminalTab");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TermWizTerminalTab {
|
|
|
|
fn new(domain_id: DomainId, inner: RenderableInner) -> Self {
|
|
|
|
let tab_id = alloc_tab_id();
|
|
|
|
let renderable = RefCell::new(RenderableState {
|
|
|
|
inner: RefCell::new(inner),
|
|
|
|
});
|
|
|
|
let reader = Pipe::new().expect("Pipe::new failed");
|
|
|
|
Self {
|
|
|
|
tab_id,
|
|
|
|
domain_id,
|
|
|
|
renderable,
|
|
|
|
reader,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Tab for TermWizTerminalTab {
|
|
|
|
fn tab_id(&self) -> TabId {
|
|
|
|
self.tab_id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn renderer(&self) -> RefMut<dyn Renderable> {
|
|
|
|
self.renderable.borrow_mut()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_title(&self) -> String {
|
|
|
|
let renderable = self.renderable.borrow();
|
|
|
|
let surface = &renderable.inner.borrow().surface;
|
|
|
|
surface.title().to_string()
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn send_paste(&self, text: &str) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
let paste = InputEvent::Paste(text.to_string());
|
|
|
|
self.renderable
|
|
|
|
.borrow_mut()
|
|
|
|
.inner
|
|
|
|
.borrow_mut()
|
|
|
|
.input_tx
|
|
|
|
.send(paste)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn reader(&self) -> anyhow::Result<Box<dyn std::io::Read + Send>> {
|
2019-11-09 06:55:12 +03:00
|
|
|
Ok(Box::new(self.reader.read.try_clone()?))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn writer(&self) -> RefMut<dyn std::io::Write> {
|
|
|
|
self.renderable.borrow_mut()
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn resize(&self, size: PtySize) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
self.renderable
|
|
|
|
.borrow()
|
|
|
|
.inner
|
|
|
|
.borrow_mut()
|
|
|
|
.surface
|
|
|
|
.resize(size.cols as usize, size.rows as usize);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn key_down(&self, key: KeyCode, modifiers: KeyModifiers) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
let event = InputEvent::Key(KeyEvent { key, modifiers });
|
|
|
|
self.renderable
|
|
|
|
.borrow_mut()
|
|
|
|
.inner
|
|
|
|
.borrow_mut()
|
|
|
|
.input_tx
|
|
|
|
.send(event)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn mouse_event(&self, _event: MouseEvent, _host: &mut dyn TerminalHost) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
// FIXME: send mouse events through
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn advance_bytes(&self, _buf: &[u8], _host: &mut dyn TerminalHost) {
|
|
|
|
panic!("advance_bytes is undefed for TermWizTerminalTab");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_dead(&self) -> bool {
|
|
|
|
self.renderable.borrow().inner.borrow().dead
|
|
|
|
}
|
|
|
|
|
|
|
|
fn palette(&self) -> ColorPalette {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn domain_id(&self) -> DomainId {
|
|
|
|
self.domain_id
|
|
|
|
}
|
|
|
|
|
2020-01-03 07:02:59 +03:00
|
|
|
fn is_mouse_grabbed(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2020-01-11 10:18:15 +03:00
|
|
|
|
2020-01-15 09:06:13 +03:00
|
|
|
fn get_current_working_dir(&self) -> Option<Url> {
|
2020-01-11 10:18:15 +03:00
|
|
|
None
|
|
|
|
}
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TermWizTerminal {
|
|
|
|
render_tx: Sender<Vec<Change>>,
|
|
|
|
input_rx: Receiver<InputEvent>,
|
|
|
|
screen_size: ScreenSize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TermWizTerminal {
|
2019-12-15 08:43:05 +03:00
|
|
|
fn do_input_poll(&mut self, wait: Option<Duration>) -> anyhow::Result<Option<InputEvent>> {
|
2019-11-09 06:55:12 +03:00
|
|
|
if let Some(timeout) = wait {
|
|
|
|
match self.input_rx.recv_timeout(timeout) {
|
|
|
|
Ok(input) => Ok(Some(input)),
|
|
|
|
Err(err) => {
|
|
|
|
if err.is_timeout() {
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
Err(err.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let input = self.input_rx.recv()?;
|
|
|
|
Ok(Some(input))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl termwiz::terminal::Terminal for TermWizTerminal {
|
2019-12-15 08:43:05 +03:00
|
|
|
fn set_raw_mode(&mut self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn set_cooked_mode(&mut self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn enter_alternate_screen(&mut self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
bail!("TermWizTerminalTab has no alt screen");
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn exit_alternate_screen(&mut self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
bail!("TermWizTerminalTab has no alt screen");
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn get_screen_size(&mut self) -> anyhow::Result<ScreenSize> {
|
2019-11-09 06:55:12 +03:00
|
|
|
Ok(self.screen_size)
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn set_screen_size(&mut self, _size: ScreenSize) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
bail!("TermWizTerminalTab cannot set screen size");
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn render(&mut self, changes: &[Change]) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
self.render_tx.send(changes.to_vec())?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn flush(&mut self) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
fn poll_input(&mut self, wait: Option<Duration>) -> anyhow::Result<Option<InputEvent>> {
|
2019-11-09 06:55:12 +03:00
|
|
|
self.do_input_poll(wait).map(|i| {
|
|
|
|
if let Some(InputEvent::Resized { cols, rows }) = i.as_ref() {
|
|
|
|
self.screen_size.cols = *cols;
|
|
|
|
self.screen_size.rows = *rows;
|
|
|
|
}
|
|
|
|
i
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn waker(&self) -> TerminalWaker {
|
|
|
|
// TODO: TerminalWaker assumes that we're a SystemTerminal but that
|
|
|
|
// isn't the case here.
|
|
|
|
panic!("TermWizTerminal::waker called!?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function spawns a thread and constructs a GUI window with an
|
|
|
|
/// associated termwiz Terminal object to execute the provided function.
|
|
|
|
/// The function is expected to run in a loop to manage input and output
|
|
|
|
/// from the terminal window.
|
|
|
|
/// When it completes its loop it will fulfil a promise and yield
|
|
|
|
/// the return value from the function.
|
2020-01-16 20:15:07 +03:00
|
|
|
pub async fn run<
|
|
|
|
T: Send + 'static,
|
|
|
|
F: Send + 'static + Fn(TermWizTerminal) -> anyhow::Result<T>,
|
|
|
|
>(
|
2019-11-09 06:55:12 +03:00
|
|
|
width: usize,
|
|
|
|
height: usize,
|
|
|
|
f: F,
|
2020-01-16 20:15:07 +03:00
|
|
|
) -> anyhow::Result<T> {
|
2019-11-09 06:55:12 +03:00
|
|
|
let (render_tx, render_rx) = channel();
|
|
|
|
let (input_tx, input_rx) = channel();
|
|
|
|
|
|
|
|
let tw_term = TermWizTerminal {
|
|
|
|
render_tx,
|
|
|
|
input_rx,
|
|
|
|
screen_size: ScreenSize {
|
|
|
|
cols: width,
|
|
|
|
rows: height,
|
|
|
|
xpixel: 0,
|
|
|
|
ypixel: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-16 20:15:07 +03:00
|
|
|
async fn register_tab(
|
|
|
|
input_tx: Sender<InputEvent>,
|
|
|
|
render_rx: Receiver<Vec<Change>>,
|
|
|
|
width: usize,
|
|
|
|
height: usize,
|
|
|
|
) -> anyhow::Result<()> {
|
2019-11-09 06:55:12 +03:00
|
|
|
let mux = Mux::get().unwrap();
|
|
|
|
|
|
|
|
// TODO: make a singleton
|
|
|
|
let domain: Arc<dyn Domain> = Arc::new(TermWizTerminalDomain::new());
|
|
|
|
mux.add_domain(&domain);
|
|
|
|
|
|
|
|
let window_id = mux.new_empty_window();
|
|
|
|
|
|
|
|
let inner = RenderableInner {
|
|
|
|
surface: Surface::new(width, height),
|
|
|
|
local_sequence: 0,
|
|
|
|
dead: false,
|
|
|
|
something_changed: Arc::new(AtomicBool::new(false)),
|
|
|
|
input_tx,
|
|
|
|
render_rx,
|
|
|
|
};
|
|
|
|
|
|
|
|
let tab: Rc<dyn Tab> = Rc::new(TermWizTerminalTab::new(domain.domain_id(), inner));
|
|
|
|
|
|
|
|
mux.add_tab(&tab)?;
|
|
|
|
mux.add_tab_to_window(&tab, window_id)?;
|
|
|
|
|
2019-12-10 00:35:38 +03:00
|
|
|
let fontconfig = Rc::new(FontConfiguration::new());
|
2019-11-09 06:55:12 +03:00
|
|
|
|
|
|
|
let gui = front_end().unwrap();
|
2019-11-24 19:55:55 +03:00
|
|
|
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
2019-11-09 06:55:12 +03:00
|
|
|
|
|
|
|
Ok(())
|
2020-01-16 20:15:07 +03:00
|
|
|
}
|
2019-11-09 06:55:12 +03:00
|
|
|
|
2020-01-16 20:15:07 +03:00
|
|
|
promise::spawn::spawn_into_main_thread(async move {
|
|
|
|
register_tab(input_tx, render_rx, width, height).await.ok();
|
2019-11-09 06:55:12 +03:00
|
|
|
});
|
|
|
|
|
2020-01-16 20:15:07 +03:00
|
|
|
promise::spawn::spawn_into_new_thread(move || f(tw_term))
|
|
|
|
.await
|
|
|
|
.unwrap_or_else(|| bail!("task panicked or was cancelled"))
|
2019-11-09 06:55:12 +03:00
|
|
|
}
|
2019-11-09 08:11:22 +03:00
|
|
|
|
|
|
|
pub fn message_box_ok(message: &str) {
|
|
|
|
let title = "wezterm";
|
|
|
|
let message = message.to_string();
|
|
|
|
|
2020-01-16 20:15:07 +03:00
|
|
|
promise::spawn::block_on(run(60, 10, move |mut term| {
|
2019-11-09 08:11:22 +03:00
|
|
|
term.render(&[
|
|
|
|
Change::Title(title.to_string()),
|
|
|
|
Change::Text(message.to_string()),
|
2019-12-15 08:43:05 +03:00
|
|
|
])
|
|
|
|
.map_err(Error::msg)?;
|
2019-11-09 08:11:22 +03:00
|
|
|
|
|
|
|
let mut editor = LineEditor::new(term);
|
|
|
|
editor.set_prompt("press enter to continue.");
|
|
|
|
|
|
|
|
let mut host = NopLineEditorHost::default();
|
|
|
|
editor.read_line(&mut host).ok();
|
|
|
|
Ok(())
|
2020-01-16 20:15:07 +03:00
|
|
|
}))
|
2019-11-09 08:11:22 +03:00
|
|
|
.ok();
|
|
|
|
}
|