LineEditor.h 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <AK/AKString.h>
  3. #include <AK/Vector.h>
  4. class LineEditor {
  5. public:
  6. LineEditor();
  7. ~LineEditor();
  8. String get_line(const String& prompt);
  9. void add_to_history(const String&);
  10. const Vector<String>& history() const { return m_history; }
  11. private:
  12. void clear_line();
  13. void append(const String&);
  14. void vt_save_cursor();
  15. void vt_restore_cursor();
  16. void vt_clear_to_end_of_line();
  17. Vector<char, 1024> m_buffer;
  18. int m_cursor { 0 };
  19. // FIXME: This should be something more take_first()-friendly.
  20. Vector<String> m_history;
  21. int m_history_cursor { 0 };
  22. int m_history_capacity { 100 };
  23. enum class InputState {
  24. Free,
  25. ExpectBracket,
  26. ExpectFinal,
  27. ExpectTerminator,
  28. };
  29. InputState m_state { InputState::Free };
  30. };