Commit Graph

85 Commits

Author SHA1 Message Date
Ali Mohammad Pur
c257d27f0b LibLine: Turn bracketed paste mode off in Editor::restore()
We turn it on in initialize(), so turn it off in restore().
Not all CLI applications can handle this mode correctly, and there's no
reason to leave it on.
2022-05-25 23:17:15 +01:00
Ali Mohammad Pur
dd5fb7b32a LibLine: Reset next suggestion index when resetting suggestions
Otherwise we'd end up starting at the previous index on another
suggestion list.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
1699ddc186 LibLine: Make it possible to avoid autocompletion if requested
Setting 'allow_commit_without_listing' to false will now make LibLine
show the suggestion before actually committing to it; this is useful for
completions that will replace all the user input, where mistakes can go
unnoticed without some visual cue.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
d5b3998d23 LibLine: Respect the provided completion static offset
Now that we can resolve these correctly and they're per-suggestion, we
can finally use them for their intended purpose of letting suggestions
overwrite stuff in the buffer.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
6aceec4535 LibLine: Don't use fdopen() for stream in edit_in_external_editor()
We would have to fclose() it to be clean and nice, but that would close
the fd; instead just duplicate it and write through that, this makes it
actually write to the file.
2022-04-18 19:53:10 +04:30
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Ali Mohammad Pur
b732edf61c LibLine: Avoid pointless size_t <-> ssize_t cast
Just a small cleanup.
2022-03-27 21:05:44 +02:00
Ali Mohammad Pur
f6afb70b07 LibLine: Handle read events serially
Previously LibLine accepted read callbacks while it was in the process
of reading input, this wasn't an issue as no async code was being
executed up until the Shell autocompletion came along.
Simply defer input processing while processing input to avoid causing
problems.
Fixes #13280.
2022-03-27 21:05:44 +02:00
Ali Mohammad Pur
d995be428a LibLine: Add a display trivia field to suggestions
These strings will be shown next to the completions as an optional hint
or description.
2022-03-26 21:34:56 +04:30
Lenny Maiorani
103ce2f9e9 Libraries: Use default constructors/destructors in LibLine
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00
Ali Mohammad Pur
dbc2b746b8 LibLine: Reset suggestion index back to zero when fetching new ones 2022-03-06 15:34:27 +01:00
Ali Mohammad Pur
941550e601 LibLine: Make sure suggestions have their *_views set correctly 2022-03-06 15:34:27 +01:00
Ali Mohammad Pur
d7d847c8c6 LibLine: Allow the embedder to optionally handle pasted data itself
If the 'on_paste' callback is set, LibLine will buffer the pasted data
and pass it over to the embedder to use as it pleases; in practice, this
means that the users of LibLine can now escape or otherwise handle
pasted data without the incremental codepoint-by-codepoint buildup.
2022-03-06 13:20:41 +01:00
Ali Mohammad Pur
118590325a LibLine+Userland: Make suggestion offsets per-suggestion
This allows the user to modify different parts of the input with
different suggestions.
2022-03-06 13:20:41 +01:00
Ali Mohammad Pur
1fcef99ff7 LibLine: Never assume a 25x80 terminal
Just reuse the lldb hack if the normal stderr ioctl fails for any
reason, and read the size directly off /dev/tty.
2022-03-06 13:20:41 +01:00
Nícolas F. R. A. Prado
9e81c2dc83 LibLine: Update inline search cursor after kill_line (^U) command
After the kill_line (^U) command was used, searching backwards in the
history would still filter based on the text previous to the deletion.

Update the inline search cursor like already done in other internal
functions, so the text used for search is the current one.
2022-02-27 00:14:10 +03:30
Sam Atkins
8260135d4d LibCore+Everywhere: Return ErrorOr from ConfigFile factory methods
I've attempted to handle the errors gracefully where it was clear how to
do so, and simple, but a lot of this was just adding
`release_value_but_fixme_should_propagate_errors()` in places.
2022-02-16 19:49:41 -05:00
Andreas Kling
88e7d44cc4 LibJS+LibLine: Run clang-format 2022-02-13 14:55:23 +01:00
Anonymous
77511627e9 LibLine: Fix loading of terminal dimensions when running under lldb 2022-02-13 14:44:36 +01:00
Andrew Kaster
d70aba6a11 LibLine: Replace call to vfork() with fork()
We don't actually have a non-trivial vfork implementation, so just
call fork(). As a bonus, vfork() is deprecated in XCode 13.1 when
targeting macOS Big Sur, so this removes a blocker from updating our
macOS CI version.
2022-01-07 11:02:30 +01:00
Ben Wiederhake
5c4b2e8447 LibLine: Avoid unnecessary copies in Editor 2022-01-01 15:40:39 +01:00
Ali Mohammad Pur
4458cc249e LibLine: Switch all files to use east-const 2021-12-16 03:26:59 +03:30
Ali Mohammad Pur
2338d5fcda LibLine: Update the prompt origin after resize + suggestion redisplay 2021-12-16 03:26:59 +03:30
Ali Mohammad Pur
86e1d1e73d LibLine: Take the prompt into account when adjusting for a scrolled view
Otherwise we'd end up putting the prompt *after* the previous prompt
instead of *over* it when showing suggestions that span more lines than
are available without scrolling.
2021-12-16 03:26:59 +03:30
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
a15ed8743d AK: Make ByteBuffer::try_* functions return ErrorOr<void>
Same as Vector, ByteBuffer now also signals allocation failure by
returning an ENOMEM Error instead of a bool, allowing us to use the
TRY() and MUST() patterns.
2021-11-10 21:58:58 +01:00
Nico Weber
b8dc3661ac Libraries: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Andreas Kling
6ad427993a Everywhere: Behaviour => Behavior 2021-09-07 13:53:14 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
networkException
acde7d12b0 Everywhere: Rename get in ConfigFile::get_for_{lib,app,system} to open
This patch brings the ConfigFile helpers for opening lib, app and system
configs more inline with the regular ConfigFile::open functions.
2021-08-22 01:32:25 +02:00
Jamie Mansfield
137d716495 LibLine: Correct spelling mistake in variable name
This corrects the spelling of 'matching' from 'macthing'.
2021-07-21 14:15:24 +02:00
Ali Mohammad Pur
3184086679 LibLine: Avoid excessive write() syscalls when refreshing the display
Previously, we were generating the display update one character at a
time, and writing them one at a time to stderr, which is not buffered,
doing so caused one syscall per character printed which is s l o w (TM)
This commit makes LibLine write the update contents into a buffer, and
flush it after all the update is generated :^)
2021-07-20 11:55:42 +04:30
Ali Mohammad Pur
0f6654fef2 LibLine: Reset the suggestion page offset when finding the max length
Otherwise, something like shift+tab->tab->tab will mess up the page
contents (assuming that the max lengths in the pages are different).
2021-07-20 11:55:42 +04:30
Max Wipfli
9cc35d1ba3 AK: Implement String::find_any_of() and StringView::find_any_of()
This implements StringUtils::find_any_of() and uses it in
String::find_any_of() and StringView::find_any_of(). All uses of
find_{first,last}_of have been replaced with find_any_of(), find() or
find_last(). find_{first,last}_of have subsequently been removed.
2021-07-02 21:54:21 +02:00
Ali Mohammad Pur
4bf14715a1 LibLine: Recalculate the origin on resize 2021-06-23 19:04:08 +02:00
Ali Mohammad Pur
7700ee2722 LibLine: Actually remove the two levels of deferred_invoke
4d5cdcc893 partially reverted the changes
from d8c5eeceab, but it reverted too much
and reintroduced the bug.
This commit finally fixes the actual bug.
The author hasn't been in his best committing state today.
2021-06-07 02:22:40 +04:30
Ali Mohammad Pur
4d5cdcc893 LibLine: Partially revert d8c5eec and remove unrelated code
This is a partial revert of d8c5eeceab
as it contained unrelated code that was committed accidentally,
which broke history on LibLine.
2021-06-07 02:08:17 +04:30
Ali Mohammad Pur
f82aa87d14 LibLine: Keep the CSI bytes alive across read events
Otherwise we would lose the CSI parameters and intermediates if the
whole sequence was split between two reads.
Fixes #7835.
2021-06-06 23:55:20 +04:30
Ali Mohammad Pur
d8c5eeceab LibLine: Stop registering the Notifier as a child Object
We're already keeping it alive via `m_notifier`.
This makes the event loop quitting logic simpler by making less
deferred calls and removes a race condition where the notifier would be
deleted before the second deferred_invoke() would be invoked, leading
to a nullptr dereference.
Fixes #7822.
2021-06-06 23:55:20 +04:30
brapru
7843287d89 LibLine: Actually cancel the search editor on Ctl-C
When the search editor calls on really_quit_event_loop to cancel the
search, the command loaded in m_buffer would actually execute because
really_quit_event_loop sends a new line character and then afterwards
clears the buffer.

By using end_search prior to exiting the event loop, this patch will
appropriately clear the buffer, not execute any commands, and
preserve the original loaded buffer after returning from a canceled
search.
2021-06-04 11:00:24 +04:30
Max Wipfli
bc8d16ad28 Everywhere: Replace ctype.h to avoid narrowing conversions
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
2021-06-03 13:31:46 +02:00
Ben Wiederhake
a7c265f341 Everywhere: Sort out superfluous QuickSort.h imports
They were sorta unneeded. :^)
2021-05-29 23:41:54 +01:00
Ali Mohammad Pur
b2ef18d538 LibLine+Shell: Allow some programs to modify the current termios
This setting can be controlled by setting the
PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS _local_ shell variable to a
list containing such programs.
2021-05-24 23:26:49 +04:30
Ali Mohammad Pur
e318f12263 LibLine: Add bracketed paste mode support
This mode makes the editor insert all the "pasted" text into the buffer
without interpreting it in any way.
2021-05-24 23:26:49 +04:30
Gunnar Beutner
d954c11f66 Everywhere: Add missing includes for <AK/OwnPtr.h>
Previously <AK/Function.h> also included <AK/OwnPtr.h>. That's about to
change though. This patch fixes a few build problems that will occur
when that change happens.
2021-05-19 21:36:57 +02:00
Gunnar Beutner
c4d0b0cd6b Userland: Don't explicitly call Vector<T>::is_null()
This method always returns false so there's no reason for calling it.
2021-05-16 17:49:42 +02:00
Ali Mohammad Pur
bbaa463032 LibLine: Make line management less broken when at the last line
Previously, all sorts of weird stuff would happen when the editor was at
the last line of the terminal (or when the printed line would be at the
last line), this commit makes the editor scroll the terminal up before
trying to write to a row that doesn't actually exist (yet).
This fixes ^R search making a mess when initiated at the last line
(especially with multiline prompts).
2021-05-16 10:11:56 +01:00
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00