From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B25D0AECA for ; Wed, 28 Jun 2023 18:01:20 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9BC0A1A0A4 for ; Wed, 28 Jun 2023 18:01:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 28 Jun 2023 18:01:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B1E5641D78 for ; Wed, 28 Jun 2023 18:01:19 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 28 Jun 2023 18:01:01 +0200 Message-Id: <20230628160101.1765-4-c.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230628160101.1765-1-c.ebner@proxmox.com> References: <20230628160101.1765-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -2.422 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SOMETLD_ARE_BAD_TLD 5 .bar, .beauty, .buzz, .cam, .casa, .cfd, .club, .date, .guru, .link, .live, .online, .press, .pw, .quest, .rest, .sbs, .shop, .stream, .top, .trade, .work, .xyz TLD abuse PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_PDS_OTHER_BAD_TLD 0.01 Untrustworthy TLDs T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH v2 backup stable-2 3/3] pbs2to3: set failure messages to bold X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jun 2023 16:01:20 -0000 ... and reset instead of setting color to clear settings Signed-off-by: Christian Ebner --- src/bin/pbs2to3.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/bin/pbs2to3.rs b/src/bin/pbs2to3.rs index d85551ec..8ff13b47 100644 --- a/src/bin/pbs2to3.rs +++ b/src/bin/pbs2to3.rs @@ -485,19 +485,22 @@ impl ConsoleOutput { Ok(()) } - pub fn set_color(&mut self, color: Color) -> Result<(), Error> { + pub fn set_color(&mut self, color: Color, bold: bool) -> Result<(), Error> { self.stream - .set_color(ColorSpec::new().set_fg(Some(color)))?; + .set_color(ColorSpec::new().set_fg(Some(color)).set_bold(bold))?; Ok(()) } + pub fn reset(&mut self) -> Result<(), std::io::Error> { + self.stream.reset() + } + pub fn log_line(&mut self, level: LogLevel, message: &str) -> Result<(), Error> { match level { LogLevel::Pass => { self.counters.pass += 1; - self.set_color(Color::Green)?; + self.set_color(Color::Green, false)?; writeln!(&mut self.stream, "PASS: {}", message)?; - self.set_color(Color::White)?; } LogLevel::Info => { writeln!(&mut self.stream, "INFO: {}", message)?; @@ -508,21 +511,21 @@ impl ConsoleOutput { } LogLevel::Notice => { self.counters.notice += 1; + self.set_color(Color::White, true)?; writeln!(&mut self.stream, "NOTICE: {}", message)?; } LogLevel::Warn => { self.counters.warn += 1; - self.set_color(Color::Yellow)?; + self.set_color(Color::Yellow, true)?; writeln!(&mut self.stream, "WARN: {}", message)?; - self.set_color(Color::White)?; } LogLevel::Fail => { self.counters.fail += 1; - self.set_color(Color::Red)?; + self.set_color(Color::Red, true)?; writeln!(&mut self.stream, "FAIL: {}", message)?; - self.set_color(Color::White)?; } } + self.reset()?; Ok(()) } @@ -559,28 +562,28 @@ impl ConsoleOutput { + self.counters.skip + self.counters.warn; - self.set_color(Color::White)?; writeln!(&mut self.stream, "TOTAL: {total}")?; - self.set_color(Color::Green)?; + self.set_color(Color::Green, false)?; writeln!(&mut self.stream, "PASSED: {}", self.counters.pass)?; - self.set_color(Color::White)?; + self.reset()?; writeln!(&mut self.stream, "SKIPPED: {}", self.counters.skip)?; writeln!(&mut self.stream, "NOTICE: {}", self.counters.notice)?; if self.counters.warn > 0 { - self.set_color(Color::Yellow)?; + self.set_color(Color::Yellow, false)?; writeln!(&mut self.stream, "WARNINGS: {}", self.counters.warn)?; } if self.counters.fail > 0 { - self.set_color(Color::Red)?; + self.set_color(Color::Red, true)?; writeln!(&mut self.stream, "FAILURES: {}", self.counters.fail)?; } if self.counters.warn > 0 || self.counters.fail > 0 { - let mut color = Color::Yellow; - if self.counters.fail > 0 { - color = Color::Red; - } + let (color, bold) = if self.counters.fail > 0 { + (Color::Red, true) + } else { + (Color::Yellow, false) + }; - self.set_color(color)?; + self.set_color(color, bold)?; writeln!( &mut self.stream, "\nATTENTION: Please check the output for detailed information!", @@ -592,7 +595,7 @@ impl ConsoleOutput { )?; } } - self.set_color(Color::White)?; + self.reset()?; Ok(()) } } -- 2.30.2