2020-03-30 16:59:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-01-10 12:53:04 +00:00
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2020-03-30 16:59:04 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-30 16:59:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/BinarySearch.h>
|
2020-04-05 02:11:33 +00:00
|
|
|
#include <AK/ByteBuffer.h>
|
2020-03-30 16:59:04 +00:00
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
|
|
#include <AK/QuickSort.h>
|
2020-05-25 12:27:07 +00:00
|
|
|
#include <AK/Result.h>
|
2020-03-30 16:59:04 +00:00
|
|
|
#include <AK/String.h>
|
2020-08-17 16:08:10 +00:00
|
|
|
#include <AK/Traits.h>
|
2020-05-21 13:36:43 +00:00
|
|
|
#include <AK/Utf32View.h>
|
|
|
|
#include <AK/Utf8View.h>
|
2020-03-30 16:59:04 +00:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibCore/DirIterator.h>
|
2021-01-09 00:10:07 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2020-05-26 10:34:39 +00:00
|
|
|
#include <LibCore/Notifier.h>
|
|
|
|
#include <LibCore/Object.h>
|
2020-10-19 06:09:36 +00:00
|
|
|
#include <LibLine/KeyCallbackMachine.h>
|
2020-05-06 15:40:06 +00:00
|
|
|
#include <LibLine/Span.h>
|
2020-06-29 15:38:02 +00:00
|
|
|
#include <LibLine/StringMetrics.h>
|
2020-05-06 15:40:06 +00:00
|
|
|
#include <LibLine/Style.h>
|
2020-05-21 23:22:34 +00:00
|
|
|
#include <LibLine/SuggestionDisplay.h>
|
|
|
|
#include <LibLine/SuggestionManager.h>
|
|
|
|
#include <LibLine/VT.h>
|
2020-08-17 13:35:29 +00:00
|
|
|
#include <sys/ioctl.h>
|
2020-03-30 16:59:04 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <termios.h>
|
|
|
|
|
2020-03-31 11:34:06 +00:00
|
|
|
namespace Line {
|
|
|
|
|
2020-08-17 16:08:10 +00:00
|
|
|
struct KeyBinding {
|
2020-10-19 06:09:36 +00:00
|
|
|
Vector<Key> keys;
|
2020-08-17 16:08:10 +00:00
|
|
|
enum class Kind {
|
|
|
|
InternalFunction,
|
|
|
|
Insertion,
|
|
|
|
} kind { Kind::InternalFunction };
|
|
|
|
String binding;
|
|
|
|
};
|
|
|
|
|
2020-08-17 16:38:52 +00:00
|
|
|
struct Configuration {
|
|
|
|
enum RefreshBehaviour {
|
|
|
|
Lazy,
|
|
|
|
Eager,
|
|
|
|
};
|
|
|
|
enum OperationMode {
|
|
|
|
Unset,
|
|
|
|
Full,
|
|
|
|
NoEscapeSequences,
|
|
|
|
NonInteractive,
|
|
|
|
};
|
2021-01-09 00:10:07 +00:00
|
|
|
enum SignalHandler {
|
|
|
|
WithSignalHandlers,
|
|
|
|
NoSignalHandlers,
|
|
|
|
};
|
2020-08-17 16:38:52 +00:00
|
|
|
|
2021-04-17 17:11:38 +00:00
|
|
|
struct DefaultTextEditor {
|
|
|
|
String command;
|
|
|
|
};
|
|
|
|
|
2020-08-17 16:38:52 +00:00
|
|
|
Configuration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Arg, typename... Rest>
|
|
|
|
Configuration(Arg arg, Rest... rest)
|
|
|
|
: Configuration(rest...)
|
|
|
|
{
|
|
|
|
set(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(RefreshBehaviour refresh) { refresh_behaviour = refresh; }
|
|
|
|
void set(OperationMode mode) { operation_mode = mode; }
|
2021-01-09 00:10:07 +00:00
|
|
|
void set(SignalHandler mode) { m_signal_mode = mode; }
|
2020-08-17 16:38:52 +00:00
|
|
|
void set(const KeyBinding& binding) { keybindings.append(binding); }
|
2021-04-17 17:11:38 +00:00
|
|
|
void set(DefaultTextEditor editor) { m_default_text_editor = move(editor.command); }
|
2020-08-17 16:38:52 +00:00
|
|
|
|
|
|
|
static Configuration from_config(const StringView& libname = "line");
|
|
|
|
|
|
|
|
RefreshBehaviour refresh_behaviour { RefreshBehaviour::Lazy };
|
2021-01-09 00:10:07 +00:00
|
|
|
SignalHandler m_signal_mode { SignalHandler::WithSignalHandlers };
|
2020-08-17 16:38:52 +00:00
|
|
|
OperationMode operation_mode { OperationMode::Unset };
|
|
|
|
Vector<KeyBinding> keybindings;
|
2021-04-17 17:11:38 +00:00
|
|
|
String m_default_text_editor {};
|
2020-08-17 16:38:52 +00:00
|
|
|
};
|
|
|
|
|
2020-08-17 16:08:10 +00:00
|
|
|
#define ENUMERATE_EDITOR_INTERNAL_FUNCTIONS(M) \
|
|
|
|
M(clear_screen) \
|
|
|
|
M(cursor_left_character) \
|
|
|
|
M(cursor_left_word) \
|
|
|
|
M(cursor_right_character) \
|
|
|
|
M(cursor_right_word) \
|
|
|
|
M(enter_search) \
|
|
|
|
M(erase_character_backwards) \
|
|
|
|
M(erase_character_forwards) \
|
|
|
|
M(erase_to_beginning) \
|
|
|
|
M(erase_to_end) \
|
|
|
|
M(erase_word_backwards) \
|
|
|
|
M(finish_edit) \
|
|
|
|
M(go_end) \
|
|
|
|
M(go_home) \
|
|
|
|
M(kill_line) \
|
|
|
|
M(search_backwards) \
|
|
|
|
M(search_forwards) \
|
|
|
|
M(transpose_characters) \
|
|
|
|
M(transpose_words) \
|
|
|
|
M(insert_last_words) \
|
|
|
|
M(erase_alnum_word_backwards) \
|
|
|
|
M(erase_alnum_word_forwards) \
|
|
|
|
M(capitalize_word) \
|
|
|
|
M(lowercase_word) \
|
2021-04-17 17:11:38 +00:00
|
|
|
M(uppercase_word) \
|
|
|
|
M(edit_in_external_editor)
|
2020-08-17 16:08:10 +00:00
|
|
|
|
|
|
|
#define EDITOR_INTERNAL_FUNCTION(name) \
|
|
|
|
[](auto& editor) { editor.name(); return false; }
|
|
|
|
|
2020-05-26 10:34:39 +00:00
|
|
|
class Editor : public Core::Object {
|
|
|
|
C_OBJECT(Editor);
|
|
|
|
|
2020-03-30 16:59:04 +00:00
|
|
|
public:
|
2020-05-25 12:27:07 +00:00
|
|
|
enum class Error {
|
|
|
|
ReadFailure,
|
|
|
|
Empty,
|
|
|
|
Eof,
|
|
|
|
};
|
|
|
|
|
2020-03-31 11:34:06 +00:00
|
|
|
~Editor();
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-05-25 12:27:07 +00:00
|
|
|
Result<String, Error> get_line(const String& prompt);
|
2020-04-28 21:16:19 +00:00
|
|
|
|
2020-05-26 15:22:01 +00:00
|
|
|
void initialize();
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-10-25 23:25:41 +00:00
|
|
|
void add_to_history(const String& line);
|
|
|
|
bool load_history(const String& path);
|
|
|
|
bool save_history(const String& path);
|
2021-01-11 15:28:42 +00:00
|
|
|
const auto& history() const { return m_history; }
|
2021-05-11 15:06:03 +00:00
|
|
|
bool is_history_dirty() const { return m_history_dirty; }
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-08-17 16:08:10 +00:00
|
|
|
void register_key_input_callback(const KeyBinding&);
|
2020-10-19 06:09:36 +00:00
|
|
|
void register_key_input_callback(Vector<Key> keys, Function<bool(Editor&)> callback) { m_callback_machine.register_key_input_callback(move(keys), move(callback)); }
|
|
|
|
void register_key_input_callback(Key key, Function<bool(Editor&)> callback) { register_key_input_callback(Vector<Key> { key }, move(callback)); }
|
2020-08-17 16:08:10 +00:00
|
|
|
|
2020-08-17 21:17:19 +00:00
|
|
|
static StringMetrics actual_rendered_string_metrics(const StringView&);
|
|
|
|
static StringMetrics actual_rendered_string_metrics(const Utf32View&);
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-05-19 04:12:01 +00:00
|
|
|
Function<Vector<CompletionSuggestion>(const Editor&)> on_tab_complete;
|
2020-05-13 09:52:47 +00:00
|
|
|
Function<void()> on_interrupt_handled;
|
2020-04-05 02:11:33 +00:00
|
|
|
Function<void(Editor&)> on_display_refresh;
|
2020-03-30 17:25:09 +00:00
|
|
|
|
2020-08-17 16:08:10 +00:00
|
|
|
static Function<bool(Editor&)> find_internal_function(const StringView& name);
|
|
|
|
enum class CaseChangeOp {
|
|
|
|
Lowercase,
|
|
|
|
Uppercase,
|
|
|
|
Capital,
|
|
|
|
};
|
|
|
|
void case_change_word(CaseChangeOp);
|
|
|
|
#define __ENUMERATE_EDITOR_INTERNAL_FUNCTION(name) \
|
|
|
|
void name();
|
|
|
|
|
|
|
|
ENUMERATE_EDITOR_INTERNAL_FUNCTIONS(__ENUMERATE_EDITOR_INTERNAL_FUNCTION)
|
|
|
|
|
|
|
|
#undef __ENUMERATE_EDITOR_INTERNAL_FUNCTION
|
|
|
|
|
2020-08-20 15:34:55 +00:00
|
|
|
void interrupted();
|
2021-04-19 08:13:36 +00:00
|
|
|
void resized();
|
2020-03-30 16:59:04 +00:00
|
|
|
|
|
|
|
size_t cursor() const { return m_cursor; }
|
2020-09-16 00:35:03 +00:00
|
|
|
void set_cursor(size_t cursor)
|
|
|
|
{
|
|
|
|
if (cursor > m_buffer.size())
|
|
|
|
cursor = m_buffer.size();
|
|
|
|
m_cursor = cursor;
|
|
|
|
}
|
2020-05-18 09:17:34 +00:00
|
|
|
const Vector<u32, 1024>& buffer() const { return m_buffer; }
|
|
|
|
u32 buffer_at(size_t pos) const { return m_buffer.at(pos); }
|
2020-05-19 04:12:01 +00:00
|
|
|
String line() const { return line(m_buffer.size()); }
|
|
|
|
String line(size_t up_to_index) const;
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-05-22 22:49:48 +00:00
|
|
|
// Only makes sense inside a character_input callback or on_* callback.
|
2020-04-09 03:14:04 +00:00
|
|
|
void set_prompt(const String& prompt)
|
|
|
|
{
|
|
|
|
if (m_cached_prompt_valid)
|
2020-06-26 12:13:55 +00:00
|
|
|
m_old_prompt_metrics = m_cached_prompt_metrics;
|
2020-04-09 03:14:04 +00:00
|
|
|
m_cached_prompt_valid = false;
|
2020-06-26 12:13:55 +00:00
|
|
|
m_cached_prompt_metrics = actual_rendered_string_metrics(prompt);
|
2020-04-09 03:14:04 +00:00
|
|
|
m_new_prompt = prompt;
|
|
|
|
}
|
|
|
|
|
2020-03-30 16:59:04 +00:00
|
|
|
void clear_line();
|
|
|
|
void insert(const String&);
|
2020-08-06 18:01:56 +00:00
|
|
|
void insert(const StringView&);
|
2020-05-21 13:36:43 +00:00
|
|
|
void insert(const Utf32View&);
|
2020-05-18 09:17:34 +00:00
|
|
|
void insert(const u32);
|
2020-04-05 02:11:33 +00:00
|
|
|
void stylize(const Span&, const Style&);
|
2020-05-17 21:55:58 +00:00
|
|
|
void strip_styles(bool strip_anchored = false);
|
|
|
|
|
2020-05-21 00:44:34 +00:00
|
|
|
// Invariant Offset is an offset into the suggested data, hinting the editor what parts of the suggestion will not change
|
|
|
|
// Static Offset is an offset into the token, signifying where the suggestions start
|
|
|
|
// e.g.
|
|
|
|
// foobar<suggestion initiated>, on_tab_complete returns "barx", "bary", "barz"
|
|
|
|
// ^ ^
|
|
|
|
// +-|- static offset: the suggestions start here
|
|
|
|
// +- invariant offset: the suggestions do not change up to here
|
2020-05-21 10:45:56 +00:00
|
|
|
//
|
|
|
|
void suggest(size_t invariant_offset = 0, size_t static_offset = 0, Span::Mode offset_mode = Span::ByteOriented) const;
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-03-30 18:12:50 +00:00
|
|
|
const struct termios& termios() const { return m_termios; }
|
|
|
|
const struct termios& default_termios() const { return m_default_termios; }
|
2020-08-17 13:35:29 +00:00
|
|
|
struct winsize terminal_size() const
|
|
|
|
{
|
|
|
|
winsize ws { (u16)m_num_lines, (u16)m_num_columns, 0, 0 };
|
|
|
|
return ws;
|
|
|
|
}
|
2020-03-30 18:12:50 +00:00
|
|
|
|
2020-04-19 19:04:58 +00:00
|
|
|
void finish()
|
|
|
|
{
|
|
|
|
m_finish = true;
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:01:22 +00:00
|
|
|
bool is_editing() const { return m_is_editing; }
|
|
|
|
|
2020-06-26 12:13:55 +00:00
|
|
|
const Utf32View buffer_view() const { return { m_buffer.data(), m_buffer.size() }; }
|
|
|
|
|
2020-03-30 16:59:04 +00:00
|
|
|
private:
|
2020-08-17 14:43:52 +00:00
|
|
|
explicit Editor(Configuration configuration = Configuration::from_config());
|
2020-05-26 10:34:39 +00:00
|
|
|
|
2020-08-17 16:08:10 +00:00
|
|
|
void set_default_keybinds();
|
|
|
|
|
2020-06-26 12:13:55 +00:00
|
|
|
enum VTState {
|
|
|
|
Free = 1,
|
|
|
|
Escape = 3,
|
|
|
|
Bracket = 5,
|
|
|
|
BracketArgsSemi = 7,
|
|
|
|
Title = 9,
|
|
|
|
};
|
|
|
|
|
2021-01-10 12:53:04 +00:00
|
|
|
static VTState actual_rendered_string_length_step(StringMetrics&, size_t, StringMetrics::LineMetrics& current_line, u32, u32, VTState);
|
2020-06-26 12:13:55 +00:00
|
|
|
|
2020-08-20 15:34:55 +00:00
|
|
|
enum LoopExitCode {
|
|
|
|
Exit = 0,
|
|
|
|
Retry
|
|
|
|
};
|
|
|
|
|
2020-09-15 19:33:37 +00:00
|
|
|
// FIXME: Port to Core::Property
|
|
|
|
void save_to(JsonObject&);
|
2020-05-26 10:51:44 +00:00
|
|
|
|
2020-12-18 11:59:07 +00:00
|
|
|
void try_update_once();
|
2020-06-01 11:56:31 +00:00
|
|
|
void handle_interrupt_event();
|
2020-05-26 10:34:39 +00:00
|
|
|
void handle_read_event();
|
|
|
|
|
2021-05-16 05:15:22 +00:00
|
|
|
void ensure_free_lines_from_origin(size_t count);
|
|
|
|
|
2020-04-09 03:14:04 +00:00
|
|
|
Vector<size_t, 2> vt_dsr();
|
2020-05-17 21:55:58 +00:00
|
|
|
void remove_at_index(size_t);
|
|
|
|
|
|
|
|
enum class ModificationKind {
|
|
|
|
Insertion,
|
|
|
|
Removal,
|
2020-05-21 00:44:34 +00:00
|
|
|
ForcedOverlapRemoval,
|
2020-05-17 21:55:58 +00:00
|
|
|
};
|
|
|
|
void readjust_anchored_styles(size_t hint_index, ModificationKind);
|
2020-04-05 02:11:33 +00:00
|
|
|
|
|
|
|
Style find_applicable_style(size_t offset) const;
|
|
|
|
|
2020-09-06 20:14:55 +00:00
|
|
|
bool search(const StringView&, bool allow_empty = false, bool from_beginning = true);
|
2020-04-19 19:04:58 +00:00
|
|
|
inline void end_search()
|
|
|
|
{
|
|
|
|
m_is_searching = false;
|
|
|
|
m_refresh_needed = true;
|
|
|
|
m_search_offset = 0;
|
|
|
|
if (m_reset_buffer_on_search_end) {
|
2020-04-20 13:23:24 +00:00
|
|
|
m_buffer.clear();
|
|
|
|
for (auto ch : m_pre_search_buffer)
|
|
|
|
m_buffer.append(ch);
|
2020-04-19 19:04:58 +00:00
|
|
|
m_cursor = m_pre_search_cursor;
|
|
|
|
}
|
2020-04-20 13:23:24 +00:00
|
|
|
m_reset_buffer_on_search_end = true;
|
2020-04-19 19:04:58 +00:00
|
|
|
m_search_editor = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-09 03:14:04 +00:00
|
|
|
void reset()
|
|
|
|
{
|
2020-06-26 12:13:55 +00:00
|
|
|
m_cached_buffer_metrics.reset();
|
2020-05-11 07:25:42 +00:00
|
|
|
m_cached_prompt_valid = false;
|
|
|
|
m_cursor = 0;
|
|
|
|
m_drawn_cursor = 0;
|
|
|
|
m_inline_search_cursor = 0;
|
2020-08-23 13:14:07 +00:00
|
|
|
m_search_offset = 0;
|
|
|
|
m_search_offset_state = SearchOffsetState::Unbiased;
|
2020-06-26 12:13:55 +00:00
|
|
|
m_old_prompt_metrics = m_cached_prompt_metrics;
|
2020-05-21 23:22:34 +00:00
|
|
|
set_origin(0, 0);
|
2020-05-11 07:25:42 +00:00
|
|
|
m_prompt_lines_at_suggestion_initiation = 0;
|
2020-04-09 03:14:04 +00:00
|
|
|
m_refresh_needed = true;
|
2020-05-25 12:27:07 +00:00
|
|
|
m_input_error.clear();
|
2020-05-26 10:34:39 +00:00
|
|
|
m_returned_line = String::empty();
|
2021-02-21 00:33:43 +00:00
|
|
|
m_chars_touched_in_the_middle = 0;
|
|
|
|
m_drawn_end_of_line_offset = 0;
|
|
|
|
m_drawn_spans = {};
|
2020-04-09 03:14:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 02:11:33 +00:00
|
|
|
void refresh_display();
|
2020-04-19 19:04:58 +00:00
|
|
|
void cleanup();
|
2020-08-31 17:34:32 +00:00
|
|
|
void cleanup_suggestions();
|
2020-08-20 15:34:55 +00:00
|
|
|
void really_quit_event_loop();
|
2020-04-05 02:11:33 +00:00
|
|
|
|
2020-04-28 21:16:19 +00:00
|
|
|
void restore()
|
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(m_initialized);
|
2020-04-28 21:16:19 +00:00
|
|
|
tcsetattr(0, TCSANOW, &m_default_termios);
|
|
|
|
m_initialized = false;
|
2021-01-09 00:10:07 +00:00
|
|
|
for (auto id : m_signal_handlers)
|
|
|
|
Core::EventLoop::unregister_signal(id);
|
2020-04-28 21:16:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 12:13:55 +00:00
|
|
|
const StringMetrics& current_prompt_metrics() const
|
2020-04-09 03:14:04 +00:00
|
|
|
{
|
2020-06-26 12:13:55 +00:00
|
|
|
return m_cached_prompt_valid ? m_cached_prompt_metrics : m_old_prompt_metrics;
|
2020-04-09 03:14:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 02:11:33 +00:00
|
|
|
size_t num_lines() const
|
|
|
|
{
|
2020-06-26 12:13:55 +00:00
|
|
|
return current_prompt_metrics().lines_with_addition(m_cached_buffer_metrics, m_num_columns);
|
2020-04-05 02:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t cursor_line() const
|
|
|
|
{
|
2020-06-26 12:13:55 +00:00
|
|
|
auto cursor = m_drawn_cursor;
|
|
|
|
if (cursor > m_cursor)
|
|
|
|
cursor = m_cursor;
|
|
|
|
return current_prompt_metrics().lines_with_addition(
|
|
|
|
actual_rendered_string_metrics(buffer_view().substring_view(0, cursor)),
|
|
|
|
m_num_columns);
|
2020-04-05 02:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t offset_in_line() const
|
|
|
|
{
|
2020-06-26 12:13:55 +00:00
|
|
|
auto cursor = m_drawn_cursor;
|
|
|
|
if (cursor > m_cursor)
|
|
|
|
cursor = m_cursor;
|
|
|
|
auto buffer_metrics = actual_rendered_string_metrics(buffer_view().substring_view(0, cursor));
|
2021-01-04 08:08:56 +00:00
|
|
|
return current_prompt_metrics().offset_with_addition(buffer_metrics, m_num_columns);
|
2020-04-09 03:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_origin()
|
|
|
|
{
|
|
|
|
auto position = vt_dsr();
|
2020-05-21 23:22:34 +00:00
|
|
|
set_origin(position[0], position[1]);
|
|
|
|
}
|
|
|
|
|
2020-06-07 20:18:40 +00:00
|
|
|
void set_origin(int row, int col)
|
2020-05-21 23:22:34 +00:00
|
|
|
{
|
2020-06-07 20:18:40 +00:00
|
|
|
m_origin_row = row;
|
|
|
|
m_origin_column = col;
|
|
|
|
m_suggestion_display->set_origin(row, col, {});
|
2020-04-05 02:11:33 +00:00
|
|
|
}
|
2020-05-19 04:12:01 +00:00
|
|
|
|
2020-04-11 09:36:46 +00:00
|
|
|
void recalculate_origin();
|
2020-06-29 15:38:02 +00:00
|
|
|
void reposition_cursor(bool to_end = false);
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-05-21 10:45:56 +00:00
|
|
|
struct CodepointRange {
|
|
|
|
size_t start { 0 };
|
|
|
|
size_t end { 0 };
|
|
|
|
};
|
2020-08-05 20:31:20 +00:00
|
|
|
CodepointRange byte_offset_range_to_code_point_offset_range(size_t byte_start, size_t byte_end, size_t code_point_scan_offset, bool reverse = false) const;
|
2020-05-21 10:45:56 +00:00
|
|
|
|
2020-07-06 15:28:11 +00:00
|
|
|
void get_terminal_size();
|
|
|
|
|
2020-04-19 19:04:58 +00:00
|
|
|
bool m_finish { false };
|
|
|
|
|
2020-05-26 10:34:39 +00:00
|
|
|
RefPtr<Editor> m_search_editor;
|
2020-04-19 19:04:58 +00:00
|
|
|
bool m_is_searching { false };
|
|
|
|
bool m_reset_buffer_on_search_end { true };
|
|
|
|
size_t m_search_offset { 0 };
|
2020-08-23 13:14:07 +00:00
|
|
|
enum class SearchOffsetState {
|
|
|
|
Unbiased,
|
|
|
|
Backwards,
|
|
|
|
Forwards,
|
|
|
|
} m_search_offset_state { SearchOffsetState::Unbiased };
|
2020-04-19 19:04:58 +00:00
|
|
|
size_t m_pre_search_cursor { 0 };
|
2020-05-18 09:17:34 +00:00
|
|
|
Vector<u32, 1024> m_pre_search_buffer;
|
2020-04-19 19:04:58 +00:00
|
|
|
|
2020-05-18 09:17:34 +00:00
|
|
|
Vector<u32, 1024> m_buffer;
|
2020-04-05 02:11:33 +00:00
|
|
|
ByteBuffer m_pending_chars;
|
2020-05-25 12:27:07 +00:00
|
|
|
Vector<char, 512> m_incomplete_data;
|
|
|
|
Optional<Error> m_input_error;
|
2020-05-26 10:34:39 +00:00
|
|
|
String m_returned_line;
|
2020-05-25 12:27:07 +00:00
|
|
|
|
2020-03-30 16:59:04 +00:00
|
|
|
size_t m_cursor { 0 };
|
2020-04-09 03:14:04 +00:00
|
|
|
size_t m_drawn_cursor { 0 };
|
2021-02-20 18:03:13 +00:00
|
|
|
size_t m_drawn_end_of_line_offset { 0 };
|
2020-04-20 12:50:31 +00:00
|
|
|
size_t m_inline_search_cursor { 0 };
|
2021-02-20 18:03:13 +00:00
|
|
|
size_t m_chars_touched_in_the_middle { 0 };
|
2020-03-30 16:59:04 +00:00
|
|
|
size_t m_times_tab_pressed { 0 };
|
|
|
|
size_t m_num_columns { 0 };
|
2020-04-11 08:59:55 +00:00
|
|
|
size_t m_num_lines { 1 };
|
2020-07-06 15:28:11 +00:00
|
|
|
size_t m_previous_num_columns { 0 };
|
2020-06-26 12:13:55 +00:00
|
|
|
size_t m_extra_forward_lines { 0 };
|
|
|
|
StringMetrics m_cached_prompt_metrics;
|
|
|
|
StringMetrics m_old_prompt_metrics;
|
|
|
|
StringMetrics m_cached_buffer_metrics;
|
2020-04-14 17:48:56 +00:00
|
|
|
size_t m_prompt_lines_at_suggestion_initiation { 0 };
|
2020-04-09 03:14:04 +00:00
|
|
|
bool m_cached_prompt_valid { false };
|
|
|
|
|
2020-05-22 22:49:48 +00:00
|
|
|
// Exact position before our prompt in the terminal.
|
2020-06-07 20:18:40 +00:00
|
|
|
size_t m_origin_row { 0 };
|
|
|
|
size_t m_origin_column { 0 };
|
2020-04-09 03:14:04 +00:00
|
|
|
|
2020-05-21 23:22:34 +00:00
|
|
|
OwnPtr<SuggestionDisplay> m_suggestion_display;
|
|
|
|
|
2020-04-09 03:14:04 +00:00
|
|
|
String m_new_prompt;
|
2020-05-21 23:22:34 +00:00
|
|
|
|
|
|
|
SuggestionManager m_suggestion_manager;
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-04-19 19:04:58 +00:00
|
|
|
bool m_always_refresh { false };
|
|
|
|
|
2020-04-11 18:35:39 +00:00
|
|
|
enum class TabDirection {
|
|
|
|
Forward,
|
|
|
|
Backward,
|
|
|
|
};
|
|
|
|
TabDirection m_tab_direction { TabDirection::Forward };
|
|
|
|
|
2020-10-19 06:09:36 +00:00
|
|
|
KeyCallbackMachine m_callback_machine;
|
2020-03-30 16:59:04 +00:00
|
|
|
|
2020-08-17 14:43:52 +00:00
|
|
|
struct termios m_termios {
|
|
|
|
};
|
|
|
|
struct termios m_default_termios {
|
|
|
|
};
|
2020-04-19 19:04:58 +00:00
|
|
|
bool m_was_interrupted { false };
|
2021-02-06 23:42:17 +00:00
|
|
|
bool m_previous_interrupt_was_handled_as_interrupt { true };
|
2020-04-19 19:04:58 +00:00
|
|
|
bool m_was_resized { false };
|
2020-03-30 16:59:04 +00:00
|
|
|
|
|
|
|
// FIXME: This should be something more take_first()-friendly.
|
2021-01-11 15:28:42 +00:00
|
|
|
struct HistoryEntry {
|
|
|
|
String entry;
|
|
|
|
time_t timestamp;
|
|
|
|
};
|
|
|
|
Vector<HistoryEntry> m_history;
|
2020-03-30 16:59:04 +00:00
|
|
|
size_t m_history_cursor { 0 };
|
2021-01-11 15:28:42 +00:00
|
|
|
size_t m_history_capacity { 1024 };
|
2021-05-11 15:06:03 +00:00
|
|
|
bool m_history_dirty { false };
|
2020-03-30 16:59:04 +00:00
|
|
|
|
|
|
|
enum class InputState {
|
|
|
|
Free,
|
2021-01-10 12:53:04 +00:00
|
|
|
Verbatim,
|
2020-08-06 14:52:18 +00:00
|
|
|
GotEscape,
|
2020-09-14 00:33:04 +00:00
|
|
|
CSIExpectParameter,
|
|
|
|
CSIExpectIntermediate,
|
|
|
|
CSIExpectFinal,
|
2020-03-30 16:59:04 +00:00
|
|
|
};
|
|
|
|
InputState m_state { InputState::Free };
|
|
|
|
|
2021-02-20 18:03:13 +00:00
|
|
|
struct Spans {
|
|
|
|
HashMap<u32, HashMap<u32, Style>> m_spans_starting;
|
|
|
|
HashMap<u32, HashMap<u32, Style>> m_spans_ending;
|
|
|
|
HashMap<u32, HashMap<u32, Style>> m_anchored_spans_starting;
|
|
|
|
HashMap<u32, HashMap<u32, Style>> m_anchored_spans_ending;
|
2020-04-05 02:11:33 +00:00
|
|
|
|
2021-02-20 18:03:13 +00:00
|
|
|
bool contains_up_to_offset(const Spans& other, size_t offset) const;
|
|
|
|
} m_drawn_spans, m_current_spans;
|
2020-05-17 21:55:58 +00:00
|
|
|
|
2020-05-26 10:34:39 +00:00
|
|
|
RefPtr<Core::Notifier> m_notifier;
|
|
|
|
|
2020-04-05 02:11:33 +00:00
|
|
|
bool m_initialized { false };
|
|
|
|
bool m_refresh_needed { false };
|
2021-01-09 00:10:07 +00:00
|
|
|
Vector<int, 2> m_signal_handlers;
|
2020-04-28 20:01:22 +00:00
|
|
|
|
|
|
|
bool m_is_editing { false };
|
2020-04-30 03:49:47 +00:00
|
|
|
|
|
|
|
Configuration m_configuration;
|
2020-03-30 16:59:04 +00:00
|
|
|
};
|
2020-03-31 11:34:06 +00:00
|
|
|
|
|
|
|
}
|