fix(errors): Add colored crate to replace primitive color formatting (#837)

This commit is contained in:
Ken Matsui 2021-11-06 04:39:14 +09:00 committed by GitHub
parent 6e5c8dc852
commit 8ef1d10df9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

1
Cargo.lock generated
View file

@ -2906,6 +2906,7 @@ dependencies = [
"async-std", "async-std",
"backtrace", "backtrace",
"bincode", "bincode",
"colored",
"colorsys", "colorsys",
"crossbeam", "crossbeam",
"directories-next", "directories-next",

View file

@ -11,6 +11,7 @@ license = "MIT"
[dependencies] [dependencies]
backtrace = "0.3.55" backtrace = "0.3.55"
bincode = "1.3.1" bincode = "1.3.1"
colored = "2.0.0"
colorsys = "0.6.5" colorsys = "0.6.5"
crossbeam = "0.8.0" crossbeam = "0.8.0"
directories-next = "2.0" directories-next = "2.0"

View file

@ -2,6 +2,7 @@
//! the instructions that are sent between threads. //! the instructions that are sent between threads.
use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS};
use colored::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
use std::panic::PanicInfo; use std::panic::PanicInfo;
@ -180,24 +181,21 @@ pub enum ContextType {
Empty, Empty,
} }
// TODO use the `colored` crate for color formatting
impl Display for ContextType { impl Display for ContextType {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
let purple = "\u{1b}[1;35m"; if let Some((left, right)) = match *self {
let green = "\u{1b}[0;32m"; ContextType::Screen(c) => Some(("screen_thread:", format!("{:?}", c))),
match *self { ContextType::Pty(c) => Some(("pty_thread:", format!("{:?}", c))),
ContextType::Screen(c) => write!(f, "{}screen_thread: {}{:?}", purple, green, c), ContextType::Plugin(c) => Some(("plugin_thread:", format!("{:?}", c))),
ContextType::Pty(c) => write!(f, "{}pty_thread: {}{:?}", purple, green, c), ContextType::Client(c) => Some(("main_thread:", format!("{:?}", c))),
ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), ContextType::IPCServer(c) => Some(("ipc_server:", format!("{:?}", c))),
ContextType::Client(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), ContextType::StdinHandler => Some(("stdin_handler_thread:", "AcceptInput".to_string())),
ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c), ContextType::AsyncTask => Some(("stream_terminal_bytes:", "AsyncTask".to_string())),
ContextType::StdinHandler => { ContextType::Empty => None,
write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) } {
} write!(f, "{} {}", left.purple(), right.green())
ContextType::AsyncTask => { } else {
write!(f, "{}stream_terminal_bytes: {}AsyncTask", purple, green) write!(f, "")
}
ContextType::Empty => write!(f, ""),
} }
} }
} }