Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed progress bar and wizard colored output when --no-color option is used #1269

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-Japanese.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**バグ修正:**

- `search`コマンドの出力に入っている不要な改行文字を削除した。 (#1253) (@hitenkoku)
- `no-color`オプション使用時のプログレスバーとウィザードのカラー出力を修正した。 (#1256) (@hitenkoku)

**その他:**

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**Bug Fixes:**

- Removed newline characters in `search` command output. (#1253) (@hitenkoku)
- Fixed progress bar and wizard colored output when `--no-color` option is used. (#1256) (@hitenkoku)

**Other:**

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ num = "0.4.0"
indexmap = "2.*"
dialoguer = "*"
wildmatch = "2.*"
console = "0.15.7"

[profile.dev]
debug = 0
Expand Down
57 changes: 42 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
use clap::Command;
use compact_str::CompactString;
use console::{style, Style};
use dialoguer::Confirm;
use dialoguer::{theme::ColorfulTheme, Select};
use evtx::{EvtxParser, ParserSettings, RecordAllocation};
Expand Down Expand Up @@ -1132,7 +1133,31 @@
format!("5. All event and alert rules ({} rules) ( status: * | level: informational+ )", sections_rule_cnt[4].iter().map(|(_, cnt)| cnt).sum::<i128>() - sections_rule_cnt[4].get("excluded").unwrap_or(&0))
];

let selected_index = Select::with_theme(&ColorfulTheme::default())
let color_theme = if stored_static.common_options.no_color {
ColorfulTheme {
defaults_style: Style::new().for_stderr(),
prompt_style: Style::new().for_stderr().bold(),
prompt_prefix: style("?".to_string()).for_stderr(),
prompt_suffix: style("›".to_string()).for_stderr(),
success_prefix: style("✔".to_string()).for_stderr(),
success_suffix: style("·".to_string()).for_stderr(),
error_prefix: style("✘".to_string()).for_stderr(),
error_style: Style::new().for_stderr(),
hint_style: Style::new().for_stderr(),
values_style: Style::new().for_stderr(),
active_item_style: Style::new().for_stderr(),
inactive_item_style: Style::new().for_stderr(),
active_item_prefix: style("❯".to_string()).for_stderr(),
inactive_item_prefix: style(" ".to_string()).for_stderr(),
checked_item_prefix: style("✔".to_string()).for_stderr(),
unchecked_item_prefix: style("⬚".to_string()).for_stderr(),
picked_item_prefix: style("❯".to_string()).for_stderr(),
unpicked_item_prefix: style(" ".to_string()).for_stderr(),
}

Check warning on line 1156 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1136-L1156

Added lines #L1136 - L1156 were not covered by tests
} else {
ColorfulTheme::default()

Check warning on line 1158 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1158

Added line #L1158 was not covered by tests
};
let selected_index = Select::with_theme(&color_theme)

Check warning on line 1160 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1160

Added line #L1160 was not covered by tests
.with_prompt("Which set of detection rules would you like to load?")
.default(0)
.items(selection_status_items.as_slice())
Expand Down Expand Up @@ -1179,7 +1204,7 @@
if selected_index < 3 {
if let Some(et_cnt) = tags_cnt.get("detection.emerging_threats") {
let prompt_fmt = format!("Include Emerging Threats rules? ({} rules)", et_cnt);
let et_rules_load_flag = Confirm::with_theme(&ColorfulTheme::default())
let et_rules_load_flag = Confirm::with_theme(&color_theme)

Check warning on line 1207 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1207

Added line #L1207 was not covered by tests
.with_prompt(prompt_fmt)
.default(true)
.show_default(true)
Expand All @@ -1192,7 +1217,7 @@
}
if let Some(th_cnt) = tags_cnt.get("detection.threat_hunting") {
let prompt_fmt = format!("Include Threat Hunting rules? ({} rules)", th_cnt);
let th_rules_load_flag = Confirm::with_theme(&ColorfulTheme::default())
let th_rules_load_flag = Confirm::with_theme(&color_theme)

Check warning on line 1220 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1220

Added line #L1220 was not covered by tests
.with_prompt(prompt_fmt)
.default(false)
.show_default(true)
Expand All @@ -1208,7 +1233,7 @@
if let Some(dep_cnt) = exclude_noisy_cnt.get("deprecated") {
// deprecated rules load prompt
let prompt_fmt = format!("Include deprecated rules? ({} rules)", dep_cnt);
let dep_rules_load_flag = Confirm::with_theme(&ColorfulTheme::default())
let dep_rules_load_flag = Confirm::with_theme(&color_theme)

Check warning on line 1236 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1236

Added line #L1236 was not covered by tests
.with_prompt(prompt_fmt)
.default(false)
.show_default(true)
Expand All @@ -1225,13 +1250,12 @@
if let Some(unsup_cnt) = exclude_noisy_cnt.get("unsupported") {
// unsupported rules load prompt
let prompt_fmt = format!("Include unsupported rules? ({} rules)", unsup_cnt);
let unsupported_rules_load_flag =
Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(prompt_fmt)
.default(false)
.show_default(true)
.interact()
.unwrap();
let unsupported_rules_load_flag = Confirm::with_theme(&color_theme)
.with_prompt(prompt_fmt)
.default(false)
.show_default(true)
.interact()
.unwrap();

Check warning on line 1258 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1253-L1258

Added lines #L1253 - L1258 were not covered by tests
if unsupported_rules_load_flag {
stored_static
.output_option
Expand All @@ -1245,7 +1269,7 @@
if let Some(noisy_cnt) = exclude_noisy_cnt.get("noisy") {
// noisy rules load prompt
let prompt_fmt = format!("Include noisy rules? ({} rules)", noisy_cnt);
let noisy_rules_load_flag = Confirm::with_theme(&ColorfulTheme::default())
let noisy_rules_load_flag = Confirm::with_theme(&color_theme)

Check warning on line 1272 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1272

Added line #L1272 was not covered by tests
.with_prompt(prompt_fmt)
.default(false)
.show_default(true)
Expand All @@ -1262,7 +1286,7 @@

if let Some(sysmon_cnt) = tags_cnt.get("sysmon") {
let prompt_fmt = format!("Include sysmon rules? ({} rules)", sysmon_cnt);
let sysmon_rules_load_flag = Confirm::with_theme(&ColorfulTheme::default())
let sysmon_rules_load_flag = Confirm::with_theme(&color_theme)

Check warning on line 1289 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1289

Added line #L1289 was not covered by tests
.with_prompt(prompt_fmt)
.default(true)
.show_default(true)
Expand Down Expand Up @@ -1341,8 +1365,11 @@
return;
}

let template =
"[{elapsed_precise}] {human_pos} / {human_len} {spinner:.green} [{bar:40.green}] {percent}%\r\n\r\n{msg}";
let template = if stored_static.common_options.no_color {
"[{elapsed_precise}] {human_pos} / {human_len} {spinner} [{bar:40}] {percent}%\r\n\r\n{msg}"

Check warning on line 1369 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L1369

Added line #L1369 was not covered by tests
} else {
"[{elapsed_precise}] {human_pos} / {human_len} {spinner:.green} [{bar:40.green}] {percent}%\r\n\r\n{msg}"
};
let progress_style = ProgressStyle::with_template(template)
.unwrap()
.progress_chars("=> ");
Expand Down
Loading