Skip to content

Commit 6e9246c

Browse files
feat: custom refresh time, filter non-highlighted
1 parent 7af34be commit 6e9246c

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/cli/local_subcommands.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ pub(crate) enum LocalSubcommands {
1313
/// Flags for setting highlight colors for lines that contain a certain string
1414
/// Colors inside mean the color of the background of the highlighted line
1515
#[clap(flatten)]
16-
colors: ScriptslogColors
16+
colors: ScriptslogColors,
17+
18+
/// How often should the log be refreshed, in millis
19+
#[clap(short, long, default_value_t=1000)]
20+
refresh_time: u64,
21+
22+
/// Filter out lines that do not containt highlighted text
23+
#[clap(short, long)]
24+
filter_non_highlighted: bool
1725
}
1826
}
1927

@@ -49,9 +57,9 @@ pub(crate) fn handle_local_subcommand( cmd: LocalSubcommands, options: CliOption
4957
if !options.no_wait { thread::sleep( Duration::from_millis(3000) ) }
5058

5159
match cmd {
52-
LocalSubcommands::Scriptslog { colors } => {
60+
LocalSubcommands::Scriptslog { colors, refresh_time, filter_non_highlighted } => {
5361
let highlights = scriptslog_colors_to_highlight_records(colors);
54-
if let Some(err) = rw3d_core::scriptslog::tail_scriptslog(|s| scriptslog_printer(s, &highlights), 1000, logger_rcv) {
62+
if let Some(err) = rw3d_core::scriptslog::tail_scriptslog(|text| scriptslog_printer(text, &highlights, filter_non_highlighted), refresh_time, logger_rcv) {
5563
println!("{}", err);
5664
}
5765
}
@@ -132,8 +140,8 @@ fn scriptslog_colors_to_highlight_records(colors: ScriptslogColors) -> Vec<Scrip
132140
// The color chosen is not used anywhere else for that matter
133141
const NO_COLORING_PLACEHOLDER: Color = Color::BrightBlack;
134142

135-
fn scriptslog_printer( t: &String, highlights: &Vec<ScriptslogHighlightRecord> ) {
136-
let lines = t.split("\n");
143+
fn scriptslog_printer( text: &String, highlights: &Vec<ScriptslogHighlightRecord>, filter_non_highlighted: bool ) {
144+
let lines = text.split("\n");
137145

138146
for line in lines {
139147
let (mut fg, mut bg) = (NO_COLORING_PLACEHOLDER, NO_COLORING_PLACEHOLDER);
@@ -148,7 +156,7 @@ fn scriptslog_printer( t: &String, highlights: &Vec<ScriptslogHighlightRecord> )
148156

149157
if fg != NO_COLORING_PLACEHOLDER {
150158
println!("{}", line.color(fg).on_color(bg));
151-
} else {
159+
} else if !filter_non_highlighted {
152160
println!("{}", line);
153161
}
154162
}

0 commit comments

Comments
 (0)