Used Claude Sonnet 3.5 agent to add license and documentation to all
files in the project
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
name = "unibar"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@@ -1,3 +1,30 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! CPU usage monitoring module for Unibar
|
||||
//!
|
||||
//! This module tracks CPU utilization by sampling /proc/stat and calculating
|
||||
//! the percentage of time spent in different CPU states. It provides real-time
|
||||
//! CPU usage information for display in the status bar.
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
use std::thread;
|
||||
@@ -6,6 +33,11 @@ use std::time::Duration;
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Represents CPU time spent in various states
|
||||
///
|
||||
/// This struct holds counters for different CPU states as reported by /proc/stat.
|
||||
/// Each field represents the amount of time the CPU has spent in that particular state
|
||||
/// since system boot, measured in USER_HZ units (typically 100Hz).
|
||||
#[derive(Debug, Default, Clone)]
|
||||
struct CpuTimes {
|
||||
user: u64,
|
||||
|
@@ -1,7 +1,40 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Date module for Unibar
|
||||
//!
|
||||
//! This module displays the current date in a formatted string.
|
||||
//! It updates automatically to show the current date with month,
|
||||
//! day, and year information.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Formatted date display
|
||||
//! - Automatic daily updates
|
||||
//! - Calendar icon
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Date display module showing current calendar date
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModuleDate {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,3 +1,35 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Memory module for Unibar
|
||||
//!
|
||||
//! This module monitors system memory usage by reading /proc/meminfo.
|
||||
//! It calculates and displays current memory utilization as a percentage
|
||||
//! of total available memory.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Real-time memory usage monitoring
|
||||
//! - Percentage-based display
|
||||
//! - Automatic updates at configured intervals
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::io::prelude::*;
|
||||
@@ -6,6 +38,7 @@ use regex::Regex;
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Memory monitor that displays current system memory usage
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModuleMemory {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,8 +1,42 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Music module for Unibar
|
||||
//!
|
||||
//! This module displays current music playback information.
|
||||
//! It shows the currently playing track and playback progress
|
||||
//! using the system's music player.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Current track information
|
||||
//! - Playback progress
|
||||
//! - Playback state (playing/paused)
|
||||
//! - Music note icon
|
||||
|
||||
use std::process::{Stdio, Command};
|
||||
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Music playback monitor showing current track and progress
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModuleMusic {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,3 +1,36 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Network module for Unibar
|
||||
//!
|
||||
//! This module monitors network interfaces and displays current connection status
|
||||
//! and IP addresses. It supports both wireless and ethernet interfaces, with
|
||||
//! different icons for each connection type.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Automatic interface detection
|
||||
//! - Priority-based interface selection (ethernet over wireless)
|
||||
//! - IP address display
|
||||
//! - Connection status monitoring
|
||||
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use std::process::{Stdio, Command};
|
||||
@@ -5,6 +38,7 @@ use std::process::{Stdio, Command};
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Network interface monitor that displays connection status and IP addresses
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModuleNetwork {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,10 +1,42 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Power module for Unibar
|
||||
//!
|
||||
//! This module monitors system power status using UPower.
|
||||
//! It displays battery level and charging status with appropriate icons.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Battery level monitoring
|
||||
//! - Charging status detection
|
||||
//! - Different icons for charging/discharging states
|
||||
//! - Automatic updates
|
||||
|
||||
use std::process::{Stdio, Command};
|
||||
//use std::collections::HashMap;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
|
||||
/// Power monitor that displays battery status and level
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModulePower {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,8 +1,42 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Time module for Unibar
|
||||
//!
|
||||
//! This module displays the current time with timezone information.
|
||||
//! It automatically updates to show the current time in 12-hour format
|
||||
//! with AM/PM indicator.
|
||||
//!
|
||||
//! # Features
|
||||
//! - 12-hour time format with AM/PM
|
||||
//! - Timezone display
|
||||
//! - Automatic updates
|
||||
//! - Unicode clock icon
|
||||
|
||||
use chrono::{DateTime, TimeZone, Local, Utc};
|
||||
use crate::common;
|
||||
use crate::bar_modules;
|
||||
use chrono_tz::{OffsetName, Tz};
|
||||
|
||||
/// Time display module showing current time and timezone
|
||||
#[derive(Clone)]
|
||||
pub struct UnibarModuleTime {
|
||||
opts: common::AppOptions,
|
||||
|
@@ -1,3 +1,35 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Weather module for Unibar
|
||||
//!
|
||||
//! Fetches weather data from the National Weather Service API and displays
|
||||
//! current temperature and conditions using Unicode weather symbols.
|
||||
//!
|
||||
//! # Features
|
||||
//! - Temperature display in Celsius or Fahrenheit
|
||||
//! - Automatic updates at configurable intervals
|
||||
//! - Weather condition icons using Unicode symbols
|
||||
//! - Robust error handling for API interactions
|
||||
|
||||
use std::str;
|
||||
use curl::easy::{Easy, List};
|
||||
use serde_json::json;
|
||||
|
@@ -1,7 +1,38 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Bar modules for the Unibar status bar
|
||||
//!
|
||||
//! This module contains implementations of various status bar components that
|
||||
//! display system information like weather, CPU usage, memory, etc.
|
||||
//!
|
||||
//! Each module implements the `BarModuleActions` trait which defines the core
|
||||
//! functionality required for status bar components.
|
||||
|
||||
use crate::common::UpdateResult;
|
||||
|
||||
// --------------------
|
||||
/// All Bar modules must implement the actions
|
||||
/// Core trait that must be implemented by all bar modules.
|
||||
///
|
||||
/// This trait defines the interface that every status bar component must implement
|
||||
/// to provide its functionality to the Unibar system.
|
||||
pub trait BarModuleActions {
|
||||
/// Returns the name of the module
|
||||
fn get_name(&self) -> String;
|
||||
|
95
src/main.rs
95
src/main.rs
@@ -1,23 +1,68 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2025 Mahesh @ HeshApps
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Unibar - A Versatile Status Bar Information Provider
|
||||
//!
|
||||
//! Unibar is a customizable status bar information provider that displays various
|
||||
//! system metrics and information in a format suitable for integration with
|
||||
//! status bars like i3bar, polybar, or similar tools.
|
||||
//!
|
||||
//! # Features
|
||||
//! - System monitoring (CPU, memory, network)
|
||||
//! - Power management (battery status, charging)
|
||||
//! - Weather information
|
||||
//! - Date and time display
|
||||
//! - Music playback information
|
||||
//! - Configurable update intervals
|
||||
//! - Support for both metric and imperial units
|
||||
//!
|
||||
//! # Usage
|
||||
//! ```bash
|
||||
//! unibar --interval 1 --weather-station khio --weather-metric
|
||||
//! ```
|
||||
//!
|
||||
//! The output is formatted as a string that can be directly used
|
||||
//! by status bar applications.
|
||||
|
||||
use std::str;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use clap::Parser;
|
||||
use crate::common::UpdateResult;
|
||||
|
||||
// Common utilities/types
|
||||
/// Common utilities and types used across modules
|
||||
mod common;
|
||||
// Bar Modules
|
||||
/// Status bar component modules
|
||||
mod bar_modules;
|
||||
|
||||
// Commandline parsing
|
||||
/// Command-line arguments for configuring Unibar behavior
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "unibar")]
|
||||
#[command(version = "1.0")]
|
||||
#[command(about = "Get string of info for a status bar")]
|
||||
#[command(about, long_about = "A tool that returns variety of components in a string
|
||||
suitable to use in a status bar")]
|
||||
#[command(about = "A versatile status bar information provider")]
|
||||
#[command(long_about = "Unibar provides system information, weather, and other metrics \
|
||||
in a format suitable for status bars. It supports various modules including \
|
||||
system monitoring, weather information, and music playback status.")]
|
||||
struct CommandlineArgs {
|
||||
/// Update interval in seconds
|
||||
/// The frequency at which information is updated, in seconds.
|
||||
/// Lower values provide more frequent updates but increase system load.
|
||||
#[arg(short = 'i', long, default_value = "1")]
|
||||
interval: u64,
|
||||
|
||||
@@ -52,14 +97,25 @@ struct CommandlineArgs {
|
||||
// Application (Unibar)
|
||||
//
|
||||
//#[derive(Clone)]
|
||||
/// Main application structure that manages all status bar modules
|
||||
/// and coordinates their updates.
|
||||
struct Unibar {
|
||||
opts: common::AppOptions,
|
||||
bar_modules_enabled: Vec<Box<dyn bar_modules::BarModuleActions>>,
|
||||
debug_modules_done: bool,
|
||||
/// Application-wide configuration options
|
||||
opts: common::AppOptions,
|
||||
/// List of active status bar modules
|
||||
bar_modules_enabled: Vec<Box<dyn bar_modules::BarModuleActions>>,
|
||||
/// Flag to track if module debugging has been performed
|
||||
debug_modules_done: bool,
|
||||
}
|
||||
|
||||
impl Unibar {
|
||||
// --------------------
|
||||
/// Starts the main application loop, initializing all modules and
|
||||
/// updating them at the configured interval.
|
||||
///
|
||||
/// This function:
|
||||
/// 1. Initializes all enabled modules
|
||||
/// 2. Enters an infinite loop for updates
|
||||
/// 3. Coordinates module updates based on their individual timing requirements
|
||||
fn run(&mut self) {
|
||||
if self.opts.debug {
|
||||
self.debug_msg("Debugging ...");
|
||||
@@ -163,9 +219,18 @@ impl Unibar {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Entry point
|
||||
//
|
||||
/// Main entry point for the Unibar application.
|
||||
///
|
||||
/// This function:
|
||||
/// 1. Parses command-line arguments
|
||||
/// 2. Creates and configures the main application instance
|
||||
/// 3. Starts the application loop
|
||||
///
|
||||
/// # Example
|
||||
/// ```bash
|
||||
/// # Run with metric units and 1-second updates
|
||||
/// unibar --interval 1 --weather-metric
|
||||
/// ```
|
||||
fn main() {
|
||||
let cmd_args = CommandlineArgs::parse();
|
||||
let mut app = Unibar {
|
||||
|
Reference in New Issue
Block a user