diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-06 10:14:16 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-06 10:14:16 +0200 |
commit | f2d74a69df074262d020a4dd3d5e05d348e327e9 (patch) | |
tree | 3a436d19ab2a86072bc3d3bf8fd0a2168c244788 /rust | |
parent | chore(deployes): Add newly deployed binaries (diff) | |
download | qmk_layout-f2d74a69df074262d020a4dd3d5e05d348e327e9.zip |
fix(keymap): Avoid formatting it via clang-format
Diffstat (limited to 'rust')
-rw-r--r-- | rust/format/src/main.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/rust/format/src/main.rs b/rust/format/src/main.rs index 3554087..9c167eb 100644 --- a/rust/format/src/main.rs +++ b/rust/format/src/main.rs @@ -10,12 +10,25 @@ fn main() { .read_to_string(&mut keymap_h) .expect("Failed to read keymap_h"); + let mut lines: Vec<_> = keymap_h.lines().collect(); + if lines[0] == "// clang-format off" { + lines.remove(0); + } + if lines.last().expect("Exists") == &"// clang-format on" { + lines.remove(lines.len() - 1); + } + + keymap_h = lines.join("\n"); + let mut c_column_max = [0; 14]; let out = calculate(&mut c_column_max, keymap_h); let output = calculate(&mut c_column_max, out.join("\n")); - print!("{}", output.join("\n")); + print!( + "// clang-format off\n{}\n// clang-format on", + output.join("\n") + ); } fn calculate(c_column_max: &mut [usize; 14], keymap_h: String) -> Vec<String> { @@ -35,7 +48,10 @@ fn calculate(c_column_max: &mut [usize; 14], keymap_h: String) -> Vec<String> { } '[' => { // Start of a new layer - assert!(c_layer.is_empty(), "No new layer, without empty"); + assert!( + c_layer.is_empty(), + "A new layer cannot start, when the current layer is not empty." + ); output.push(format!(" {}", line)); } ')' => { |