Colorize pacman output on ttys

Signed-off-by: Trivernis <trivernis@protonmail.com>
i18n
Trivernis 2 years ago
parent 31f1d1bf74
commit c2bbe77b89

@ -57,3 +57,4 @@ rusqlite = { version = "0.26.3", default-features = false }
ureq = { version = "2.4.0", default-features = false, features = ["native-tls", "json"] }
serde = { version = "1.0.90", default-features = false, features = ["derive", "serde_derive"] }
native-tls = "0.2.8"
libc = "0.2.123"

@ -1,4 +1,5 @@
use crate::internal::error::{AppError, AppResult};
use crate::internal::is_tty;
use std::ffi::{OsStr, OsString};
use std::process::{Child, Command, ExitStatus, Stdio};
@ -18,7 +19,13 @@ pub struct ShellCommand {
impl ShellCommand {
pub fn pacman() -> Self {
Self::new("pacman")
let pacman_cmd = Self::new("pacman");
if is_tty() {
pacman_cmd.arg("--color=always")
} else {
pacman_cmd
}
}
pub fn makepkg() -> Self {

@ -38,3 +38,9 @@ pub fn uwu_enabled() -> bool {
pub fn uwu_debug_enabled() -> bool {
env::var("AME_UWU_DEBUG").unwrap_or_else(|_| "".to_string()) == "true"
}
/// Checks if we're running in a tty. If we do we can assume that
/// the output can safely be colorized.
pub fn is_tty() -> bool {
(unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0)
}

@ -17,11 +17,7 @@ mod internal;
mod operations;
fn main() {
extern "C" {
fn geteuid() -> u32;
}
if unsafe { geteuid() } == 0 {
if unsafe { libc::geteuid() } == 0 {
crash("Running amethyst as root is disallowed as it can lead to system breakage. Instead, amethyst will prompt you when it needs superuser permissions".to_string(), AppExitCode::RunAsRoot);
}

Loading…
Cancel
Save