mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
Shell: Add live formatting and take an option to enable it
This patchset makes it possible for the shell to format the current buffer of the line editor live, with somewhat accurate cursor tracking. Since this feature is pretty goofy at best, let's keep it off by default for now :^)
This commit is contained in:
parent
e94ee08eca
commit
fa03a2848f
Notes:
sideshowbarker
2024-07-19 02:11:58 +09:00
Author: https://github.com/alimpfard
Commit: fa03a2848f
Pull-request: https://github.com/SerenityOS/serenity/pull/3505
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/devsh0
2 changed files with 18 additions and 0 deletions
|
@ -190,6 +190,14 @@ int main(int argc, char** argv)
|
|||
|
||||
editor->on_display_refresh = [&](auto& editor) {
|
||||
editor.strip_styles();
|
||||
if (shell->should_format_live()) {
|
||||
auto line = editor.line();
|
||||
ssize_t cursor = editor.cursor();
|
||||
editor.clear_line();
|
||||
editor.insert(shell->format(line, cursor));
|
||||
if (cursor >= 0)
|
||||
editor.set_cursor(cursor);
|
||||
}
|
||||
shell->highlight(editor);
|
||||
};
|
||||
editor->on_tab_complete = [&](const Line::Editor& editor) {
|
||||
|
@ -201,16 +209,20 @@ int main(int argc, char** argv)
|
|||
Vector<const char*> script_args;
|
||||
bool skip_rc_files = false;
|
||||
const char* format = nullptr;
|
||||
bool should_format_live = false;
|
||||
|
||||
Core::ArgsParser parser;
|
||||
parser.add_option(command_to_run, "String to read commands from", "command-string", 'c', "command-string");
|
||||
parser.add_option(skip_rc_files, "Skip running shellrc files", "skip-shellrc", 0);
|
||||
parser.add_option(format, "File to format", "format", 0, "file");
|
||||
parser.add_option(should_format_live, "Enable live formatting", "live-formatting", 'f');
|
||||
parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No);
|
||||
parser.add_positional_argument(script_args, "Extra argumets to pass to the script (via $* and co)", "argument", Core::ArgsParser::Required::No);
|
||||
|
||||
parser.parse(argc, argv);
|
||||
|
||||
shell->set_live_formatting(should_format_live);
|
||||
|
||||
if (format) {
|
||||
auto file = Core::File::open(format, Core::IODevice::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
|
@ -228,6 +240,7 @@ int main(int argc, char** argv)
|
|||
perror("setsid");
|
||||
// Let's just hope that it's ok.
|
||||
}
|
||||
}
|
||||
|
||||
shell->current_script = argv[0];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue