TerminalWidget.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. #include "TerminalWidget.h"
  2. #include "XtermColors.h"
  3. #include <AK/StdLibExtras.h>
  4. #include <AK/String.h>
  5. #include <AK/StringBuilder.h>
  6. #include <Kernel/KeyCode.h>
  7. #include <LibDraw/Font.h>
  8. #include <LibGUI/GApplication.h>
  9. #include <LibGUI/GClipboard.h>
  10. #include <LibGUI/GPainter.h>
  11. #include <LibGUI/GScrollBar.h>
  12. #include <LibGUI/GWindow.h>
  13. #include <errno.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <sys/ioctl.h>
  18. #include <unistd.h>
  19. //#define TERMINAL_DEBUG
  20. void TerminalWidget::set_pty_master_fd(int fd)
  21. {
  22. m_ptm_fd = fd;
  23. if (m_ptm_fd == -1) {
  24. m_notifier = nullptr;
  25. return;
  26. }
  27. m_notifier = CNotifier::construct(m_ptm_fd, CNotifier::Read);
  28. m_notifier->on_ready_to_read = [this] {
  29. u8 buffer[BUFSIZ];
  30. ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer));
  31. if (nread < 0) {
  32. dbgprintf("Terminal read error: %s\n", strerror(errno));
  33. perror("read(ptm)");
  34. GApplication::the().quit(1);
  35. return;
  36. }
  37. if (nread == 0) {
  38. dbgprintf("Terminal: EOF on master pty, firing on_command_exit hook.\n");
  39. if (on_command_exit)
  40. on_command_exit();
  41. int rc = close(m_ptm_fd);
  42. if (rc < 0) {
  43. perror("close");
  44. }
  45. set_pty_master_fd(-1);
  46. return;
  47. }
  48. for (ssize_t i = 0; i < nread; ++i)
  49. m_terminal.on_char(buffer[i]);
  50. flush_dirty_lines();
  51. };
  52. }
  53. TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<CConfigFile> config)
  54. : m_terminal(*this)
  55. , m_automatic_size_policy(automatic_size_policy)
  56. , m_config(move(config))
  57. {
  58. set_pty_master_fd(ptm_fd);
  59. m_cursor_blink_timer = CTimer::construct();
  60. m_visual_beep_timer = CTimer::construct();
  61. set_frame_shape(FrameShape::Container);
  62. set_frame_shadow(FrameShadow::Sunken);
  63. set_frame_thickness(2);
  64. m_scrollbar = GScrollBar::construct(Orientation::Vertical, this);
  65. m_scrollbar->set_relative_rect(0, 0, 16, 0);
  66. m_scrollbar->on_change = [this](int) {
  67. force_repaint();
  68. };
  69. dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters());
  70. m_cursor_blink_timer->set_interval(m_config->read_num_entry("Text",
  71. "CursorBlinkInterval",
  72. 500));
  73. m_cursor_blink_timer->on_timeout = [this] {
  74. m_cursor_blink_state = !m_cursor_blink_state;
  75. update_cursor();
  76. };
  77. auto font_entry = m_config->read_entry("Text", "Font", "default");
  78. if (font_entry == "default")
  79. set_font(Font::default_fixed_width_font());
  80. else
  81. set_font(Font::load_from_file(font_entry));
  82. m_line_height = font().glyph_height() + m_line_spacing;
  83. m_terminal.set_size(m_config->read_num_entry("Window", "Width", 80), m_config->read_num_entry("Window", "Height", 25));
  84. }
  85. TerminalWidget::~TerminalWidget()
  86. {
  87. }
  88. static inline Color lookup_color(unsigned color)
  89. {
  90. return Color::from_rgb(xterm_colors[color]);
  91. }
  92. Rect TerminalWidget::glyph_rect(u16 row, u16 column)
  93. {
  94. int y = row * m_line_height;
  95. int x = column * font().glyph_width('x');
  96. return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x'), font().glyph_height() };
  97. }
  98. Rect TerminalWidget::row_rect(u16 row)
  99. {
  100. int y = row * m_line_height;
  101. Rect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x') * m_terminal.columns(), font().glyph_height() };
  102. rect.inflate(0, m_line_spacing);
  103. return rect;
  104. }
  105. void TerminalWidget::set_logical_focus(bool focus)
  106. {
  107. m_has_logical_focus = focus;
  108. if (!m_has_logical_focus) {
  109. m_cursor_blink_timer->stop();
  110. } else {
  111. m_cursor_blink_state = true;
  112. m_cursor_blink_timer->start();
  113. }
  114. invalidate_cursor();
  115. update();
  116. }
  117. void TerminalWidget::focusin_event(CEvent& event)
  118. {
  119. set_logical_focus(true);
  120. return GFrame::focusin_event(event);
  121. }
  122. void TerminalWidget::focusout_event(CEvent& event)
  123. {
  124. set_logical_focus(false);
  125. return GFrame::focusout_event(event);
  126. }
  127. void TerminalWidget::event(CEvent& event)
  128. {
  129. if (event.type() == GEvent::WindowBecameActive)
  130. set_logical_focus(true);
  131. else if (event.type() == GEvent::WindowBecameInactive)
  132. set_logical_focus(false);
  133. return GFrame::event(event);
  134. }
  135. void TerminalWidget::keydown_event(GKeyEvent& event)
  136. {
  137. if (m_ptm_fd == -1) {
  138. event.ignore();
  139. return GFrame::keydown_event(event);
  140. }
  141. // Reset timer so cursor doesn't blink while typing.
  142. m_cursor_blink_timer->stop();
  143. m_cursor_blink_state = true;
  144. m_cursor_blink_timer->start();
  145. switch (event.key()) {
  146. case KeyCode::Key_Up:
  147. write(m_ptm_fd, "\033[A", 3);
  148. return;
  149. case KeyCode::Key_Down:
  150. write(m_ptm_fd, "\033[B", 3);
  151. return;
  152. case KeyCode::Key_Right:
  153. write(m_ptm_fd, "\033[C", 3);
  154. return;
  155. case KeyCode::Key_Left:
  156. write(m_ptm_fd, "\033[D", 3);
  157. return;
  158. case KeyCode::Key_Insert:
  159. write(m_ptm_fd, "\033[2~", 4);
  160. return;
  161. case KeyCode::Key_Delete:
  162. write(m_ptm_fd, "\033[3~", 4);
  163. return;
  164. case KeyCode::Key_Home:
  165. write(m_ptm_fd, "\033[H", 3);
  166. return;
  167. case KeyCode::Key_End:
  168. write(m_ptm_fd, "\033[F", 3);
  169. return;
  170. case KeyCode::Key_PageUp:
  171. if (event.modifiers() == Mod_Shift) {
  172. m_scrollbar->set_value(m_scrollbar->value() - m_terminal.rows());
  173. return;
  174. }
  175. write(m_ptm_fd, "\033[5~", 4);
  176. return;
  177. case KeyCode::Key_PageDown:
  178. if (event.modifiers() == Mod_Shift) {
  179. m_scrollbar->set_value(m_scrollbar->value() + m_terminal.rows());
  180. return;
  181. }
  182. write(m_ptm_fd, "\033[6~", 4);
  183. return;
  184. default:
  185. break;
  186. }
  187. // Key event was not one of the above special cases,
  188. // attempt to treat it as a character...
  189. char ch = !event.text().is_empty() ? event.text()[0] : 0;
  190. if (ch) {
  191. if (event.ctrl()) {
  192. if (ch >= 'a' && ch <= 'z') {
  193. ch = ch - 'a' + 1;
  194. } else if (ch == '\\') {
  195. ch = 0x1c;
  196. }
  197. }
  198. // ALT modifier sends escape prefix
  199. if (event.alt())
  200. write(m_ptm_fd, "\033", 1);
  201. //Clear the selection if we type in/behind it
  202. auto future_cursor_column = (event.key() == KeyCode::Key_Backspace) ? m_terminal.cursor_column() - 1 : m_terminal.cursor_column();
  203. auto min_selection_row = min(m_selection_start.row(), m_selection_end.row());
  204. auto max_selection_row = max(m_selection_start.row(), m_selection_end.row());
  205. if (future_cursor_column <= last_selection_column_on_row(m_terminal.cursor_row()) && m_terminal.cursor_row() >= min_selection_row && m_terminal.cursor_row() <= max_selection_row) {
  206. m_selection_end = {};
  207. update();
  208. }
  209. write(m_ptm_fd, &ch, 1);
  210. }
  211. m_scrollbar->set_value(m_scrollbar->max());
  212. }
  213. void TerminalWidget::paint_event(GPaintEvent& event)
  214. {
  215. GFrame::paint_event(event);
  216. GPainter painter(*this);
  217. painter.add_clip_rect(event.rect());
  218. Rect terminal_buffer_rect(frame_inner_rect().top_left(), { frame_inner_rect().width() - m_scrollbar->width(), frame_inner_rect().height() });
  219. painter.add_clip_rect(terminal_buffer_rect);
  220. if (m_visual_beep_timer->is_active())
  221. painter.fill_rect(frame_inner_rect(), Color::Red);
  222. else
  223. painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(m_opacity));
  224. invalidate_cursor();
  225. int rows_from_history = 0;
  226. int first_row_from_history = 0;
  227. int row_with_cursor = m_terminal.cursor_row();
  228. if (m_scrollbar->value() != m_scrollbar->max()) {
  229. rows_from_history = min((int)m_terminal.rows(), m_scrollbar->max() - m_scrollbar->value());
  230. first_row_from_history = m_terminal.history().size() - (m_scrollbar->max() - m_scrollbar->value());
  231. row_with_cursor = m_terminal.cursor_row() + rows_from_history;
  232. }
  233. auto line_for_visual_row = [&](u16 row) -> const VT::Terminal::Line& {
  234. if (row < rows_from_history)
  235. return m_terminal.history().at(first_row_from_history + row);
  236. return m_terminal.line(row - rows_from_history);
  237. };
  238. for (u16 row = 0; row < m_terminal.rows(); ++row) {
  239. auto row_rect = this->row_rect(row);
  240. if (!event.rect().contains(row_rect))
  241. continue;
  242. auto& line = line_for_visual_row(row);
  243. bool has_only_one_background_color = line.has_only_one_background_color();
  244. if (m_visual_beep_timer->is_active())
  245. painter.fill_rect(row_rect, Color::Red);
  246. else if (has_only_one_background_color)
  247. painter.fill_rect(row_rect, lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
  248. // The terminal insists on thinking characters and
  249. // bytes are the same thing. We want to still draw
  250. // emojis in *some* way, but it won't be completely
  251. // perfect. So what we do is we make multi-byte
  252. // characters take up multiple columns, and render
  253. // the character itself in the center of the columns
  254. // its bytes take up as far as the terminal is concerned.
  255. Utf8View utf8_view { line.text() };
  256. for (auto it = utf8_view.begin(); it != utf8_view.end(); ++it) {
  257. u32 codepoint = *it;
  258. int this_char_column = utf8_view.byte_offset_of(it);
  259. AK::Utf8CodepointIterator it_copy = it;
  260. int next_char_column = utf8_view.byte_offset_of(++it_copy);
  261. // Columns from this_char_column up until next_char_column
  262. // are logically taken up by this (possibly multi-byte)
  263. // character. Iterate over these columns and draw background
  264. // for each one of them separately.
  265. bool should_reverse_fill_for_cursor_or_selection = false;
  266. VT::Attribute attribute;
  267. for (u16 column = this_char_column; column < next_char_column; ++column) {
  268. should_reverse_fill_for_cursor_or_selection |= m_cursor_blink_state
  269. && m_has_logical_focus
  270. && row == row_with_cursor
  271. && column == m_terminal.cursor_column();
  272. should_reverse_fill_for_cursor_or_selection |= selection_contains({ row, column });
  273. attribute = line.attributes[column];
  274. auto character_rect = glyph_rect(row, column);
  275. auto cell_rect = character_rect.inflated(0, m_line_spacing);
  276. if (!has_only_one_background_color || should_reverse_fill_for_cursor_or_selection) {
  277. painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.foreground_color : attribute.background_color).with_alpha(m_opacity));
  278. }
  279. if (attribute.flags & VT::Attribute::Underline)
  280. painter.draw_line(cell_rect.bottom_left(), cell_rect.bottom_right(), lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.background_color : attribute.foreground_color));
  281. }
  282. if (codepoint == ' ')
  283. continue;
  284. auto character_rect = glyph_rect(row, this_char_column);
  285. auto num_columns = next_char_column - this_char_column;
  286. character_rect.move_by((num_columns - 1) * font().glyph_width('x') / 2, 0);
  287. painter.draw_glyph_or_emoji(
  288. character_rect.location(),
  289. codepoint,
  290. attribute.flags & VT::Attribute::Bold ? Font::default_bold_fixed_width_font() : font(),
  291. lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.background_color : attribute.foreground_color));
  292. }
  293. }
  294. if (!m_has_logical_focus && row_with_cursor < m_terminal.rows()) {
  295. auto& cursor_line = line_for_visual_row(row_with_cursor);
  296. if (m_terminal.cursor_row() < (m_terminal.rows() - rows_from_history)) {
  297. auto cell_rect = glyph_rect(row_with_cursor, m_terminal.cursor_column()).inflated(0, m_line_spacing);
  298. painter.draw_rect(cell_rect, lookup_color(cursor_line.attributes[m_terminal.cursor_column()].foreground_color));
  299. }
  300. }
  301. }
  302. void TerminalWidget::set_window_title(const StringView& title)
  303. {
  304. if (on_title_change)
  305. on_title_change(title);
  306. }
  307. void TerminalWidget::invalidate_cursor()
  308. {
  309. m_terminal.invalidate_cursor();
  310. }
  311. void TerminalWidget::flush_dirty_lines()
  312. {
  313. // FIXME: Update smarter when scrolled
  314. if (m_terminal.m_need_full_flush || m_scrollbar->value() != m_scrollbar->max()) {
  315. update();
  316. m_terminal.m_need_full_flush = false;
  317. return;
  318. }
  319. Rect rect;
  320. for (int i = 0; i < m_terminal.rows(); ++i) {
  321. if (m_terminal.line(i).dirty) {
  322. rect = rect.united(row_rect(i));
  323. m_terminal.line(i).dirty = false;
  324. }
  325. }
  326. update(rect);
  327. }
  328. void TerminalWidget::force_repaint()
  329. {
  330. m_needs_background_fill = true;
  331. update();
  332. }
  333. void TerminalWidget::resize_event(GResizeEvent& event)
  334. {
  335. auto base_size = compute_base_size();
  336. int new_columns = (event.size().width() - base_size.width()) / font().glyph_width('x');
  337. int new_rows = (event.size().height() - base_size.height()) / m_line_height;
  338. m_terminal.set_size(new_columns, new_rows);
  339. Rect scrollbar_rect = {
  340. event.size().width() - m_scrollbar->width() - frame_thickness(),
  341. frame_thickness(),
  342. m_scrollbar->width(),
  343. event.size().height() - frame_thickness() * 2,
  344. };
  345. m_scrollbar->set_relative_rect(scrollbar_rect);
  346. }
  347. Size TerminalWidget::compute_base_size() const
  348. {
  349. int base_width = frame_thickness() * 2 + m_inset * 2 + m_scrollbar->width();
  350. int base_height = frame_thickness() * 2 + m_inset * 2;
  351. return { base_width, base_height };
  352. }
  353. void TerminalWidget::apply_size_increments_to_window(GWindow& window)
  354. {
  355. window.set_size_increment({ font().glyph_width('x'), m_line_height });
  356. window.set_base_size(compute_base_size());
  357. }
  358. void TerminalWidget::update_cursor()
  359. {
  360. invalidate_cursor();
  361. flush_dirty_lines();
  362. }
  363. void TerminalWidget::set_opacity(u8 new_opacity)
  364. {
  365. if (m_opacity == new_opacity)
  366. return;
  367. window()->set_has_alpha_channel(new_opacity < 255);
  368. m_opacity = new_opacity;
  369. force_repaint();
  370. }
  371. VT::Position TerminalWidget::normalized_selection_start() const
  372. {
  373. if (m_selection_start < m_selection_end)
  374. return m_selection_start;
  375. return m_selection_end;
  376. }
  377. VT::Position TerminalWidget::normalized_selection_end() const
  378. {
  379. if (m_selection_start < m_selection_end)
  380. return m_selection_end;
  381. return m_selection_start;
  382. }
  383. bool TerminalWidget::has_selection() const
  384. {
  385. return m_selection_start.is_valid() && m_selection_end.is_valid();
  386. }
  387. bool TerminalWidget::selection_contains(const VT::Position& position) const
  388. {
  389. if (!has_selection())
  390. return false;
  391. return position >= normalized_selection_start() && position <= normalized_selection_end();
  392. }
  393. VT::Position TerminalWidget::buffer_position_at(const Point& position) const
  394. {
  395. auto adjusted_position = position.translated(-(frame_thickness() + m_inset), -(frame_thickness() + m_inset));
  396. int row = adjusted_position.y() / m_line_height;
  397. int column = adjusted_position.x() / font().glyph_width('x');
  398. if (row < 0)
  399. row = 0;
  400. if (column < 0)
  401. column = 0;
  402. if (row >= m_terminal.rows())
  403. row = m_terminal.rows() - 1;
  404. if (column >= m_terminal.columns())
  405. column = m_terminal.columns() - 1;
  406. return { row, column };
  407. }
  408. void TerminalWidget::doubleclick_event(GMouseEvent& event)
  409. {
  410. if (event.button() == GMouseButton::Left) {
  411. m_triple_click_timer.start();
  412. auto position = buffer_position_at(event.position());
  413. auto& line = m_terminal.line(position.row());
  414. bool want_whitespace = line.characters[position.column()] == ' ';
  415. int start_column = 0;
  416. int end_column = 0;
  417. for (int column = position.column(); column >= 0 && (line.characters[column] == ' ') == want_whitespace; --column) {
  418. start_column = column;
  419. }
  420. for (int column = position.column(); column < m_terminal.columns() && (line.characters[column] == ' ') == want_whitespace; ++column) {
  421. end_column = column;
  422. }
  423. m_selection_start = { position.row(), start_column };
  424. m_selection_end = { position.row(), end_column };
  425. if (has_selection())
  426. GClipboard::the().set_data(selected_text());
  427. }
  428. GFrame::doubleclick_event(event);
  429. }
  430. void TerminalWidget::mousedown_event(GMouseEvent& event)
  431. {
  432. if (event.button() == GMouseButton::Left) {
  433. if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
  434. int start_column = 0;
  435. int end_column = m_terminal.columns() - 1;
  436. auto position = buffer_position_at(event.position());
  437. m_selection_start = { position.row(), start_column };
  438. m_selection_end = { position.row(), end_column };
  439. if (has_selection())
  440. GClipboard::the().set_data(selected_text());
  441. } else {
  442. m_selection_start = buffer_position_at(event.position());
  443. m_selection_end = {};
  444. }
  445. update();
  446. } else if (event.button() == GMouseButton::Middle) {
  447. if (m_ptm_fd == -1)
  448. return;
  449. auto text = GClipboard::the().data();
  450. if (text.is_empty())
  451. return;
  452. int nwritten = write(m_ptm_fd, text.characters(), text.length());
  453. if (nwritten < 0) {
  454. perror("write");
  455. ASSERT_NOT_REACHED();
  456. }
  457. }
  458. }
  459. void TerminalWidget::mousemove_event(GMouseEvent& event)
  460. {
  461. if (!(event.buttons() & GMouseButton::Left))
  462. return;
  463. auto old_selection_end = m_selection_end;
  464. m_selection_end = buffer_position_at(event.position());
  465. if (old_selection_end != m_selection_end)
  466. update();
  467. }
  468. void TerminalWidget::mouseup_event(GMouseEvent& event)
  469. {
  470. if (event.button() != GMouseButton::Left)
  471. return;
  472. if (!has_selection())
  473. return;
  474. GClipboard::the().set_data(selected_text());
  475. }
  476. void TerminalWidget::mousewheel_event(GMouseEvent& event)
  477. {
  478. if (!is_scrollable())
  479. return;
  480. m_scrollbar->set_value(m_scrollbar->value() + event.wheel_delta());
  481. GFrame::mousewheel_event(event);
  482. }
  483. bool TerminalWidget::is_scrollable() const
  484. {
  485. return m_scrollbar->is_scrollable();
  486. }
  487. String TerminalWidget::selected_text() const
  488. {
  489. StringBuilder builder;
  490. auto start = normalized_selection_start();
  491. auto end = normalized_selection_end();
  492. for (int row = start.row(); row <= end.row(); ++row) {
  493. int first_column = first_selection_column_on_row(row);
  494. int last_column = last_selection_column_on_row(row);
  495. for (int column = first_column; column <= last_column; ++column) {
  496. auto& line = m_terminal.line(row);
  497. if (line.attributes[column].is_untouched()) {
  498. builder.append('\n');
  499. break;
  500. }
  501. builder.append(line.characters[column]);
  502. if (column == line.m_length - 1) {
  503. builder.append('\n');
  504. }
  505. }
  506. }
  507. return builder.to_string();
  508. }
  509. int TerminalWidget::first_selection_column_on_row(int row) const
  510. {
  511. return row == normalized_selection_start().row() ? normalized_selection_start().column() : 0;
  512. }
  513. int TerminalWidget::last_selection_column_on_row(int row) const
  514. {
  515. return row == normalized_selection_end().row() ? normalized_selection_end().column() : m_terminal.columns() - 1;
  516. }
  517. void TerminalWidget::terminal_history_changed()
  518. {
  519. bool was_max = m_scrollbar->value() == m_scrollbar->max();
  520. m_scrollbar->set_max(m_terminal.history().size());
  521. if (was_max)
  522. m_scrollbar->set_value(m_scrollbar->max());
  523. m_scrollbar->update();
  524. }
  525. void TerminalWidget::terminal_did_resize(u16 columns, u16 rows)
  526. {
  527. m_pixel_width = (frame_thickness() * 2) + (m_inset * 2) + (columns * font().glyph_width('x'));
  528. m_pixel_height = (frame_thickness() * 2) + (m_inset * 2) + (rows * (font().glyph_height() + m_line_spacing)) - m_line_spacing;
  529. if (m_automatic_size_policy) {
  530. set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  531. set_preferred_size(m_pixel_width, m_pixel_height);
  532. }
  533. m_needs_background_fill = true;
  534. force_repaint();
  535. winsize ws;
  536. ws.ws_row = rows;
  537. ws.ws_col = columns;
  538. if (m_ptm_fd != -1) {
  539. int rc = ioctl(m_ptm_fd, TIOCSWINSZ, &ws);
  540. ASSERT(rc == 0);
  541. }
  542. }
  543. void TerminalWidget::beep()
  544. {
  545. if (m_should_beep) {
  546. sysbeep();
  547. return;
  548. }
  549. m_visual_beep_timer->restart(200);
  550. m_visual_beep_timer->set_single_shot(true);
  551. m_visual_beep_timer->on_timeout = [this] {
  552. force_repaint();
  553. };
  554. force_repaint();
  555. }