From 81714dfdc092be3fbdb9a21578439eef455d2023 Mon Sep 17 00:00:00 2001 From: murmeldin Date: Mon, 5 Aug 2024 19:57:12 +0200 Subject: [PATCH] colored std-output for better readability --- src/email.rs | 6 ++++-- src/key_value.rs | 8 +++++--- src/main.rs | 19 ++++++++++++++++--- src/mediawiki.rs | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/email.rs b/src/email.rs index d7b2353..13f783e 100644 --- a/src/email.rs +++ b/src/email.rs @@ -1,5 +1,6 @@ use std::error::Error; +use colored::Colorize; use lettre::{Message, SmtpTransport, Transport}; use lettre::message::{header, SinglePart}; use lettre::transport::smtp::authentication::Credentials; @@ -104,8 +105,9 @@ impl Email { Ok(message_id) } else { println!( - "[DRY RUN - NOT sending email]\n(raw message:)\n{}", - std::str::from_utf8(&email.formatted()).unwrap_or("((UTF-8 error))") + "{}\n(raw message:)\n{}", + "[DRY RUN - NOT sending email]".yellow(), + std::str::from_utf8(&email.formatted()).unwrap_or("((UTF-8 error))").blue() ); Ok("dummy-message-id@localhost".to_string()) } diff --git a/src/key_value.rs b/src/key_value.rs index 0a605bb..14984d1 100644 --- a/src/key_value.rs +++ b/src/key_value.rs @@ -16,11 +16,13 @@ //! let all_ok = !cfg.has_errors(); //! ``` -use rusqlite::{params, Connection, Result}; use std::cell::Cell; use std::collections::HashSet; use std::ops::Index; +use colored::Colorize; +use rusqlite::{Connection, params, Result}; + /// Simple SQLite-backed key/value store. /// /// All failing writes will log a message, any errors will set `has_errors`. @@ -122,10 +124,10 @@ impl KeyValueStore { while let Some(row) = rows.next()? { let key: String = row.get(0)?; if exclude_set.contains(key.as_str()) { - eprintln!("{} = REDACTED", key); + eprintln!("{}{}", key, " = REDACTED".blue()); } else { let value: String = row.get(1)?; - eprintln!("{} = {}", key, value); + eprintln!("{}{}{}", key, " = ".blue(), value.blue()); } } Ok(()) diff --git a/src/main.rs b/src/main.rs index 3a775f7..af06a4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::error::Error; use chrono::{Datelike, Local, NaiveDate, Weekday}; use clap::{Arg, Command}; +use colored::Colorize; use regex::Regex; use reqwest::blocking::Client; @@ -133,6 +134,19 @@ fn parse_args() -> Args { fn main() -> Result<(), Box> { // set up config file access + + let ansi_art = r#" + _____ _____ _____ ____ _____ _ ____ _ + / ____/ ____/ ____| _ \ | __ \| | | _ \ | | + | | | | | | | |_) | | |__) | | ___ _ __ _ _ _ __ ___ | |_) | ___ | |_ + | | | | | | | _ < | ___/| |/ _ \ '_ \| | | | '_ ` _ \| _ < / _ \| __| + | |___| |___| |____| |_) | | | | | __/ | | | |_| | | | | | | |_) | (_) | |_ + \_____\_____\_____|____/ |_| |_|\___|_| |_|\__,_|_| |_| |_|____/ \___/ \__| + +"#; + + println!("{}", ansi_art.red()); + let args = parse_args(); let config_file = args.config_file.as_str(); let config = KV::new(config_file).unwrap(); @@ -154,7 +168,7 @@ fn main() -> Result<(), Box> { &config["email-to"], config.get("email-in-reply-to").ok(), ); - println!("[START]\nAktueller Zustand der DB:"); + println!("[START]\n{}", "Aktueller Zustand der DB:".bold()); config.dump_redacting(&["email-password", "wiki-http-password", "wiki-api-secret", "matrix-password"]).ok(); // Dienstage diesen Monat @@ -332,8 +346,7 @@ Und hier ist das Protokoll des letzten Plenums: mediawiki::pad_ins_wiki(old_pad_content_without_top_instructions); } println!("message id: {:?}", message_id); - - println!("[ENDE]\nAktueller Zustand der DB:"); + println!("[ENDE]\n{}", "Aktueller Zustand der DB:".bold()); config.dump_redacting(&["email-password", "wiki-http-password", "wiki-api-secret", "matrix-password"]).ok(); if config.has_errors() { diff --git a/src/mediawiki.rs b/src/mediawiki.rs index 63a9f2b..264caaf 100644 --- a/src/mediawiki.rs +++ b/src/mediawiki.rs @@ -3,7 +3,6 @@ use std::fs::File; use std::io::Read; use pandoc::{PandocError, PandocOutput}; -use reqwest; use reqwest::blocking::Client; use serde::Deserialize; @@ -105,3 +104,4 @@ pub fn get_login_token(client: &Client, http_user: &str, http_pass: &String) -> let response_deserialized: QueryResponse = serde_json::from_str(&resp)?; Ok(response_deserialized.query.tokens.logintoken) } +