Просмотр исходного кода

util/cli: Add helper functions for colored text.

parazyd 4 лет назад
Родитель
Сommit
055113a846
1 измененных файлов с 9 добавлено и 0 удалено
  1. 9 0
      src/util/cli.rs

+ 9 - 0
src/util/cli.rs

@@ -10,6 +10,7 @@ use std::{
 use indicatif::{ProgressBar, ProgressStyle};
 use serde::{de::DeserializeOwned, Serialize};
 use simplelog::ConfigBuilder;
+use termion::color;
 
 use crate::{Error, Result};
 
@@ -208,3 +209,11 @@ pub fn progress_bar(message: &str) -> ProgressBar {
     progress_bar.set_message(message.to_string());
     progress_bar
 }
+
+pub fn fg_red(message: &str) -> String {
+    format!("{}{}{}", color::Fg(color::Red), message, color::Fg(color::Reset))
+}
+
+pub fn fg_green(message: &str) -> String {
+    format!("{}{}{}", color::Fg(color::Green), message, color::Fg(color::Reset))
+}