Version 0.1.12, refactorings

This commit is contained in:
Stephen Seo 2023-05-21 15:08:19 +09:00
parent c12dafab07
commit 7db4b850b4
5 changed files with 24 additions and 13 deletions

2
Cargo.lock generated
View file

@ -141,7 +141,7 @@ dependencies = [
[[package]]
name = "swaybar_info"
version = "0.1.11"
version = "0.1.12"
dependencies = [
"chrono",
"regex",

View file

@ -1,6 +1,6 @@
[package]
name = "swaybar_info"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
description = "Provides swaybar with info to be displayed"
license = "MIT"

View file

@ -2,6 +2,10 @@
## Upcoming Changes
## 0.1.12
Some refactoring of the code related to colorizing the netgraph.
## 0.1.11
Use pango markup to colorize the netgraph, making it look cleaner.

View file

@ -4,6 +4,7 @@ mod external;
mod proc;
mod swaybar_object;
use std::fmt::Write as FMTWrite;
use std::io::{self, Write};
use std::time::Duration;
use swaybar_object::*;
@ -287,19 +288,25 @@ fn main() {
for item in graph_items.iter() {
match item.get_value_type() {
proc::GraphItemType::Download => {
text += &("<span color=\"#ff8888ff\">".to_owned()
+ &item.get_value().to_string()
+ "</span>");
write!(
&mut text,
"<span color=\"#ff8888ff\">{}</span>",
item.get_value()
)?;
}
proc::GraphItemType::Upload => {
text += &("<span color=\"#88ff88ff\">".to_owned()
+ &item.get_value().to_string()
+ "</span>");
write!(
&mut text,
"<span color=\"#88ff88ff\">{}</span>",
item.get_value()
)?;
}
proc::GraphItemType::Both => {
text += &("<span color=\"#ffff88ff\">".to_owned()
+ &item.get_value().to_string()
+ "</span>");
write!(
&mut text,
"<span color=\"#ffff88ff\">{}</span>",
item.get_value()
)?;
}
}
}

View file

@ -180,7 +180,7 @@ impl NetInfo {
pub fn get_netstring(
&mut self,
graph_max_opt: Option<f64>,
) -> Result<(String, Vec<GraphItem>, usize, String), Error> {
) -> Result<(String, &Vec<GraphItem>, usize, String), Error> {
let down_diff: f64 = if self.down > self.prev_down {
let value = (self.down - self.prev_down) as f64;
self.prev_down = self.down;
@ -333,7 +333,7 @@ impl NetInfo {
}
}
Ok((output, self.graph.clone(), history_max_idx, diff_max_string))
Ok((output, &self.graph, history_max_idx, diff_max_string))
}
}