LineEditor.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <AK/BinarySearch.h>
  3. #include <AK/FileSystemPath.h>
  4. #include <AK/QuickSort.h>
  5. #include <AK/String.h>
  6. #include <AK/Vector.h>
  7. #include <LibCore/CDirIterator.h>
  8. #include <sys/stat.h>
  9. class LineEditor {
  10. public:
  11. LineEditor();
  12. ~LineEditor();
  13. String get_line(const String& prompt);
  14. void add_to_history(const String&);
  15. const Vector<String>& history() const { return m_history; }
  16. void cache_path();
  17. private:
  18. void clear_line();
  19. void insert(const String&);
  20. void insert(const char);
  21. void cut_mismatching_chars(String& completion, const String& other, size_t start_compare);
  22. Vector<String> tab_complete_first_token(const String&);
  23. Vector<String> tab_complete_other_token(String&);
  24. void vt_save_cursor();
  25. void vt_restore_cursor();
  26. void vt_clear_to_end_of_line();
  27. Vector<char, 1024> m_buffer;
  28. size_t m_cursor { 0 };
  29. int m_times_tab_pressed { 0 };
  30. int m_num_columns { 0 };
  31. // FIXME: This should be something more take_first()-friendly.
  32. Vector<String> m_history;
  33. int m_history_cursor { 0 };
  34. int m_history_capacity { 100 };
  35. Vector<String, 256> m_path;
  36. enum class InputState {
  37. Free,
  38. ExpectBracket,
  39. ExpectFinal,
  40. ExpectTerminator,
  41. };
  42. InputState m_state { InputState::Free };
  43. };