Terminal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. #include <AK/AKString.h>
  3. #include <AK/Types.h>
  4. #include <AK/Vector.h>
  5. #include <SharedGraphics/GraphicsBitmap.h>
  6. #include <SharedGraphics/Rect.h>
  7. #include <LibGUI/GWidget.h>
  8. #include <LibGUI/GNotifier.h>
  9. class Font;
  10. class Terminal final : public GWidget {
  11. public:
  12. explicit Terminal(int ptm_fd);
  13. virtual ~Terminal() override;
  14. void create_window();
  15. void on_char(byte);
  16. void flush_dirty_lines();
  17. void force_repaint();
  18. void apply_size_increments_to_window(GWindow&);
  19. private:
  20. virtual void event(GEvent&) override;
  21. virtual void paint_event(GPaintEvent&) override;
  22. virtual void resize_event(GResizeEvent&) override;
  23. virtual void keydown_event(GKeyEvent&) override;
  24. virtual const char* class_name() const override { return "Terminal"; }
  25. void scroll_up();
  26. void newline();
  27. void set_cursor(unsigned row, unsigned column);
  28. void put_character_at(unsigned row, unsigned column, byte ch);
  29. void invalidate_cursor();
  30. void set_window_title(String&&);
  31. void inject_string(const String&);
  32. void unimplemented_escape();
  33. void unimplemented_xterm_escape();
  34. void escape$A(const Vector<unsigned>&);
  35. void escape$B(const Vector<unsigned>&);
  36. void escape$C(const Vector<unsigned>&);
  37. void escape$D(const Vector<unsigned>&);
  38. void escape$H(const Vector<unsigned>&);
  39. void escape$J(const Vector<unsigned>&);
  40. void escape$K(const Vector<unsigned>&);
  41. void escape$M(const Vector<unsigned>&);
  42. void escape$G(const Vector<unsigned>&);
  43. void escape$X(const Vector<unsigned>&);
  44. void escape$d(const Vector<unsigned>&);
  45. void escape$m(const Vector<unsigned>&);
  46. void escape$s(const Vector<unsigned>&);
  47. void escape$u(const Vector<unsigned>&);
  48. void escape$t(const Vector<unsigned>&);
  49. void escape$r(const Vector<unsigned>&);
  50. void clear();
  51. void set_size(word columns, word rows);
  52. word columns() const { return m_columns; }
  53. word rows() const { return m_rows; }
  54. Rect glyph_rect(word row, word column);
  55. Rect row_rect(word row);
  56. struct Attribute {
  57. Attribute() { reset(); }
  58. void reset()
  59. {
  60. foreground_color = 7;
  61. background_color = 0;
  62. //bold = false;
  63. }
  64. byte foreground_color;
  65. byte background_color;
  66. //bool bold : 1;
  67. bool operator==(const Attribute& other) const
  68. {
  69. return foreground_color == other.foreground_color && background_color == other.background_color;
  70. }
  71. bool operator!=(const Attribute& other) const
  72. {
  73. return !(*this == other);
  74. }
  75. };
  76. struct Line {
  77. explicit Line(word columns);
  78. ~Line();
  79. void clear(Attribute);
  80. bool has_only_one_background_color() const;
  81. byte* characters { nullptr };
  82. Attribute* attributes { nullptr };
  83. bool dirty { false };
  84. word length { 0 };
  85. };
  86. Line& line(size_t index) { ASSERT(index < m_rows); return *m_lines[index]; }
  87. Line** m_lines { nullptr };
  88. word m_columns { 0 };
  89. word m_rows { 0 };
  90. byte m_cursor_row { 0 };
  91. byte m_cursor_column { 0 };
  92. byte m_saved_cursor_row { 0 };
  93. byte m_saved_cursor_column { 0 };
  94. bool m_stomp { false };
  95. Attribute m_current_attribute;
  96. void execute_escape_sequence(byte final);
  97. void execute_xterm_command();
  98. enum EscapeState {
  99. Normal,
  100. ExpectBracket,
  101. ExpectParameter,
  102. ExpectIntermediate,
  103. ExpectFinal,
  104. ExpectXtermParameter1,
  105. ExpectXtermParameter2,
  106. ExpectXtermFinal,
  107. };
  108. EscapeState m_escape_state { Normal };
  109. Vector<byte> m_parameters;
  110. Vector<byte> m_intermediates;
  111. Vector<byte> m_xterm_param1;
  112. Vector<byte> m_xterm_param2;
  113. byte m_final { 0 };
  114. byte* m_horizontal_tabs { nullptr };
  115. bool m_belling { false };
  116. int m_pixel_width { 0 };
  117. int m_pixel_height { 0 };
  118. int m_rows_to_scroll_backing_store { 0 };
  119. int m_inset { 2 };
  120. int m_line_spacing { 4 };
  121. int m_line_height { 0 };
  122. int m_ptm_fd { -1 };
  123. bool m_swallow_current { false };
  124. bool m_in_active_window { false };
  125. bool m_need_full_flush { false };
  126. GNotifier m_notifier;
  127. float m_opacity { 0.8f };
  128. bool m_needs_background_fill { true };
  129. int m_glyph_width { 0 };
  130. };