diff options
Diffstat (limited to '')
-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)); } ')' => { |