Skip to content

Commit a7798f6

Browse files
authored
Tweak config table (#3734)
* Tweak config table * Restore active condition on xtal-frequenc * Print values using display hint * Fix clippy lints
1 parent b76a738 commit a7798f6

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

esp-config/src/bin/esp-config/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn parse_configs(
145145
chip_from_args: Option<esp_metadata::Chip>,
146146
config_file: Option<&str>,
147147
) -> Result<Vec<CrateConfig>, Box<dyn Error>> {
148-
let config_toml_path = path.join(config_file.as_deref().unwrap_or(DEFAULT_CONFIG_PATH));
148+
let config_toml_path = path.join(config_file.unwrap_or(DEFAULT_CONFIG_PATH));
149149
let config_toml_content = std::fs::read_to_string(config_toml_path)?;
150150
let config_toml = config_toml_content.as_str().parse::<DocumentMut>()?;
151151

esp-config/src/bin/esp-config/tui.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ impl Item {
2828
match self {
2929
Item::TopLevel(crate_name) => crate_name.clone(),
3030
Item::CrateLevel(config_option) => {
31-
let display_value = format_using_display_hint(
32-
&config_option.actual_value,
33-
&config_option.option.display_hint,
34-
);
31+
let display_value = config_option
32+
.option
33+
.display_hint
34+
.format_value(&config_option.actual_value);
3535
let default_indicator =
3636
if config_option.actual_value == config_option.option.default_value {
3737
ui_elements.default_value
@@ -81,24 +81,11 @@ impl Item {
8181
fn display_hint(&self) -> DisplayHint {
8282
match self {
8383
Item::TopLevel(_) => unreachable!(),
84-
Item::CrateLevel(config_option) => config_option.option.display_hint.clone(),
84+
Item::CrateLevel(config_option) => config_option.option.display_hint,
8585
}
8686
}
8787
}
8888

89-
fn format_using_display_hint(value: &Value, hint: &DisplayHint) -> String {
90-
match value {
91-
Value::Bool(b) => b.to_string(),
92-
Value::Integer(i) => match hint {
93-
DisplayHint::None => format!("{}", i),
94-
DisplayHint::Binary => format!("0b{:0b}", i),
95-
DisplayHint::Hex => format!("0x{:x}", i),
96-
DisplayHint::Octal => format!("0o{:o}", i),
97-
},
98-
Value::String(s) => s.clone(),
99-
}
100-
}
101-
10289
impl Repository {
10390
pub fn new(options: Vec<crate::CrateConfig>) -> Self {
10491
Self {
@@ -474,11 +461,10 @@ impl App<'_> {
474461
self.handle_error(set_res);
475462
}
476463
Value::Integer(_) => {
477-
let display_value = format_using_display_hint(
478-
&current,
479-
&self.repository.current_level()[selected]
480-
.display_hint(),
481-
);
464+
let display_value = self.repository.current_level()
465+
[selected]
466+
.display_hint()
467+
.format_value(&current);
482468
self.textarea =
483469
make_text_area(&display_value, &self.colors);
484470
self.editing_constraints = constraint;

esp-config/src/generate/markdown.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::fmt::Write;
33
use crate::{ConfigOption, Value};
44

55
pub(crate) const DOC_TABLE_HEADER: &str = r#"
6-
| Name | Description | Default&nbsp;value | Allowed&nbsp;value |
7-
|------|-------------|--------------------|--------------------|
6+
| Option | Stability | Default&nbsp;value | Allowed&nbsp;values |
7+
|--------|:---------:|:------------------:|:-------------------:|
88
"#;
99

1010
pub(crate) const SELECTED_TABLE_HEADER: &str = r#"
@@ -21,11 +21,11 @@ pub(crate) fn write_doc_table_line(mut table: impl Write, name: &str, option: &C
2121

2222
writeln!(
2323
table,
24-
"| <p>{key}</p><p>{stability}</p> | <p>{description}</p> | <center>{default}</center> | <center>{allowed}</center>",
24+
"| <p>**{key}**</p> <p>{description}</p> | {stability} | {default} | {allowed}",
2525
description = option.description,
2626
key = name,
2727
stability = option.stability,
28-
default = option.default_value,
28+
default = option.display_hint.format_value(&option.default_value),
2929
allowed = allowed_values
3030
)
3131
.unwrap();

esp-config/src/generate/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl Display for Stability {
440440
}
441441

442442
/// A display hint (for tooling only)
443-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
443+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
444444
pub enum DisplayHint {
445445
/// No display hint
446446
None,
@@ -455,6 +455,22 @@ pub enum DisplayHint {
455455
Octal,
456456
}
457457

458+
impl DisplayHint {
459+
/// Converts a [Value] to String applying the correct display hint.
460+
pub fn format_value(self, value: &Value) -> String {
461+
match value {
462+
Value::Bool(b) => b.to_string(),
463+
Value::Integer(i) => match self {
464+
DisplayHint::None => format!("{i}"),
465+
DisplayHint::Binary => format!("0b{i:0b}"),
466+
DisplayHint::Hex => format!("0x{i:X}"),
467+
DisplayHint::Octal => format!("0o{i:o}"),
468+
},
469+
Value::String(s) => s.clone(),
470+
}
471+
}
472+
}
473+
458474
/// A configuration option.
459475
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
460476
pub struct ConfigOption {

esp-hal/esp_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ options:
5555
validator: enumeration
5656
value:
5757
- '32'
58+
active: 'chip == "esp32" || chip == "esp32c2"'
5859

5960
- name: spi-address-workaround
6061
description: "Enables a workaround for the issue where SPI in

0 commit comments

Comments
 (0)