mirror of
https://github.com/danog/ytop.git
synced 2024-11-26 20:15:03 +01:00
Implement statusbar
This commit is contained in:
parent
d199684254
commit
54005dc4a7
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -649,6 +649,15 @@ name = "hex"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hostname"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iovec"
|
||||
version = "0.1.2"
|
||||
@ -1037,6 +1046,7 @@ dependencies = [
|
||||
"fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heim 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1490,6 +1500,14 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winutil"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ws2_32-sys"
|
||||
version = "0.2.1"
|
||||
@ -1570,6 +1588,7 @@ dependencies = [
|
||||
"checksum heim-process 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7151d91b7df657cd5da777041641915ea5f654846a70bb86b4807b73bf7bcc43"
|
||||
"checksum heim-virt 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "dca300f1b1d3270dd42f0f1f524b516c1257dd9aa5d03868218734f0095d3b34"
|
||||
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
|
||||
"checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e"
|
||||
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
|
||||
"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
|
||||
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
|
||||
@ -1665,4 +1684,5 @@ dependencies = [
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e"
|
||||
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
|
||||
|
@ -14,6 +14,7 @@ ctrlc = { version = "3.1.3", features = ["termination"] }
|
||||
fern = "0.5.8"
|
||||
futures-preview = { version = "=0.3.0-alpha.17", features = ["async-await", "nightly"] }
|
||||
heim = "0.0.4"
|
||||
hostname = "0.1.5"
|
||||
lazy_static = "1.3.0"
|
||||
log = "0.4.7"
|
||||
num_cpus = "1.10.1"
|
||||
|
@ -91,7 +91,7 @@ async fn main() {
|
||||
let logfile_path = app_dirs.state_dir.join("errors.log");
|
||||
|
||||
let colorscheme = read_colorscheme(&app_dirs.config_dir, &args.colorscheme).unwrap();
|
||||
let mut app = setup_app(&args, update_ratio, &colorscheme);
|
||||
let mut app = setup_app(&args, update_ratio, &colorscheme, program_name);
|
||||
|
||||
setup_logfile(&logfile_path);
|
||||
let mut terminal = setup_terminal().unwrap();
|
||||
|
@ -41,7 +41,12 @@ pub struct Widgets {
|
||||
pub temp: Option<TempWidget>,
|
||||
}
|
||||
|
||||
pub fn setup_app(args: &Args, update_ratio: Ratio<u64>, colorscheme: &Colorscheme) -> App {
|
||||
pub fn setup_app(
|
||||
args: &Args,
|
||||
update_ratio: Ratio<u64>,
|
||||
colorscheme: &Colorscheme,
|
||||
program_name: &str,
|
||||
) -> App {
|
||||
let cpu = CpuWidget::new(update_ratio, args.average_cpu, args.per_cpu);
|
||||
let mem = MemWidget::new(update_ratio);
|
||||
let proc = ProcWidget::new();
|
||||
@ -63,7 +68,7 @@ pub fn setup_app(args: &Args, update_ratio: Ratio<u64>, colorscheme: &Colorschem
|
||||
};
|
||||
|
||||
let statusbar = if args.statusbar {
|
||||
Some(Statusbar::new())
|
||||
Some(Statusbar::new(program_name))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -1,19 +1,42 @@
|
||||
use chrono::prelude::*;
|
||||
use tui::buffer::Buffer;
|
||||
use tui::layout::Rect;
|
||||
use tui::style::{Color, Style};
|
||||
use tui::widgets::Widget;
|
||||
|
||||
use crate::widgets::block;
|
||||
|
||||
pub struct Statusbar {}
|
||||
pub struct Statusbar {
|
||||
hostname: String,
|
||||
program_name: String,
|
||||
program_name_len: u16,
|
||||
}
|
||||
|
||||
impl Statusbar {
|
||||
pub fn new() -> Statusbar {
|
||||
Statusbar {}
|
||||
pub fn new(program_name: &str) -> Statusbar {
|
||||
Statusbar {
|
||||
hostname: hostname::get_hostname().unwrap(),
|
||||
program_name: program_name.to_string(),
|
||||
program_name_len: program_name.len() as u16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for Statusbar {
|
||||
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
|
||||
block::new().draw(area, buf);
|
||||
let time = Local::now().format("%H:%M:%S").to_string();
|
||||
buf.set_string(area.x + 1, area.y, &self.hostname, Style::default());
|
||||
buf.set_string(
|
||||
(area.x + area.width - time.len() as u16) / 2,
|
||||
area.y,
|
||||
time,
|
||||
Style::default(),
|
||||
);
|
||||
buf.set_string(
|
||||
area.x + area.width - self.program_name_len - 1,
|
||||
area.y,
|
||||
&self.program_name,
|
||||
Style::default(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user