mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:15:07 +00:00
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 ```
This commit is contained in:
parent
27040e65eb
commit
691b105885
1 changed files with 34 additions and 19 deletions
|
@ -80,27 +80,38 @@ Configuration Configuration::from_config(const StringView& libname)
|
||||||
GenericLexer key_lexer(binding_key);
|
GenericLexer key_lexer(binding_key);
|
||||||
auto has_ctrl = false;
|
auto has_ctrl = false;
|
||||||
auto alt = false;
|
auto alt = false;
|
||||||
|
auto escape = false;
|
||||||
Vector<Key> keys;
|
Vector<Key> keys;
|
||||||
|
|
||||||
while (!key_lexer.is_eof()) {
|
while (!key_lexer.is_eof()) {
|
||||||
if (key_lexer.next_is("alt+")) {
|
unsigned key;
|
||||||
alt = key_lexer.consume_specific("alt+");
|
if (escape) {
|
||||||
continue;
|
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();
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
// FIXME: Support utf?
|
|
||||||
unsigned key = key_lexer.consume();
|
|
||||||
if (has_ctrl)
|
if (has_ctrl)
|
||||||
key = ctrl(key);
|
key = ctrl(key);
|
||||||
|
|
||||||
|
@ -109,12 +120,16 @@ Configuration Configuration::from_config(const StringView& libname)
|
||||||
has_ctrl = false;
|
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:")) {
|
if (value.starts_with("internal:")) {
|
||||||
configuration.set(KeyBinding {
|
configuration.set(KeyBinding {
|
||||||
keys,
|
keys,
|
||||||
KeyBinding::Kind::InternalFunction,
|
KeyBinding::Kind::InternalFunction,
|
||||||
value.substring(9, value.length() - 9) });
|
value.substring_view(9, value.length() - 9) });
|
||||||
} else {
|
} else {
|
||||||
configuration.set(KeyBinding {
|
configuration.set(KeyBinding {
|
||||||
keys,
|
keys,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue