diff options
author | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2021-11-06 04:39:14 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-05 20:39:14 +0100 |
commit | 8ef1d10df9063caae097302d55ebda685ddd9138 (patch) | |
tree | 8079ed0e017247d07dad95b568f8962653155d80 /zellij-utils/src/errors.rs | |
parent | 6e5c8dc852f1f219e51418964d611b87253d879a (diff) |
fix(errors): Add colored crate to replace primitive color formatting (#837)
Diffstat (limited to 'zellij-utils/src/errors.rs')
-rw-r--r-- | zellij-utils/src/errors.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index a217f56c7..6dae0d1ac 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -2,6 +2,7 @@ //! the instructions that are sent between threads. use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; +use colored::*; use serde::{Deserialize, Serialize}; use std::fmt::{Display, Error, Formatter}; use std::panic::PanicInfo; @@ -180,24 +181,21 @@ pub enum ContextType { Empty, } -// TODO use the `colored` crate for color formatting impl Display for ContextType { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - let purple = "\u{1b}[1;35m"; - let green = "\u{1b}[0;32m"; - match *self { - ContextType::Screen(c) => write!(f, "{}screen_thread: {}{:?}", purple, green, c), - ContextType::Pty(c) => write!(f, "{}pty_thread: {}{:?}", purple, green, c), - ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), - ContextType::Client(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), - ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c), - ContextType::StdinHandler => { - write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) - } - ContextType::AsyncTask => { - write!(f, "{}stream_terminal_bytes: {}AsyncTask", purple, green) - } - ContextType::Empty => write!(f, ""), + if let Some((left, right)) = match *self { + ContextType::Screen(c) => Some(("screen_thread:", format!("{:?}", c))), + ContextType::Pty(c) => Some(("pty_thread:", format!("{:?}", c))), + ContextType::Plugin(c) => Some(("plugin_thread:", format!("{:?}", c))), + ContextType::Client(c) => Some(("main_thread:", format!("{:?}", c))), + ContextType::IPCServer(c) => Some(("ipc_server:", format!("{:?}", c))), + ContextType::StdinHandler => Some(("stdin_handler_thread:", "AcceptInput".to_string())), + ContextType::AsyncTask => Some(("stream_terminal_bytes:", "AsyncTask".to_string())), + ContextType::Empty => None, + } { + write!(f, "{} {}", left.purple(), right.green()) + } else { + write!(f, "") } } } |