1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:17:46 +00:00

Shell+LibLine: Handle escaped characters correctly

This patchset fixes incorrect handling of escaped tokens (`a\ b`) in
Shell autocompletion and LibLine.
The users of LibLine can now choose between two token splitting modes,
either taking into account escapes, or ignoring them.
This commit is contained in:
AnotherTest 2020-04-30 08:19:47 +04:30 committed by Andreas Kling
parent f2cdef5c47
commit a80ddf584f
3 changed files with 125 additions and 24 deletions

View file

@ -75,9 +75,37 @@ struct CompletionSuggestion {
String trailing_trivia;
};
struct Configuration {
enum TokenSplitMechanism {
Spaces,
UnescapedSpaces,
};
enum RefreshBehaviour {
Lazy,
Eager,
};
Configuration()
{
}
template<typename Arg, typename... Rest>
Configuration(Arg arg, Rest... rest)
: Configuration(rest...)
{
set(arg);
}
void set(RefreshBehaviour refresh) { refresh_behaviour = refresh; }
void set(TokenSplitMechanism split) { split_mechanism = split; }
RefreshBehaviour refresh_behaviour { RefreshBehaviour::Lazy };
TokenSplitMechanism split_mechanism { TokenSplitMechanism::Spaces };
};
class Editor {
public:
explicit Editor(bool always_refresh = false);
explicit Editor(Configuration configuration = {});
~Editor();
String get_line(const String& prompt);
@ -308,6 +336,8 @@ private:
bool m_refresh_needed { false };
bool m_is_editing { false };
Configuration m_configuration;
};
}