2019-05-07 01:39:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-12-03 17:36:46 +11:00
|
|
|
#include <AK/BinarySearch.h>
|
|
|
|
#include <AK/QuickSort.h>
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2019-05-07 01:39:10 +02:00
|
|
|
#include <AK/Vector.h>
|
2019-09-15 23:12:43 +10:00
|
|
|
#include <LibCore/CDirIterator.h>
|
|
|
|
#include <sys/stat.h>
|
2019-05-07 01:39:10 +02:00
|
|
|
|
|
|
|
class LineEditor {
|
|
|
|
public:
|
|
|
|
LineEditor();
|
|
|
|
~LineEditor();
|
|
|
|
|
2019-07-19 20:01:46 +02:00
|
|
|
String get_line(const String& prompt);
|
2019-05-07 01:39:10 +02:00
|
|
|
|
|
|
|
void add_to_history(const String&);
|
|
|
|
const Vector<String>& history() const { return m_history; }
|
|
|
|
|
2019-12-03 17:36:46 +11:00
|
|
|
void cache_path();
|
|
|
|
|
2019-05-07 01:39:10 +02:00
|
|
|
private:
|
2019-05-07 02:50:15 +02:00
|
|
|
void clear_line();
|
|
|
|
void append(const String&);
|
2019-12-09 17:45:40 +01:00
|
|
|
void cut_mismatching_chars(String& completion, const String& program, size_t token_length);
|
2019-09-15 23:12:43 +10:00
|
|
|
void tab_complete_first_token();
|
2019-05-07 05:29:07 +02:00
|
|
|
void vt_save_cursor();
|
|
|
|
void vt_restore_cursor();
|
|
|
|
void vt_clear_to_end_of_line();
|
2019-05-07 02:50:15 +02:00
|
|
|
|
2019-05-07 01:39:10 +02:00
|
|
|
Vector<char, 1024> m_buffer;
|
2019-12-09 17:45:40 +01:00
|
|
|
size_t m_cursor { 0 };
|
2019-05-07 01:39:10 +02:00
|
|
|
|
|
|
|
// FIXME: This should be something more take_first()-friendly.
|
|
|
|
Vector<String> m_history;
|
2019-05-07 02:50:15 +02:00
|
|
|
int m_history_cursor { 0 };
|
2019-05-07 01:39:10 +02:00
|
|
|
int m_history_capacity { 100 };
|
2019-05-07 02:50:15 +02:00
|
|
|
|
2019-12-03 17:36:46 +11:00
|
|
|
Vector<String, 256> m_path;
|
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum class InputState {
|
2019-05-07 02:50:15 +02:00
|
|
|
Free,
|
|
|
|
ExpectBracket,
|
|
|
|
ExpectFinal,
|
2019-08-18 11:57:10 +10:00
|
|
|
ExpectTerminator,
|
2019-05-07 02:50:15 +02:00
|
|
|
};
|
|
|
|
InputState m_state { InputState::Free };
|
2019-05-07 01:39:10 +02:00
|
|
|
};
|