diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-10-19 10:07:00 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-22 23:49:51 +0200 |
commit | 691b1058851cdb16d0664a2064dc1f5eb6be7a34 (patch) | |
tree | c2fb62eee7fef2725894d4fcd357f6b912133815 | |
parent | 27040e65eb9485eeccaa0235753032c935a3e890 (diff) | |
download | serenity-691b1058851cdb16d0664a2064dc1f5eb6be7a34.zip |
LibLine: Support basic escaped characters in config file
Until we can figure out how shift+enter works (or an alternative), this
can be used to input literal newlines:
```ini
[keybinds]
\\\n=\n
```
-rw-r--r-- | Libraries/LibLine/Editor.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index bd97454e76..28f66ce718 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -80,27 +80,38 @@ Configuration Configuration::from_config(const StringView& libname) GenericLexer key_lexer(binding_key); auto has_ctrl = false; auto alt = false; + auto escape = false; Vector<Key> keys; while (!key_lexer.is_eof()) { - if (key_lexer.next_is("alt+")) { - alt = key_lexer.consume_specific("alt+"); - continue; - } - if (key_lexer.next_is("^[")) { - alt = key_lexer.consume_specific("^["); - continue; - } - if (key_lexer.next_is("^")) { - has_ctrl = key_lexer.consume_specific("^"); - continue; - } - if (key_lexer.next_is("ctrl+")) { - has_ctrl = key_lexer.consume_specific("ctrl+"); - continue; + unsigned key; + if (escape) { + key = key_lexer.consume_escaped_character(); + escape = false; + } else { + if (key_lexer.next_is("alt+")) { + alt = key_lexer.consume_specific("alt+"); + continue; + } + if (key_lexer.next_is("^[")) { + alt = key_lexer.consume_specific("^["); + continue; + } + if (key_lexer.next_is("^")) { + has_ctrl = key_lexer.consume_specific("^"); + continue; + } + if (key_lexer.next_is("ctrl+")) { + has_ctrl = key_lexer.consume_specific("ctrl+"); + continue; + } + if (key_lexer.next_is("\\")) { + escape = true; + continue; + } + // FIXME: Support utf? + key = key_lexer.consume(); } - // FIXME: Support utf? - unsigned key = key_lexer.consume(); if (has_ctrl) key = ctrl(key); @@ -109,12 +120,16 @@ Configuration Configuration::from_config(const StringView& libname) has_ctrl = false; } - auto value = config_file->read_entry("keybinds", binding_key); + GenericLexer value_lexer { config_file->read_entry("keybinds", binding_key) }; + StringBuilder value_builder; + while (!value_lexer.is_eof()) + value_builder.append(value_lexer.consume_escaped_character()); + auto value = value_builder.string_view(); if (value.starts_with("internal:")) { configuration.set(KeyBinding { keys, KeyBinding::Kind::InternalFunction, - value.substring(9, value.length() - 9) }); + value.substring_view(9, value.length() - 9) }); } else { configuration.set(KeyBinding { keys, |