Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move graph #486

Merged
merged 2 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use super::config::{config_dir_exists, init_config};
use super::daemon;
use super::daemon::daemon_init;
use super::display::show_config;
use super::graph::{get_graph_type, GraphType};
use super::interactive::interactive;
use super::interface::{DaemonControl, DaemonController, Get, Getter, Interface, Set, Setter};
use super::settings::{get_graph_type, GraphType, Settings};
use super::settings::Settings;
use super::warn_user;

#[derive(StructOpt)]
Expand Down
4 changes: 2 additions & 2 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ use serde::Serialize;

use super::config::Config;
use super::cpu::{Speed, CPU};
use super::graph::{Graph, Grapher};
use super::graph::{Graph, GraphType, Grapher};
use super::logger;
use super::logger::Interface;
use super::network::{hook, listen};
use super::power::battery::{has_battery, Battery};
use super::power::lid::{Lid, LidRetriever, LidState};
use super::power::{Power, PowerRetriever};
use super::settings::{GraphType, Settings};
use super::settings::Settings;
use super::setup::{inside_docker_message, inside_wsl_message};
use super::system::{
check_available_governors, check_cpu_freq, check_cpu_temperature, check_cpu_usage,
Expand Down
33 changes: 33 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rasciigraph::{plot, Config};
use std::fmt;

pub trait Grapher {
fn update_all(&mut self);
Expand Down Expand Up @@ -34,3 +35,35 @@ impl Grapher for Graph {
)
}
}

#[derive(PartialEq, Eq, Clone)]
pub enum GraphType {
Hidden,
Frequency,
Usage,
Temperature,
Unknown,
}

impl fmt::Display for GraphType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
GraphType::Hidden => write!(f, "hidden"),
GraphType::Frequency => write!(f, "frequency"),
GraphType::Usage => write!(f, "usage"),
GraphType::Temperature => write!(f, "temperature"),
GraphType::Unknown => write!(f, "unknown"),
}
}
}

/// Parse from graph_type parameter which type of graph will be displayed
pub fn get_graph_type(graph_type: &str) -> GraphType {
match graph_type.to_lowercase().as_str() {
"hidden" => GraphType::Hidden,
"freq" => GraphType::Frequency,
"usage" => GraphType::Usage,
"temp" => GraphType::Temperature,
_ => GraphType::Unknown,
}
}
3 changes: 2 additions & 1 deletion src/interactive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::config::{get_config, Config};
use super::graph::GraphType;
use super::interface::{DaemonControl, DaemonController, Get, Getter, Interface, Set, Setter};
use super::settings::{GraphType, Settings};
use super::settings::Settings;
use colored::Colorize;
use std::io::{stdin, stdout, Write};

Expand Down
34 changes: 1 addition & 33 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
use std::fmt;

#[derive(PartialEq, Eq, Clone)]
pub enum GraphType {
Hidden,
Frequency,
Usage,
Temperature,
Unknown,
}

impl fmt::Display for GraphType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
GraphType::Hidden => write!(f, "hidden"),
GraphType::Frequency => write!(f, "frequency"),
GraphType::Usage => write!(f, "usage"),
GraphType::Temperature => write!(f, "temperature"),
GraphType::Unknown => write!(f, "unknown"),
}
}
}

/// Parse from graph_type parameter which type of graph will be displayed
pub fn get_graph_type(graph_type: &str) -> GraphType {
match graph_type.to_lowercase().as_str() {
"hidden" => GraphType::Hidden,
"freq" => GraphType::Frequency,
"usage" => GraphType::Usage,
"temp" => GraphType::Temperature,
_ => GraphType::Unknown,
}
}
use super::graph::GraphType;

#[derive(Clone)]
pub struct Settings {
Expand Down