Commit graph

160 commits

Author SHA1 Message Date
Ali Mohammad Pur
d3f089dc26 Utilities/js: Make it possible to exit via two consecutive ^C's
Apparently this is common in the js repl world.
Fixes #743.
2024-07-27 11:49:45 +01:00
Timothy Flynn
ebdb92eef6 LibUnicode+Everywhere: Merge LibLocale back into LibUnicode
LibLocale was split off from LibUnicode a couple years ago to reduce the
number of applications on SerenityOS that depend on CLDR data. Now that
we use ICU, both LibUnicode and LibLocale are actually linking in this
data. And since vcpkg gives us static libraries, both libraries are over
30MB in size.

This patch reverts the separation and merges LibLocale into LibUnicode
again. We now have just one library that includes the ICU data.

Further, this will let LibUnicode share the locale cache that previously
would only exist in LibLocale.
2024-06-23 19:52:45 +02:00
Timothy Flynn
3974996e95 LibLine: Port text segmentation to the ICU text segmenter 2024-06-20 13:46:54 +02:00
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Timothy Flynn
c23060e21b Userland: Avoid some now-unneeded explicit conversions to Bytes 2024-04-04 11:23:21 +02:00
Gabriel Tassinari
30d8c5f301 LibLine: Ensure suggestions are reset after ^C 2024-02-29 09:09:47 +01:00
ronak69
7833dc0f5a LibLine: Add internal functions to search character forwards & backwards 2024-02-11 08:50:51 +01:00
ronak69
cb02d52ac9 LibLine: Add internal function to erase consecutive spaces under cursor 2024-02-11 08:50:51 +01:00
Ali Mohammad Pur
cde528fdd9 LibLine: Fully redraw on resize when origin position changes 2024-02-07 00:43:11 +01:00
kleines Filmröllchen
eada4f2ee8 AK: Remove ByteString from GenericLexer
A bunch of users used consume_specific with a constant ByteString
literal, which can be replaced by an allocation-free StringView literal.

The generic consume_while overload gains a requires clause so that
consume_specific("abc") causes a more understandable and actionable
error.
2024-01-12 17:03:53 -07:00
ronak69
9d3604215d LibLine: Implement basic cut-and-paste functionality
Every cut operation (erase last word backward/forward, erase line till
start/end) stores the erased characters in `m_last_erased` u32 vector.

The last erased characters will get inserted into the buffer when
`Ctrl+Y` (`insert_last_erased()` internal function) is pressed.
2024-01-06 13:28:17 +03:30
ronak69
97bcdba2a5 LibLine: Implement internal functions to jump cursor over non-space word
Two new internal functions `cursor_left_nonspace_word()` (`Ctrl+Alt+B`)
and `cursor_right_nonspace_word()` (`Ctrl+Alt+F`) that jump the cursor
left or right until a non-space character.

Same implementation as the alphanumeric word jump functions
`cursor_left_word()` (`Alt+B`) and `cursor_right_word()` (`Alt+F`).
2024-01-06 13:28:17 +03:30
ronak69
a6ce86a4b3 LibLine: Skip initial non-alphanumeric chars in cursor_right_word() 2024-01-06 13:28:17 +03:30
ronak69
b22be93e66 LibLine: Skip initial non-alphanumeric chars in cursor_left_word() 2024-01-06 13:28:17 +03:30
Ali Mohammad Pur
8b2beb2ebe LibLine: Use the correct loop conditions for erase_character_forwards()
Prior to this commit, the loop would continue forever and try to remove
the same index every time, eventually hitting a VERIFY and crashing.
2023-12-24 16:12:27 +01:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
db34ee357d LibLine: Avoid returning reference to cached suggestion
This caused a dangling reference down the line, which lead to funny
things like the following:
    > cd Bui[tab]
    > cd Bui^@^@

By returning a direct reference to the suggestion in question, we can be
sure that the referenced object is alive until the next suggestion
cycle.
2023-12-22 10:59:56 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Ali Mohammad Pur
36f0499cc8 LibLine: Use grapheme clusters for cursor management
This makes using the line editor much nicer when multi-code-point
graphemes are present in the input (e.g. flag emojis, or some cjk
glyphs), and avoids messing up the buffer when deleting text, or
cursoring around.
2023-12-16 22:11:43 +01:00
Ali Mohammad Pur
99cc0514a7 LibLine: Don't compare byte and code point counts of the input text
This commit fixes the odd state after pasting some text containing
multibyte code points.
This also increases the input buffer size, as reading 16 bytes at a time
felt slightly laggy when pasting a large number of emojis :^)
2023-12-16 22:11:43 +01:00
hanaa12G
19f137c1e6 LibLine: Remove duplicate members in CompletionSuggestion
Previously, we stored two representations of the same string in
`CompletionSuggestion` object: one for the bytes and the other for the
code points corresponding to those bytes. To minimize duplication, this
patch combine both representations into a single UTF-8 string, which is
already supported by our new String class.

Following this update, we successfully reduce the size of each object
from 376 bytes to 256 bytes
2023-12-15 16:58:03 +03:30
hanaa12G
e6cde722c9 LibLine: Reset m_times_tab_pressed in interrupt handling code
We forgot to reset all the variables that keep track of suggestion
state, resulting in an underflow value when calculating the lines to
display completion suggestions later.

Setting `m_times_tab_pressed` to 0 apparently forces it to recalculate
the those variables and seems to fix the problem.

Fixes #22128
2023-12-03 10:02:51 +03:30
Ali Mohammad Pur
24a7df9b09 LibLine: Move the cursor to the beginning of the final line after ^C
We previously left it at the end of the final line, which caused the
next prompt to start offset to the right:
    |$ foo^C
    |  $
This commit makes LibLine move to the beginning of that line,
making it so the next prompt shows up at the beginning of the line:
    |$ foo^C
    |$
2023-12-01 20:18:50 +03:30
hanaa12G
1f0149e5a6 LibLine: Reset state after invalid character in DSR response
While parsing DSR response, we might encounter invalid characters, for
example, when we `cat` a binary file. Previously, we just pushed those
characters in `m_incomplete_data` buffer, which worked fine until we
didn't get a terminating character. We kept increasing coordinate value
and crashed in following assertion.
2023-11-18 18:33:00 +03:30
Ali Mohammad Pur
869c7c9bab LibLine: Capture the current origin immediately after ^C
Otherwise a subsequent event (^C or resize) will make LibLine use the
previous origin instead of the real current one.
2023-11-12 13:55:20 +01:00
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
ronak69
44a46aabeb LibLine: Refresh the line after case-change operations
Previously, case-change operations did not produce visible results.
As of now, setting `m_chars_touched_in_the_middle` to a non-zero value
results in refreshing the whole line. So case-change operations now set
that variable (causing a line refresh) in order to produce visible
results as expected.
2023-08-07 22:51:49 +03:30
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Nico Weber
66e210e406 Everywhere: Use nested namespace qualifiers 2023-07-12 10:05:42 +03:30
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Timothy Flynn
aff81d318b Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-16 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.h")
2023-07-08 10:32:56 +01:00
Ali Mohammad Pur
e1e04884b9 LibLine: Handle any errors propagated through refresh_display()
This can only realistically happen when the terminal no longer exists,
so quitting with an error here is the better solution as the application
will soon be killed anyway.
Fixes #19742.
Fixes #19017.
2023-07-03 19:07:33 +03:30
Ali Mohammad Pur
7e5f1fa895 LibLine: Defer handling SIGWINCH and SIGINT
Performing these immediately can introduce a race condition between the
user's signal-related logic and LibLine's own, so defer the handlers to
make sure they run when our terminal IO cannot interfere with the
user's.
2023-07-02 16:27:52 +03:30
Ben Wiederhake
c4a9afe31a LibLine: Avoid unnecessary copies of style spans 2023-06-15 08:07:17 +02:00
Tim Schumacher
ad899b179f LibLine: Ignore ENOENT errors when loading old history
A missing history file is just an empty history, so ignore that error
and replace it with an empty array.

This regressed in f93ee3142d.
2023-06-03 05:52:52 +02:00
Ben Wiederhake
f93ee3142d LibLine: Unify history reading, prefer File over DeprecatedFile 2023-05-27 07:16:01 +02:00
Ben Wiederhake
9eeda5719e LibLine: Prefer File::read_until_eof over DeprecatedFile::read_all 2023-05-19 21:36:37 +02:00
Andreas Kling
3de8dd921e Userland: Remove serialize-to-JSON functions only used for Inspector 2023-04-25 14:48:40 +02:00
Andreas Kling
411d36719e LibCore: Simplify Core::Notifier by only allowing one event type
Not a single client of this API actually used the event mask feature to
listen for readability AND writability.

Let's simplify the API and have only one hook: on_activation.
2023-04-25 14:48:40 +02:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Ali Mohammad Pur
e312d6530b LibLine: Unify the is-empty flag in Style::unify_with() as well
Not doing so can make the final unified state incorrectly marked as
empty, and will make LibLine ignore the style.
2023-03-20 23:25:21 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher
a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Tim Schumacher
43f98ac6e1 Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00