Skip to content

Commit ebc9b15

Browse files
committed
Add CLI args for setting column labels and colors
Add two more CLI arguments, `--column` and `--color` which can be used to set column labels and colors automatically. For multiple columns, these arguments can be specified multiple times. For example: --column Raw --color 555555 --column Temperature --color ff8000 The color arguments are hex colors without a leading `#` sign.
1 parent c2c14a8 commit ebc9b15

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/gui.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct MyApp {
157157
show_warning_window: WindowFeedback,
158158
do_not_show_clear_warning: bool,
159159
init: bool,
160+
cli_column_colors: Vec<egui::Color32>,
160161
#[cfg(feature = "self_update")]
161162
new_release: Option<Release>,
162163
}
@@ -176,6 +177,7 @@ impl MyApp {
176177
load_names_rx: Receiver<Vec<String>>,
177178
send_tx: Sender<String>,
178179
gui_cmd_tx: Sender<GuiCommand>,
180+
cli_column_colors: Vec<egui::Color32>,
179181
) -> Self {
180182
let mut file_dialog = FileDialog::default()
181183
//.initial_directory(PathBuf::from("/path/to/app"))
@@ -256,6 +258,7 @@ impl MyApp {
256258
init: false,
257259
show_color_window: ColorWindow::NoShow,
258260
file_opened: false,
261+
cli_column_colors,
259262
#[cfg(feature = "self_update")]
260263
new_release: None,
261264
settings_window_open: false,
@@ -325,9 +328,15 @@ impl MyApp {
325328
}
326329
if self.colors.len() != self.labels.len() {
327330
self.colors = (0..max(self.labels.len(), 1))
328-
.map(|i| COLORS[i % COLORS.len()])
331+
.map(|i| {
332+
self.cli_column_colors
333+
.get(i)
334+
.copied()
335+
.unwrap_or(COLORS[i % COLORS.len()])
336+
})
329337
.collect();
330-
self.color_vals = (0..max(self.data.plots.len(), 1)).map(|_| 0.0).collect();
338+
self.color_vals =
339+
(0..max(self.data.plots.len(), 1)).map(|_| 0.0).collect();
331340
}
332341
}
333342

src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn main_thread(
7777
load_rx: Receiver<PathBuf>,
7878
load_names_tx: Sender<Vec<String>>,
7979
gui_cmd_rx: Receiver<GuiCommand>,
80+
cli_column_labels: Vec<String>,
8081
) {
8182
// reads data from mutex, samples and saves if needed
8283
let mut data = DataContainer::default();
@@ -111,7 +112,7 @@ fn main_thread(
111112
data.dataset = vec![vec![]; max(split_data.len(), 1)];
112113
if let Ok(mut gui_data) = data_lock.write() {
113114
gui_data.plots = (0..max(split_data.len(), 1))
114-
.map(|i| (format!("Column {i}"), vec![]))
115+
.map(|i| (cli_column_labels.get(i).cloned().unwrap_or_else(|| format!("Column {i}")), vec![]))
115116
.collect();
116117
}
117118
failed_format_counter = 0;
@@ -295,6 +296,12 @@ fn parse_parity(s: &str) -> Result<serialport::Parity, String> {
295296
}
296297
}
297298

299+
fn parse_color(s: &str) -> Result<egui::Color32, String> {
300+
Ok(egui::ecolor::HexColor::from_str_without_hash(s)
301+
.map_err(|e| format!("invalid color {s:?}: {e:?}"))?
302+
.color())
303+
}
304+
298305
#[derive(Debug, Options)]
299306
struct CliOptions {
300307
/// Serial port device to open on startup
@@ -325,6 +332,14 @@ struct CliOptions {
325332
#[options(short = "F")]
326333
file: Option<std::path::PathBuf>,
327334

335+
/// Column labels, can be specified multiple times for more columns
336+
#[options(no_short, long = "column")]
337+
column_labels: Vec<String>,
338+
339+
/// Column colors (hex color without #), can be specified multiple times for more columns
340+
#[options(no_short, long = "color", parse(try_from_str = "parse_color"))]
341+
column_colors: Vec<egui::Color32>,
342+
328343
help: bool,
329344
}
330345

@@ -404,6 +419,7 @@ fn main() {
404419
load_rx,
405420
loaded_names_tx,
406421
gui_cmd_rx,
422+
args.column_labels,
407423
);
408424
});
409425

@@ -457,6 +473,7 @@ fn main() {
457473
loaded_names_rx,
458474
send_tx,
459475
gui_cmd_tx,
476+
args.column_colors,
460477
)))
461478
}),
462479
) {

0 commit comments

Comments
 (0)