Skip to content

Commit

Permalink
Change view command to clear the terminal before render the applicati…
Browse files Browse the repository at this point in the history
…on (#2)

- Changed view command to clear the terminal before rendering the application.
- Removed the get node default formatter colors
  • Loading branch information
edmocosta authored Jun 23, 2023
1 parent b81e321 commit d23bb2d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 55 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ documentation = "https://github.com/edmocosta/tuistash"
keywords = ["logstash", "tui", "cli", "terminal"]
categories = ["command-line-utilities"]
authors = ["Edmo Costa <[email protected]>"]
version = "0.1.1"
version = "0.1.2"
edition = "2021"

[dependencies]
Expand All @@ -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 }
Expand All @@ -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"
74 changes: 33 additions & 41 deletions src/cli/commands/node/default.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
]);
}
}
}
Expand All @@ -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()]);
}
Expand Down
9 changes: 7 additions & 2 deletions src/cli/commands/view/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Expand Down

0 comments on commit d23bb2d

Please sign in to comment.