From adfb780521df8ab4ebe9de2a3d5b0578d6d40874 Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Sat, 25 Apr 2026 18:18:08 -0500 Subject: [PATCH] add export config script --- export config.swift | 68 ++++++++++++++++++++++++++++++++ src/action.rs | 36 ++++++++--------- src/buffer.rs | 4 +- src/buffer/widget/status_line.rs | 4 +- src/config/default.rs | 6 +++ src/main.rs | 11 +++--- 6 files changed, 102 insertions(+), 27 deletions(-) create mode 100755 export config.swift diff --git a/export config.swift b/export config.swift new file mode 100755 index 0000000..da69b01 --- /dev/null +++ b/export config.swift @@ -0,0 +1,68 @@ +#!/usr/bin/swift + +import Foundation + +func camelCaseToSnakeCase(_ string: Substring) -> String { + var output = string.first?.lowercased() ?? "" + + var previousCharacterWasUppercase = false + + for character in string.dropFirst() { + if character.isUppercase { + if previousCharacterWasUppercase { + output.append(character.lowercased()) + } else { + output += "_\(character.lowercased())" + previousCharacterWasUppercase = true + } + } else if character.isNumber { + output += "_\(character)" + + previousCharacterWasUppercase = false + } else { + output.append(character) + + previousCharacterWasUppercase = false + } + } + + return output +} + +let defaultConfigPath = URL(filePath: "src/config/default.rs") + +let lines = try String(contentsOf: defaultConfigPath, encoding: .utf8) + .split(separator: "\n", omittingEmptySubsequences: false) + .dropFirst(14) + .dropLast(6) + +precondition(lines.first!.contains("Mode::Normal")) + +var mode: String? + +for line in lines { + if let match = line.wholeMatch(of: #/.*Mode::(?'mode'\w*),.*/#) { + mode = match.output.mode.lowercased() + } else if line.contains("None") { + print("[\(mode!)]") + } else if let match = line.wholeMatch(of: #/.*PartialAction::(?'partialAction'\w*).*/#) { + let partialAction = match.output.partialAction.lowercased() + print("[\(mode!).\(partialAction)]") + } else if let match = line.wholeMatch(of: #/.*\(keypress\("(?'keypress'.*?)"\), (?'action'.*?)\.into\(\)\).*/#) { + if match.output.keypress.contains(where: { !($0.isLetter || $0.isNumber) }) { + print( + "\"\(match.output.keypress)\"", + "=", + "\"\(camelCaseToSnakeCase(match.output.action))\"" + ) + } else { + print( + match.output.keypress, + "=", + "\"\(camelCaseToSnakeCase(match.output.action))\"" + ) + } + } else { + print() + } +} diff --git a/src/action.rs b/src/action.rs index 05dabfe..4b71cdb 100644 --- a/src/action.rs +++ b/src/action.rs @@ -310,15 +310,15 @@ impl From for &str { KeepPrimarySelection => "keep_primary_selection", RemovePrimarySelection => "remove_primary_selection", - SplitSelectionsInto1s => "split_selections_into_1_s", - SplitSelectionsInto2s => "split_selections_into_2_s", - SplitSelectionsInto3s => "split_selections_into_3_s", - SplitSelectionsInto4s => "split_selections_into_4_s", - SplitSelectionsInto5s => "split_selections_into_5_s", - SplitSelectionsInto6s => "split_selections_into_6_s", - SplitSelectionsInto7s => "split_selections_into_7_s", - SplitSelectionsInto8s => "split_selections_into_8_s", - SplitSelectionsInto9s => "split_selections_into_9_s", + SplitSelectionsInto1s => "split_selections_into_1s", + SplitSelectionsInto2s => "split_selections_into_2s", + SplitSelectionsInto3s => "split_selections_into_3s", + SplitSelectionsInto4s => "split_selections_into_4s", + SplitSelectionsInto5s => "split_selections_into_5s", + SplitSelectionsInto6s => "split_selections_into_6s", + SplitSelectionsInto7s => "split_selections_into_7s", + SplitSelectionsInto8s => "split_selections_into_8s", + SplitSelectionsInto9s => "split_selections_into_9s", JumpToSelectedOffset => "jump_to_selected_offset", JumpToSelectedOffsetRelativeToMark => "jump_to_selected_offset_relative_to_mark", @@ -393,15 +393,15 @@ impl TryFrom<&str> for BufferAction { "keep_primary_selection" => Ok(KeepPrimarySelection), "remove_primary_selection" => Ok(RemovePrimarySelection), - "split_selections_into_1_s" => Ok(SplitSelectionsInto1s), - "split_selections_into_2_s" => Ok(SplitSelectionsInto2s), - "split_selections_into_3_s" => Ok(SplitSelectionsInto3s), - "split_selections_into_4_s" => Ok(SplitSelectionsInto4s), - "split_selections_into_5_s" => Ok(SplitSelectionsInto5s), - "split_selections_into_6_s" => Ok(SplitSelectionsInto6s), - "split_selections_into_7_s" => Ok(SplitSelectionsInto7s), - "split_selections_into_8_s" => Ok(SplitSelectionsInto8s), - "split_selections_into_9_s" => Ok(SplitSelectionsInto9s), + "split_selections_into_1s" => Ok(SplitSelectionsInto1s), + "split_selections_into_2s" => Ok(SplitSelectionsInto2s), + "split_selections_into_3s" => Ok(SplitSelectionsInto3s), + "split_selections_into_4s" => Ok(SplitSelectionsInto4s), + "split_selections_into_5s" => Ok(SplitSelectionsInto5s), + "split_selections_into_6s" => Ok(SplitSelectionsInto6s), + "split_selections_into_7s" => Ok(SplitSelectionsInto7s), + "split_selections_into_8s" => Ok(SplitSelectionsInto8s), + "split_selections_into_9s" => Ok(SplitSelectionsInto9s), "jump_to_selected_offset" => Ok(JumpToSelectedOffset), "jump_to_selected_offset_relative_to_mark" => Ok(JumpToSelectedOffsetRelativeToMark), diff --git a/src/buffer.rs b/src/buffer.rs index 174fb7f..0265595 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -42,7 +42,7 @@ pub struct Buffer { #[derive(Debug)] #[serde(rename_all = "snake_case")] pub enum Mode { - Normal, Select, Insert + Normal, Select, // Insert } #[derive(Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)] @@ -69,7 +69,7 @@ impl TryFrom<&str> for PartialAction { "replace" => Ok(Replace), "space" => Ok(Space), "repeat" => Ok(Repeat), - "to" => Ok(Till), + "till" => Ok(Till), _ => Err(()), } } diff --git a/src/buffer/widget/status_line.rs b/src/buffer/widget/status_line.rs index 5c9d1ce..e0bfe63 100644 --- a/src/buffer/widget/status_line.rs +++ b/src/buffer/widget/status_line.rs @@ -40,7 +40,7 @@ impl Mode { match self { Self::Normal => " NORMAL ", Self::Select => " SELECT ", - Self::Insert => " INSERT ", + // Self::Insert => " INSERT ", } } @@ -48,7 +48,7 @@ impl Mode { match self { Self::Normal => Color::Blue, Self::Select => Color::Yellow, - Self::Insert => Color::Green, + // Self::Insert => Color::Green, } } } diff --git a/src/config/default.rs b/src/config/default.rs index 881808c..0b1a5a3 100644 --- a/src/config/default.rs +++ b/src/config/default.rs @@ -106,6 +106,9 @@ impl Default for Config { ].into()), (Some(PartialAction::Space), [ (keypress("w"), Save.into()), + + (keypress("q"), QuitIfSaved.into()), + (keypress("Q"), Quit.into()), ].into()), (Some(PartialAction::Repeat), [ (keypress("i"), MoveByteUp.into()), @@ -235,6 +238,9 @@ impl Default for Config { ].into()), (Some(PartialAction::Space), [ (keypress("w"), Save.into()), + + (keypress("q"), QuitIfSaved.into()), + (keypress("Q"), Quit.into()), ].into()), (Some(PartialAction::Repeat), [ (keypress("i"), ExtendByteUp.into()), diff --git a/src/main.rs b/src/main.rs index 45ab635..f5b655e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,17 +45,18 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - inspector translations for varint // - repeated actions may only be cursor actions // - shouldn't crash -// - gg/G in select mode -// - gl/gj in select mode // - scrolling in select mode -// - +/- to edit selected bytes by amount +// - M mark at selected offset (like Jm) // - search // - ascii and bytes (`/` and `A-/`?) // - diffing // - doesn't have to be anything fancy, just compare each byte 1:1 // - s/A-k/A-K -// - sm select marks +// - (not) sm select marks // - C-a/C-x +// - +/- to edit selected bytes by amount ? +// - operate on entire selection (u16/u32/etc) +// - hex or decimal ? // - modifications // - insert/append // - mode @@ -65,8 +66,8 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - change // - edit character panel // - modifier on existing keys like teehee? or jump to panel? +// - A-r replaces with ASCII ? // - if jump to panel, space? -// - visual gg/G // - jumplist // - p // - [/] to cycle view offset?