Skip to content

Commit

Permalink
Upgrade tui -> raratui and other deps (#139)
Browse files Browse the repository at this point in the history
* libs: switch from tui (unmaintained) to ratatui, and update crossterm

* libs: upgrade non-git dependencies

* clippy: fix lints
  • Loading branch information
alexmaco committed Nov 2, 2023
1 parent 1ca4cb5 commit 16d906e
Show file tree
Hide file tree
Showing 18 changed files with 668 additions and 576 deletions.
963 changes: 529 additions & 434 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ default = []
nvidia = ["nvml-wrapper"]

[dependencies]
tui = { version = "0.19.*", features = ["crossterm"], default-features = false }
crossterm = "0.25.*"
byte-unit = "~4.0.17"
ratatui = { version = "0.23.*", features = ["crossterm"], default-features = false }
crossterm = "0.27.*"
byte-unit = "~4.0.19"
users = "0.11.0"
num-derive = "0.3.3"
num-derive = "0.4.1"
num-traits = "0.2"
heim = {git = "https://github.com/bvaisvil/heim.git", branch="zenith_changes", features = ["full"]}
futures = "0.3.21"
futures = "0.3.28"
gumdrop = { version = "~0.8.1", features = ["default_expr"] }
chrono = "~0.4.22"
chrono = "~0.4.31"
sysinfo = {git = "https://github.com/bvaisvil/sysinfo.git", branch="zenith_changes_15.1"}
dirs-next = "2.0.0"
serde = { version = "~1.0.147", features = ["derive"] }
serde_derive = "~1.0.147"
flate2 = "1.0.22"
serde = { version = "~1.0.189", features = ["derive"] }
serde_derive = "~1.0.189"
flate2 = "1.0.28"
bincode = "1.3.3"
starship-battery = "0.7.*"
signal-hook = "~0.3.14"
log = "~0.4.17"
starship-battery = "0.8.*"
signal-hook = "~0.3.17"
log = "~0.4.20"
env_logger = { version = "~0.10.0", default-features = false }
libc = "0.2"
nvml-wrapper = { version = "0.8.0", optional = true }
unicode-width = "0.1.9"
nvml-wrapper = { version = "0.9.0", optional = true }
unicode-width = "0.1.11"
[target.'cfg(target_os = "linux")'.dependencies]
linux-taskstats = { version = "0.4.0", default-features = false }
18 changes: 8 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,14 @@ fn start_zenith(
if !db_path.exists() {
debug!("Creating DB dir.");
fs::create_dir_all(db_path).expect("Couldn't Create DB dir.");
} else {
if !db_path.is_dir() {
exit_with_message!(
format!(
"Expected the path to be a directory not a file: {}",
db_path.to_string_lossy()
),
1
);
}
} else if !db_path.is_dir() {
exit_with_message!(
format!(
"Expected the path to be a directory not a file: {}",
db_path.to_string_lossy()
),
1
);
}
debug!("Creating Lock");

Expand Down
3 changes: 1 addition & 2 deletions src/metrics/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn get_device_name(dev: &OsStr) -> String {
path.to_string_lossy().to_string()
} else {
let mut np = PathBuf::new();
np.push(&dev);
np.push(dev);
np.pop();
np.push(path);
if let Ok(cp) = canonicalize(np) {
Expand Down Expand Up @@ -165,7 +165,6 @@ pub async fn get_disk_io_metrics(disks: &mut HashMap<String, ZDisk>) {
d.previous_io.read_bytes = d.current_io.read_bytes;
}
debug!("{:?}", d);
} else {
}
} else {
debug!("Couldn't get counters for a disk, skipping.")
Expand Down
6 changes: 3 additions & 3 deletions src/metrics/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ impl HistogramMap {
Some(db) => {
debug!("Opening DB");
let dbfile = db.join("store");
let hm = if dbfile.exists() {

if dbfile.exists() {
debug!("Zenith store exists, opening...");
load_zenith_store(&dbfile, &current_time)
} else {
Expand All @@ -147,8 +148,7 @@ impl HistogramMap {
db: Some(db),
previous_stop: None,
}
});
hm
})
}
None => {
debug!("Starting with no DB.");
Expand Down
20 changes: 10 additions & 10 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn get_max_pid() -> u64 {
if cfg!(target_os = "macos") {
99999
} else if cfg!(target_os = "linux") {
match fs::read(&Path::new("/proc/sys/kernel/pid_max")) {
match fs::read(Path::new("/proc/sys/kernel/pid_max")) {
Ok(data) => {
let r = String::from_utf8_lossy(data.as_slice());
r.trim().parse::<u64>().unwrap_or(32768)
Expand Down Expand Up @@ -347,15 +347,15 @@ impl CPUTimeApp {
gfx_devices: vec![],

#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml: nvml,
nvml,
#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml_error: ne,
#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml_driver_version: nvml_driver_version,
nvml_driver_version,
#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml_version: nvml_version,
nvml_version,
#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml_cuda_version: nvml_cuda_version,
nvml_cuda_version,
#[cfg(target_os = "linux")]
netlink_client: match Client::open() {
Ok(c) => Some(c),
Expand Down Expand Up @@ -660,7 +660,7 @@ impl CPUTimeApp {
}
}
let name = get_device_name(d.get_name());
let zd = self.disks.entry(name).or_insert(ZDisk::from_disk(&d));
let zd = self.disks.entry(name).or_insert(ZDisk::from_disk(d));
zd.size_bytes = d.get_total_space();
zd.available_bytes = d.get_available_space();
total_available += zd.available_bytes;
Expand All @@ -679,13 +679,13 @@ impl CPUTimeApp {

self.disk_read = self
.process_map
.iter()
.map(|(_pid, p)| p.get_read_bytes_sec(&self.histogram_map.tick) as u64)
.values()
.map(|p| p.get_read_bytes_sec(&self.histogram_map.tick) as u64)
.sum();
self.disk_write = self
.process_map
.iter()
.map(|(_pid, p)| p.get_write_bytes_sec(&self.histogram_map.tick) as u64)
.values()
.map(|p| p.get_write_bytes_sec(&self.histogram_map.tick) as u64)
.sum();

get_disk_io_metrics(&mut self.disks).await;
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/zprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl ProcessStatusExt for ProcessStatus {
}
}

#[cfg(all(any(unix), not(target_os = "macos")))]
#[cfg(all(unix, not(target_os = "macos")))]
fn to_single_char(&self) -> &str {
match *self {
ProcessStatus::Idle => "I",
Expand Down
20 changes: 10 additions & 10 deletions src/renderer/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::metrics::histogram::{HistogramKind, View};
use crate::metrics::CPUTimeApp;
use crate::renderer::{percent_of, split_left_right_pane, Render, ZBackend};
use byte_unit::{Byte, ByteUnit};
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{BarChart, Block, Borders, Paragraph, Sparkline, Wrap};
use tui::Frame;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{BarChart, Block, Borders, Paragraph, Sparkline, Wrap};
use ratatui::Frame;

fn cpu_title<'a>(app: &'a CPUTimeApp, histogram: &'a [u64]) -> Spans<'a> {
fn cpu_title<'a>(app: &'a CPUTimeApp, histogram: &'a [u64]) -> Line<'a> {
let top_process_name = match &app.cum_cpu_process {
Some(p) => p.name.as_str(),
None => "",
Expand Down Expand Up @@ -46,7 +46,7 @@ fn cpu_title<'a>(app: &'a CPUTimeApp, histogram: &'a [u64]) -> Spans<'a> {
} else {
String::from("")
};
Spans(vec![
Line::from(vec![
Span::raw("CPU ["),
Span::styled(
format!("{: >3}%", app.cpu_utilization),
Expand Down Expand Up @@ -75,7 +75,7 @@ fn cpu_title<'a>(app: &'a CPUTimeApp, histogram: &'a [u64]) -> Spans<'a> {
])
}

fn mem_title(app: &CPUTimeApp) -> Spans {
fn mem_title(app: &CPUTimeApp) -> Line {
let mem = percent_of(app.mem_utilization, app.mem_total) as u64;
let swp = percent_of(app.swap_utilization, app.swap_total) as u64;

Expand All @@ -87,7 +87,7 @@ fn mem_title(app: &CPUTimeApp) -> Spans {
None => String::from(""),
};

Spans(vec![
Line::from(vec![
Span::raw("MEM ["),
Span::styled(
format!(
Expand Down Expand Up @@ -195,7 +195,7 @@ fn render_cpu_bars(app: &CPUTimeApp, area: Rect, f: &mut Frame<'_, ZBackend>, st
});
}

Paragraph::new(Spans::from(items))
Paragraph::new(Line::from(items))
.wrap(Wrap { trim: false })
.render(f, layout[0]);

Expand Down
28 changes: 14 additions & 14 deletions src/renderer/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::float_to_byte_string;
use crate::metrics::histogram::{HistogramKind, View};
use crate::metrics::CPUTimeApp;
use byte_unit::{Byte, ByteUnit};
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, Sparkline};
use ratatui::Frame;
use std::borrow::Cow;
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, Borders, List, ListItem, Paragraph, Sparkline};
use tui::Frame;

pub fn render_disk(
app: &CPUTimeApp,
Expand Down Expand Up @@ -171,7 +171,7 @@ fn disk_activity_histogram(
}

Sparkline::default()
.block(Block::default().title(Spans::from(spans)))
.block(Block::default().title(Line::from(spans)))
.data(h_read.data())
.style(Style::default().fg(Color::LightYellow))
.max(read_max)
Expand Down Expand Up @@ -240,19 +240,19 @@ fn disk_usage(
.split(area[1]);
let rhs_style = Style::default().fg(Color::Green);
let text = vec![
Spans::from(vec![
Line::from(vec![
Span::raw("Device: ".to_string()),
Span::styled(fs.name.to_string(), rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("File System: ".to_string()),
Span::styled(fs.file_system.to_string(), rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Mount Point: ".to_string()),
Span::styled(fs.mount_point.to_string_lossy(), rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Read: ".to_string()),
Span::styled(
format!(
Expand All @@ -269,19 +269,19 @@ fn disk_usage(
];
Paragraph::new(text).render(f, columns[0]);
let text = vec![
Spans::from(vec![
Line::from(vec![
Span::raw("Size: ".to_string()),
Span::styled(size, rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Used: ".to_string()),
Span::styled(used, rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Free: ".to_string()),
Span::styled(free, rhs_style),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Write: ".to_string()),
Span::styled(
format!(
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::float_to_byte_string;
use crate::metrics::histogram::{HistogramKind, View};
use crate::metrics::CPUTimeApp;
use byte_unit::{Byte, ByteUnit};
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, List, ListItem, Sparkline};
use ratatui::Frame;
use std::borrow::Cow;
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, Borders, List, ListItem, Sparkline};
use tui::Frame;

pub fn render_graphics(
app: &CPUTimeApp,
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn render_graphics(
) {
format!(" VER [DRIVER: {:} CUDA: {:} NVML: {:}]", dv, cv, nv)
} else {
format!("")
String::new()
};
Sparkline::default()
.block(
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn render_graphics(
};

Sparkline::default()
.block(Block::default().title(Spans(vec![
.block(Block::default().title(Line::from(vec![
Span::raw(
format!(
"FB [{:3.0}%] MEM [{:} / {:} - {:}%] {:}",
Expand Down
Loading

0 comments on commit 16d906e

Please sign in to comment.