From d23bb2d0b59f3f14c8039ee04896cf1f999eee8b Mon Sep 17 00:00:00 2001 From: Edmo Vamerlatti Costa <11836452+edmocosta@users.noreply.github.com> Date: Fri, 23 Jun 2023 10:09:03 +0200 Subject: [PATCH] Change view command to clear the terminal before render the application (#2) - Changed view command to clear the terminal before rendering the application. - Removed the get node default formatter colors --- Cargo.lock | 9 +--- Cargo.toml | 6 +-- src/cli/commands/node/default.rs | 74 ++++++++++++++------------------ src/cli/commands/view/backend.rs | 9 +++- 4 files changed, 43 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f6ff52..74c99b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,12 +467,6 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" - [[package]] name = "papergrid" version = "0.7.1" @@ -801,7 +795,7 @@ dependencies = [ [[package]] name = "tuistash" -version = "0.1.0" +version = "0.1.2" dependencies = [ "base64", "chrono", @@ -813,7 +807,6 @@ dependencies = [ "humantime", "json_to_table", "num-format", - "owo-colors", "rustls", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 41b5708..62c5e54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ documentation = "https://github.com/edmocosta/tuistash" keywords = ["logstash", "tui", "cli", "terminal"] categories = ["command-line-utilities"] authors = ["Edmo Costa "] -version = "0.1.1" +version = "0.1.2" edition = "2021" [dependencies] @@ -16,8 +16,7 @@ ureq = { version = "2.7.1", features = ["json", "tls"], default-features = false serde = { version = "1.0", features = ["derive"], default-features = false } serde_with = { version = "3.0.0", default-features = false } serde_json = { version = "1.0", default-features = false } -tabled = { version = "0.10", features = ["color"], default-features = false } -owo-colors = { version = "3.5.0", default-features = false } +tabled = { version = "0.10.0", features = ["color"], default-features = false } json_to_table = { version = "*", default-features = false } base64 = { version = "0.21.0", features = ["std"], default-features = false } rustls = { version = "0.21.2", features = ["dangerous_configuration"], default-features = false } @@ -31,7 +30,6 @@ num-format = { version = "0.4.4", default-features = false, features = ["with-nu human_format = { version = "1.0" } uuid = { version = "1.3.3", features = ["v4"] } - [[bin]] name = "tuistash" path = "src/cli/main.rs" \ No newline at end of file diff --git a/src/cli/commands/node/default.rs b/src/cli/commands/node/default.rs index 672efe2..766fb0d 100644 --- a/src/cli/commands/node/default.rs +++ b/src/cli/commands/node/default.rs @@ -1,6 +1,5 @@ use chrono::NaiveDateTime; use humansize::{format_size_i, DECIMAL}; -use owo_colors::OwoColorize; use tabled::builder::Builder; use tabled::{row, Style, Table}; @@ -22,18 +21,17 @@ impl ValueFormatter for DefaultFormatter { fn create_info_table(node_info: &NodeInfo) -> Table { let mut builder = Builder::default(); - builder.set_columns(vec![ - "ID".bold().to_string(), - "NAME".bold().to_string(), - "HOST".bold().to_string(), - "VERSION".bold().to_string(), - "HTTP_ADDRESS".bold().to_string(), - "STATUS".bold().to_string(), - "WORKERS".bold().to_string(), - "BATCH_SIZE".bold().to_string(), - "BATCH_DELAY".bold().to_string(), - "EPHEMERAL_ID".bold().to_string(), + "ID".to_string(), + "NAME".to_string(), + "HOST".to_string(), + "VERSION".to_string(), + "HTTP_ADDRESS".to_string(), + "STATUS".to_string(), + "WORKERS".to_string(), + "BATCH_SIZE".to_string(), + "BATCH_DELAY".to_string(), + "EPHEMERAL_ID".to_string(), ]); let node = &node_info.node; @@ -59,14 +57,14 @@ fn create_pipelines_table(node_info: &NodeInfo) -> Table { let mut builder = Builder::default(); builder.set_columns(vec![ - "NAME".bold().to_string(), - "WORKERS".bold().to_string(), - "BATCH_SIZE".bold().to_string(), - "BATCH_DELAY".bold().to_string(), - "CONFIG_RELOAD_AUTOMATIC".bold().to_string(), - "CONFIG_RELOAD_INTERVAL".bold().to_string(), - "DLQ_ENABLED".bold().to_string(), - "EPHEMERAL_ID".bold().to_string(), + "NAME".to_string(), + "WORKERS".to_string(), + "BATCH_SIZE".to_string(), + "BATCH_DELAY".to_string(), + "CONFIG_RELOAD_AUTOMATIC".to_string(), + "CONFIG_RELOAD_INTERVAL".to_string(), + "DLQ_ENABLED".to_string(), + "EPHEMERAL_ID".to_string(), ]); if node_info.pipelines.is_some() { @@ -93,10 +91,10 @@ fn create_os_table(node_info: &NodeInfo) -> Table { let mut builder = Builder::default(); builder.set_columns(vec![ - "NAME".bold().to_string(), - "VERSION".bold().to_string(), - "ARCH".bold().to_string(), - "AVAILABLE_PROCESSORS".bold().to_string(), + "NAME".to_string(), + "VERSION".to_string(), + "ARCH".to_string(), + "AVAILABLE_PROCESSORS".to_string(), ]); if node_info.os.is_some() { @@ -118,13 +116,13 @@ fn create_jvm_table(node_info: &NodeInfo) -> Table { let mut builder = Builder::default(); builder.set_columns(vec![ - "PID".bold().to_string(), - "VERSION".bold().to_string(), - "VM".bold().to_string(), - "START_TIME".bold().to_string(), - "HEAP_INIT_MAX".bold().to_string(), - "NON_HEAP_INIT_MAX".bold().to_string(), - "GC_COLLECTORS".bold().to_string(), + "PID".to_string(), + "VERSION".to_string(), + "VM".to_string(), + "START_TIME".to_string(), + "HEAP_INIT_MAX".to_string(), + "NON_HEAP_INIT_MAX".to_string(), + "GC_COLLECTORS".to_string(), ]); if node_info.jvm.is_some() { @@ -184,9 +182,9 @@ fn new_default_table(node_info: &NodeInfo, types: Option<&[NodeInfoType]>) -> Ta } _ => { add_section_separator(&mut builder, info_types, info_type); - builder.add_record(vec!["Default format not supported for this type" - .red() - .to_string()]); + builder.add_record(vec![ + "Default format not supported for this type".to_string() + ]); } } } @@ -210,13 +208,7 @@ fn add_section_separator( } fn add_section_separator_record(builder: &mut Builder, current: &NodeInfoType) { - let mut section = row![current - .to_string() - .to_uppercase() - .blue() - .bold() - .underline() - .to_string()]; + let mut section = row![current.to_string().to_uppercase()]; section.with(Style::empty()); builder.add_record(vec![section.to_string()]); } diff --git a/src/cli/commands/view/backend.rs b/src/cli/commands/view/backend.rs index b8286a4..9f3c2ea 100644 --- a/src/cli/commands/view/backend.rs +++ b/src/cli/commands/view/backend.rs @@ -23,12 +23,17 @@ pub fn run(interval: Duration, config: &Config) -> Result<(), AnyError> { let mut stdout = io::stdout(); execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; + let backend = CrosstermBackend::new(stdout); let mut terminal = Terminal::new(backend)?; - let app = App::new("Logstash", config.api, interval); + terminal.clear()?; - run_app(&mut terminal, app, interval)?; + run_app( + &mut terminal, + App::new("Logstash", config.api, interval), + interval, + )?; disable_raw_mode()?;