Files
topgrade/src/terminal.rs

333 lines
9.7 KiB
Rust
Raw Normal View History

2018-05-31 16:00:01 +03:00
use std::cmp::{max, min};
use std::env;
use std::io::{self, Write};
use std::process::Command;
use std::sync::{LazyLock, Mutex};
use std::time::Duration;
use chrono::{Local, Timelike};
2022-11-11 09:39:29 -05:00
use color_eyre::eyre;
use color_eyre::eyre::Context;
use console::{Key, Term, style};
use notify_rust::{Notification, Timeout};
use rust_i18n::t;
2022-11-16 13:43:57 -05:00
use tracing::{debug, error};
#[cfg(windows)]
2019-08-14 21:36:57 +03:00
use which_crate::which;
2018-05-31 16:00:01 +03:00
use crate::command::CommandExt;
use crate::runner::StepResult;
static TERMINAL: LazyLock<Mutex<Terminal>> = LazyLock::new(|| Mutex::new(Terminal::new()));
2018-12-05 11:34:08 +02:00
#[cfg(unix)]
2019-08-22 21:46:06 +03:00
pub fn shell() -> String {
env::var("SHELL").unwrap_or_else(|_| "sh".to_string())
}
#[cfg(windows)]
2019-08-22 21:46:06 +03:00
pub fn shell() -> &'static str {
2019-08-14 21:36:57 +03:00
which("pwsh").map(|_| "pwsh").unwrap_or("powershell")
}
2022-11-11 09:39:29 -05:00
pub fn run_shell() -> eyre::Result<()> {
Command::new(shell()).env("IN_TOPGRADE", "1").status_checked()
2019-06-13 22:05:18 +03:00
}
2018-12-05 11:34:08 +02:00
struct Terminal {
2018-11-01 11:28:27 +02:00
width: Option<u16>,
prefix: String,
2018-11-01 11:28:27 +02:00
term: Term,
set_title: bool,
display_time: bool,
desktop_notification: bool,
2018-05-31 16:00:01 +03:00
}
impl Terminal {
2018-12-05 11:34:08 +02:00
fn new() -> Self {
2018-11-01 11:28:27 +02:00
let term = Term::stdout();
2018-05-31 16:00:01 +03:00
Self {
2018-11-01 11:28:27 +02:00
width: term.size_checked().map(|(_, w)| w),
term,
prefix: env::var("TOPGRADE_PREFIX").map_or_else(|_| String::new(), |prefix| format!("({prefix}) ")),
set_title: true,
display_time: true,
desktop_notification: false,
2018-05-31 16:00:01 +03:00
}
}
fn set_desktop_notifications(&mut self, desktop_notifications: bool) {
self.desktop_notification = desktop_notifications;
}
fn set_title(&mut self, set_title: bool) {
self.set_title = set_title;
}
fn display_time(&mut self, display_time: bool) {
self.display_time = display_time;
}
fn notify_desktop<P: AsRef<str>>(&self, message: P, timeout: Option<Duration>) {
debug!("Desktop notification: {}", message.as_ref());
let mut notification = Notification::new();
notification
.summary("Topgrade")
.body(message.as_ref())
.appname("topgrade");
if let Some(timeout) = timeout {
notification.timeout(Timeout::Milliseconds(timeout.as_millis() as u32));
}
notification.show().ok();
}
2018-12-05 11:34:08 +02:00
fn print_separator<P: AsRef<str>>(&mut self, message: P) {
if self.set_title {
self.term
.set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref()));
}
if self.desktop_notification {
self.notify_desktop(message.as_ref(), Some(Duration::from_secs(5)));
}
2019-05-21 16:40:00 +03:00
let now = Local::now();
let message = if self.display_time {
format!(
"{}{:02}:{:02}:{:02} - {}",
self.prefix,
now.hour(),
now.minute(),
now.second(),
message.as_ref()
)
} else {
String::from(message.as_ref())
};
2018-06-04 23:23:25 +03:00
match self.width {
Some(width) => {
2018-12-05 11:34:08 +02:00
self.term
.write_fmt(format_args!(
"{}\n",
style(format_args!(
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
"\n── {} {:─^border$}",
2018-12-05 11:34:08 +02:00
message,
"",
2019-01-30 10:41:40 +02:00
border = max(
2,
min(80, width as usize)
2019-03-15 19:22:37 -05:00
.checked_sub(4)
2019-01-30 10:41:40 +02:00
.and_then(|e| e.checked_sub(message.len()))
.unwrap_or(0)
)
2018-12-11 16:00:19 +02:00
))
.bold()
))
.ok();
2018-06-04 23:23:25 +03:00
}
None => {
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
self.term.write_fmt(format_args!("―― {message} ――\n")).ok();
2018-05-31 16:00:01 +03:00
}
}
}
2018-06-03 16:43:53 +03:00
2022-11-11 09:42:16 -05:00
#[allow(dead_code)]
fn print_error<P: AsRef<str>, Q: AsRef<str>>(&mut self, key: Q, message: P) {
let key = key.as_ref();
let message = message.as_ref();
self.term
.write_fmt(format_args!(
"{} {}",
style(format!("{}", t!("{key} failed:", key = key))).red().bold(),
2022-11-11 09:42:16 -05:00
message
))
.ok();
}
2018-06-27 23:04:39 +03:00
#[allow(dead_code)]
2018-12-05 11:34:08 +02:00
fn print_warning<P: AsRef<str>>(&mut self, message: P) {
2018-06-04 23:23:25 +03:00
let message = message.as_ref();
2018-12-05 11:34:08 +02:00
self.term
.write_fmt(format_args!("{}\n", style(message).yellow().bold()))
.ok();
2018-06-03 16:43:53 +03:00
}
2018-06-03 18:04:58 +03:00
2019-06-13 22:05:18 +03:00
#[allow(dead_code)]
fn print_info<P: AsRef<str>>(&mut self, message: P) {
let message = message.as_ref();
self.term
2019-06-16 09:09:05 +03:00
.write_fmt(format_args!("{}\n", style(message).blue().bold()))
2019-06-13 22:05:18 +03:00
.ok();
}
2020-08-21 23:04:36 +03:00
fn print_result<P: AsRef<str>>(&mut self, key: P, result: &StepResult) {
2018-06-03 18:04:58 +03:00
let key = key.as_ref();
2018-12-05 11:34:08 +02:00
self.term
.write_fmt(format_args!(
"{}: {}\n",
key,
match result {
StepResult::Success => format!("{}", style(t!("OK")).bold().green()),
StepResult::Failure => format!("{}", style(t!("FAILED")).bold().red()),
StepResult::Ignored => format!("{}", style(t!("IGNORED")).bold().yellow()),
StepResult::SkippedMissingSudo => format!(
"{}: {}",
style(t!("SKIPPED")).bold().yellow(),
t!("Could not find sudo")
),
StepResult::Skipped(reason) => format!("{}: {}", style(t!("SKIPPED")).bold().blue(), reason),
2018-12-05 11:34:08 +02:00
}
2018-12-11 16:00:19 +02:00
))
.ok();
2018-06-03 18:04:58 +03:00
}
2018-08-25 22:19:38 +03:00
#[allow(dead_code)]
fn prompt_yesno(&mut self, question: &str) -> Result<bool, io::Error> {
self.term
.write_fmt(format_args!(
"{}",
style(format!("{question} {}", t!("(Y)es/(N)o"))).yellow().bold()
))
.ok();
loop {
match self.term.read_char()? {
'y' | 'Y' => break Ok(true),
'n' | 'N' | '\r' | '\n' => break Ok(false),
_ => (),
}
}
}
2020-01-03 10:26:21 +02:00
#[allow(unused_variables)]
fn should_retry(&mut self, step_name: &str) -> eyre::Result<ShouldRetry> {
2018-08-25 22:19:38 +03:00
if self.width.is_none() {
return Ok(ShouldRetry::No);
2018-08-25 22:19:38 +03:00
}
if self.set_title {
self.term.set_title(format!("Topgrade - {}", t!("Awaiting user")));
}
2020-01-03 10:26:21 +02:00
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
if self.desktop_notification {
self.notify_desktop(format!("{}", t!("{step_name} failed", step_name = step_name)), None);
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
}
2020-01-03 10:26:21 +02:00
let prompt_inner = style(format!("{}{}", self.prefix, t!("Retry? (y)es/(N)o/(s)hell/(q)uit")))
.yellow()
.bold();
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
self.term.write_fmt(format_args!("\n{prompt_inner}")).ok();
2018-08-25 22:19:38 +03:00
2018-11-10 20:18:43 +02:00
let answer = loop {
match self.term.read_key() {
Ok(Key::Char('y' | 'Y')) => break Ok(ShouldRetry::Yes),
Ok(Key::Char('s' | 'S')) => {
println!(
"\n\n{}\n",
t!("Dropping you to shell. Fix what you need and then exit the shell.")
);
if let Err(err) = run_shell().context("Failed to run shell") {
v10.2.5 release (#330) * Don't show desktop notification on error (if `skip_notify = true`) (#275) * Use ─ (U+2500) to draw borders (#282) * Adds Pclinuxos support (#283) * Add Devkitpro Pacman support (#291) * Added support for Neovim package manager lazy.nvim (#293) * Added support for lazy.nvim From https://github.com/folke/lazy.nvim Authored-by: Jacob Lane Ledbetter <jledbetter460@gmail.com> * Make garuda-update update AUR packages by default (#296) * fix(#298): Don't throw error if no Helm repository found (#305) * Skip .NET when `dotnet tool list` is not successful (#302) * feat(pacstall): add `-y` flag variant (#312) * Add openSUSE MicroOS support (#315) * Adds notify-send timeout of 10s (#318) * Don't run yum when rpm-ostree is available (#313) * don't run yum when rpm-ostree is available * Clippy fix * rpm-ostree: set default value to true * Fixes if loop error * Fixes gem update --system requires sudo now (#317) * Fixes gem update --system requires sudo now * rubygem: Adds arg -EH to sudo * Use fixed nala path instead of which(nala) (#314) * Adds notify-send bug warning when topgrade is run (#324) * Adds notify-send bug warning when topgrade is run * fix typo + clippy * notify-send warning respects skip_notify flag * nix: Adds additional arguments support (#325) * Adds pip-review and pipupgrade support (#316) * Adds pip-review and pipupgrade support * Python: fixes pip_review and pipupgrade * v10.2.5 patch (#329) * WSL: Adds new wsl --update flags (#327) * wsl: Updates available flags * Clippy fix * Add WslUpdate runner * wsl: Code Typo * wsl: Code Typos * wsl: Code Typos * wsl: Code Typo * Adds AM Package Manager (#328) * Adds AM Package Manager * Clippy fixes * Cargo fmt * Moves am to linux only in main file --------- Co-authored-by: Guilherme Silva <626206+guihkx@users.noreply.github.com> Co-authored-by: Gabriel Augendre <gabriel@augendre.info> Co-authored-by: Cat Core <34719527+arthurbambou@users.noreply.github.com> Co-authored-by: Hugo Haas <hugoh@hugoh.net> Co-authored-by: Baptiste <32563450+BapRx@users.noreply.github.com> Co-authored-by: bbx0 <39773919+bbx0@users.noreply.github.com> Co-authored-by: Sourajyoti Basak <wiz28@protonmail.com>
2023-01-29 19:19:27 +00:00
self.term.write_fmt(format_args!("{err:?}\n{prompt_inner}")).ok();
} else {
break Ok(ShouldRetry::Yes);
}
}
Ok(Key::Char('n' | 'N') | Key::Enter) => break Ok(ShouldRetry::No),
Err(e) => {
error!("Error reading from terminal: {}", e);
break Ok(ShouldRetry::No);
}
Ok(Key::Char('q' | 'Q')) => {
break Ok(ShouldRetry::Quit);
}
2020-08-26 22:33:10 +03:00
_ => (),
2018-08-25 22:19:38 +03:00
}
2018-11-10 20:18:43 +02:00
};
2018-12-05 11:34:08 +02:00
self.term.write_str("\n").ok();
2018-11-10 20:18:43 +02:00
answer
2018-08-25 22:19:38 +03:00
}
fn get_char(&self) -> Result<Key, io::Error> {
self.term.read_key()
}
2018-05-31 16:00:01 +03:00
}
#[derive(Clone, Copy)]
pub enum ShouldRetry {
Yes,
No,
Quit,
}
impl Default for Terminal {
fn default() -> Self {
Self::new()
}
}
2018-12-05 11:34:08 +02:00
pub fn should_retry(step_name: &str) -> eyre::Result<ShouldRetry> {
TERMINAL.lock().unwrap().should_retry(step_name)
2018-12-05 11:34:08 +02:00
}
pub fn print_separator<P: AsRef<str>>(message: P) {
TERMINAL.lock().unwrap().print_separator(message);
2018-12-05 11:34:08 +02:00
}
2022-11-11 09:42:16 -05:00
#[allow(dead_code)]
pub fn print_error<P: AsRef<str>, Q: AsRef<str>>(key: Q, message: P) {
TERMINAL.lock().unwrap().print_error(key, message);
2022-11-11 09:42:16 -05:00
}
2019-01-21 20:28:23 +02:00
#[allow(dead_code)]
2018-12-05 11:34:08 +02:00
pub fn print_warning<P: AsRef<str>>(message: P) {
TERMINAL.lock().unwrap().print_warning(message);
2018-12-05 11:34:08 +02:00
}
2019-06-13 22:05:18 +03:00
#[allow(dead_code)]
pub fn print_info<P: AsRef<str>>(message: P) {
TERMINAL.lock().unwrap().print_info(message);
2019-06-13 22:05:18 +03:00
}
2020-08-21 23:04:36 +03:00
pub fn print_result<P: AsRef<str>>(key: P, result: &StepResult) {
TERMINAL.lock().unwrap().print_result(key, result);
2018-12-05 11:34:08 +02:00
}
/// Tells whether the terminal is dumb.
pub fn is_dumb() -> bool {
TERMINAL.lock().unwrap().width.is_none()
}
pub fn get_key() -> Result<Key, io::Error> {
TERMINAL.lock().unwrap().get_char()
}
pub fn set_title(set_title: bool) {
TERMINAL.lock().unwrap().set_title(set_title);
}
pub fn set_desktop_notifications(desktop_notifications: bool) {
TERMINAL
.lock()
.unwrap()
.set_desktop_notifications(desktop_notifications);
}
#[allow(dead_code)]
pub fn prompt_yesno(question: &str) -> Result<bool, io::Error> {
TERMINAL.lock().unwrap().prompt_yesno(question)
}
pub fn notify_desktop<P: AsRef<str>>(message: P, timeout: Option<Duration>) {
TERMINAL.lock().unwrap().notify_desktop(message, timeout);
}
pub fn display_time(display_time: bool) {
TERMINAL.lock().unwrap().display_time(display_time);
}