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