From 1123a99aeaf71af800e22c32a240b579dfb59b30 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 26 Mar 2025 18:00:54 +0000 Subject: [PATCH] fix(cli): Improve console output formatting for status banners and logging messages --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/daemon.ts | 12 ++++++------ ts/nupst.ts | 2 +- ts/systemd.ts | 8 ++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index c127446..22ca2aa 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-03-26 - 2.6.9 - fix(cli) +Improve console output formatting for status banners and logging messages + +- Standardize banner messages in daemon status updates +- Refine version information banner in nupst logging +- Update UPS connection and status banners in systemd + ## 2025-03-26 - 2.6.8 - fix(cli) Improve CLI formatting, refine debug option filtering, and remove unused dgram import in SNMP manager diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 8b80f29..c0cd08e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/nupst', - version: '2.6.8', + version: '2.6.9', description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' } diff --git a/ts/daemon.ts b/ts/daemon.ts index 204b6f7..b513fa8 100644 --- a/ts/daemon.ts +++ b/ts/daemon.ts @@ -226,8 +226,8 @@ export class NupstDaemon { // Log status changes if (status.powerStatus !== lastStatus) { - console.log('┌──────────────────────────────────────────┐'); - console.log(`│ Power status changed: ${lastStatus} → ${status.powerStatus}`); + console.log('┌─ Power Status Change ─────────────────────┐'); + console.log(`│ Status changed: ${lastStatus} → ${status.powerStatus}`); console.log('└──────────────────────────────────────────┘'); lastStatus = status.powerStatus; lastLogTime = currentTime; // Reset log timer when status changes @@ -235,8 +235,8 @@ export class NupstDaemon { // Log status periodically (at least every 5 minutes) else if (shouldLogStatus) { const timestamp = new Date().toISOString(); - console.log('┌──────────────────────────────────────────┐'); - console.log(`│ [${timestamp}] Periodic Status Update`); + console.log('┌─ Periodic Status Update ──────────────────┐'); + console.log(`│ Timestamp: ${timestamp}`); console.log(`│ Power Status: ${status.powerStatus}`); console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`); console.log('└──────────────────────────────────────────┘'); @@ -267,8 +267,8 @@ export class NupstDaemon { batteryCapacity: number, batteryRuntime: number }): Promise { - console.log('┌─ UPS Status ───────────────────────────────┐'); - console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min │`); + console.log('┌─ UPS Status ────────────────────────────┐'); + console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`); console.log('└──────────────────────────────────────────┘'); // Check battery threshold diff --git a/ts/nupst.ts b/ts/nupst.ts index eded8c9..b9d1299 100644 --- a/ts/nupst.ts +++ b/ts/nupst.ts @@ -162,7 +162,7 @@ export class Nupst { */ public logVersionInfo(checkForUpdates: boolean = true): void { const version = this.getVersion(); - console.log('┌─ NUPST Version ────────────────────────┐'); + console.log('┌─ NUPST Version ────────────────────────────┐'); console.log(`│ Current Version: ${version}`); if (this.updateAvailable && this.latestVersion) { diff --git a/ts/systemd.ts b/ts/systemd.ts index 81dccc8..ff8c0d1 100644 --- a/ts/systemd.ts +++ b/ts/systemd.ts @@ -190,20 +190,20 @@ WantedBy=multi-user.target timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check }; - console.log('┌─ Connecting to UPS... ────────────────────┐'); + console.log('┌─ Connecting to UPS... ─────────────────────┐'); console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`); console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`); - console.log('└──────────────────────────────────────────┘'); + console.log('└────────────────────────────────────────────┘'); const status = await snmp.getUpsStatus(snmpConfig); - console.log('┌─ UPS Status ───────────────────────────────┐'); + console.log('┌─ UPS Status ─────────────────────────────┐'); console.log(`│ Power Status: ${status.powerStatus}`); console.log(`│ Battery Capacity: ${status.batteryCapacity}%`); console.log(`│ Runtime Remaining: ${status.batteryRuntime} minutes`); console.log('└──────────────────────────────────────────┘'); } catch (error) { - console.error('┌─ UPS Status ───────────────────────────────┐'); + console.error('┌─ UPS Status ─────────────────────────────┐'); console.error(`│ Failed to retrieve UPS status: ${error.message}`); console.error('└──────────────────────────────────────────┘'); }