| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | #include "TerminalWidget.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-03 16:11:28 +01:00
										 |  |  | #include "XtermColors.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | #include <AK/AKString.h>
 | 
					
						
							| 
									
										
										
										
											2019-01-15 10:20:20 +01:00
										 |  |  | #include <AK/StdLibExtras.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  | #include <AK/StringBuilder.h>
 | 
					
						
							|  |  |  | #include <Kernel/KeyCode.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  | #include <LibDraw/Font.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-11 15:07:05 +01:00
										 |  |  | #include <LibGUI/GApplication.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | #include <LibGUI/GClipboard.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  | #include <LibGUI/GPainter.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  | #include <LibGUI/GScrollBar.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | #include <LibGUI/GWindow.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-20 23:32:33 +01:00
										 |  |  | #include <sys/ioctl.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-23 08:55:59 +01:00
										 |  |  | //#define TERMINAL_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-01-15 10:20:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | TerminalWidget::TerminalWidget(int ptm_fd, RefPtr<CConfigFile> config) | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     : m_terminal(*this) | 
					
						
							|  |  |  |     , m_ptm_fd(ptm_fd) | 
					
						
							| 
									
										
										
										
											2019-04-10 17:35:43 +02:00
										 |  |  |     , m_notifier(ptm_fd, CNotifier::Read) | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     , m_config(move(config)) | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-11 02:27:06 +02:00
										 |  |  |     set_frame_shape(FrameShape::Container); | 
					
						
							|  |  |  |     set_frame_shadow(FrameShadow::Sunken); | 
					
						
							|  |  |  |     set_frame_thickness(2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     m_scrollbar = new GScrollBar(Orientation::Vertical, this); | 
					
						
							|  |  |  |     m_scrollbar->set_relative_rect(0, 0, 16, 0); | 
					
						
							|  |  |  |     m_scrollbar->on_change = [this](int) { | 
					
						
							|  |  |  |         force_repaint(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 16:43:15 -07:00
										 |  |  |     dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters()); | 
					
						
							|  |  |  |     m_cursor_blink_timer.set_interval(m_config->read_num_entry("Text", | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  |         "CursorBlinkInterval", | 
					
						
							|  |  |  |         500)); | 
					
						
							| 
									
										
										
										
											2019-03-30 21:40:27 +01:00
										 |  |  |     m_cursor_blink_timer.on_timeout = [this] { | 
					
						
							|  |  |  |         m_cursor_blink_state = !m_cursor_blink_state; | 
					
						
							|  |  |  |         update_cursor(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 16:43:15 -07:00
										 |  |  |     auto font_entry = m_config->read_entry("Text", "Font", "default"); | 
					
						
							|  |  |  |     if (font_entry == "default") | 
					
						
							|  |  |  |         set_font(Font::default_fixed_width_font()); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         set_font(Font::load_from_file(font_entry)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  |     m_notifier.on_ready_to_read = [this] { | 
					
						
							| 
									
										
										
										
											2019-07-03 21:17:35 +02:00
										 |  |  |         u8 buffer[BUFSIZ]; | 
					
						
							| 
									
										
										
										
											2019-04-10 17:35:43 +02:00
										 |  |  |         ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer)); | 
					
						
							| 
									
										
										
										
											2019-02-11 15:07:05 +01:00
										 |  |  |         if (nread < 0) { | 
					
						
							|  |  |  |             dbgprintf("Terminal read error: %s\n", strerror(errno)); | 
					
						
							|  |  |  |             perror("read(ptm)"); | 
					
						
							| 
									
										
										
										
											2019-02-17 09:58:35 +01:00
										 |  |  |             GApplication::the().quit(1); | 
					
						
							| 
									
										
										
										
											2019-02-11 15:07:05 +01:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (nread == 0) { | 
					
						
							|  |  |  |             dbgprintf("Terminal: EOF on master pty, closing.\n"); | 
					
						
							| 
									
										
										
										
											2019-02-17 09:58:35 +01:00
										 |  |  |             GApplication::the().quit(0); | 
					
						
							| 
									
										
										
										
											2019-02-11 15:07:05 +01:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         for (ssize_t i = 0; i < nread; ++i) | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |             m_terminal.on_char(buffer[i]); | 
					
						
							| 
									
										
										
										
											2019-02-11 15:07:05 +01:00
										 |  |  |         flush_dirty_lines(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 16:19:49 +01:00
										 |  |  |     m_line_height = font().glyph_height() + m_line_spacing; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     m_terminal.set_size(m_config->read_num_entry("Window", "Width", 80), m_config->read_num_entry("Window", "Height", 25)); | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | TerminalWidget::~TerminalWidget() | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 16:11:28 +01:00
										 |  |  | static inline Color lookup_color(unsigned color) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  |     return Color::from_rgb(xterm_colors[color]); | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | Rect TerminalWidget::glyph_rect(u16 row, u16 column) | 
					
						
							| 
									
										
										
										
											2019-01-17 16:19:49 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int y = row * m_line_height; | 
					
						
							| 
									
										
										
										
											2019-03-06 11:03:10 +01:00
										 |  |  |     int x = column * font().glyph_width('x'); | 
					
						
							| 
									
										
										
										
											2019-05-11 02:27:06 +02:00
										 |  |  |     return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x'), font().glyph_height() }; | 
					
						
							| 
									
										
										
										
											2019-01-17 16:19:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | Rect TerminalWidget::row_rect(u16 row) | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int y = row * m_line_height; | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     Rect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x') * m_terminal.columns(), font().glyph_height() }; | 
					
						
							| 
									
										
										
										
											2019-02-03 16:11:28 +01:00
										 |  |  |     rect.inflate(0, m_line_spacing); | 
					
						
							|  |  |  |     return rect; | 
					
						
							| 
									
										
										
										
											2019-01-17 16:19:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::event(CEvent& event) | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) { | 
					
						
							|  |  |  |         m_in_active_window = event.type() == GEvent::WindowBecameActive; | 
					
						
							| 
									
										
										
										
											2019-03-30 21:40:27 +01:00
										 |  |  |         if (!m_in_active_window) { | 
					
						
							|  |  |  |             m_cursor_blink_timer.stop(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_cursor_blink_state = true; | 
					
						
							|  |  |  |             m_cursor_blink_timer.start(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |         invalidate_cursor(); | 
					
						
							|  |  |  |         update(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return GWidget::event(event); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::keydown_event(GKeyEvent& event) | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-28 21:46:23 +02:00
										 |  |  |     // Reset timer so cursor doesn't blink while typing.
 | 
					
						
							|  |  |  |     m_cursor_blink_timer.stop(); | 
					
						
							|  |  |  |     m_cursor_blink_state = true; | 
					
						
							|  |  |  |     m_cursor_blink_timer.start(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     switch (event.key()) { | 
					
						
							|  |  |  |     case KeyCode::Key_Up: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[A", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     case KeyCode::Key_Down: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[B", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     case KeyCode::Key_Right: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[C", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     case KeyCode::Key_Left: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[D", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     case KeyCode::Key_Insert: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[2~", 4); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     case KeyCode::Key_Delete: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[3~", 4); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-05-07 05:03:21 +02:00
										 |  |  |     case KeyCode::Key_Home: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[H", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-05-07 05:03:21 +02:00
										 |  |  |     case KeyCode::Key_End: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[F", 3); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     case KeyCode::Key_PageUp: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[5~", 4); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     case KeyCode::Key_PageDown: | 
					
						
							|  |  |  |         write(m_ptm_fd, "\033[6~", 4); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Key event was not one of the above special cases,
 | 
					
						
							|  |  |  |     // attempt to treat it as a character...
 | 
					
						
							|  |  |  |     char ch = !event.text().is_empty() ? event.text()[0] : 0; | 
					
						
							|  |  |  |     if (ch) { | 
					
						
							|  |  |  |         if (event.ctrl()) { | 
					
						
							|  |  |  |             if (ch >= 'a' && ch <= 'z') { | 
					
						
							|  |  |  |                 ch = ch - 'a' + 1; | 
					
						
							|  |  |  |             } else if (ch == '\\') { | 
					
						
							|  |  |  |                 ch = 0x1c; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // ALT modifier sends escape prefix
 | 
					
						
							|  |  |  |         if (event.alt()) | 
					
						
							|  |  |  |             write(m_ptm_fd, "\033", 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-25 00:01:47 -05:00
										 |  |  |         //Clear the selection if we type in/behind it
 | 
					
						
							|  |  |  |         auto future_cursor_column = (event.key() == KeyCode::Key_Backspace) ? m_terminal.cursor_column() - 1 : m_terminal.cursor_column(); | 
					
						
							|  |  |  |         auto min_selection_row = min(m_selection_start.row(), m_selection_end.row()); | 
					
						
							|  |  |  |         auto max_selection_row = max(m_selection_start.row(), m_selection_end.row()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-25 11:20:32 -05:00
										 |  |  |         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) { | 
					
						
							| 
									
										
										
										
											2019-08-25 00:01:47 -05:00
										 |  |  |             m_selection_end = {}; | 
					
						
							|  |  |  |             update(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-28 21:44:32 +02:00
										 |  |  |         write(m_ptm_fd, &ch, 1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::paint_event(GPaintEvent& event) | 
					
						
							| 
									
										
										
										
											2019-05-31 12:43:58 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-11 02:27:06 +02:00
										 |  |  |     GFrame::paint_event(event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-28 17:19:56 +01:00
										 |  |  |     GPainter painter(*this); | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:45:58 +02:00
										 |  |  |     painter.add_clip_rect(event.rect()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  |     if (m_visual_beep_timer.is_active()) | 
					
						
							|  |  |  |         painter.fill_rect(frame_inner_rect(), Color::Red); | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2019-06-28 21:41:13 +02:00
										 |  |  |         painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(m_opacity)); | 
					
						
							| 
									
										
										
										
											2019-02-03 14:00:48 +01:00
										 |  |  |     invalidate_cursor(); | 
					
						
							| 
									
										
										
										
											2019-02-01 05:40:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     int rows_from_history = 0; | 
					
						
							|  |  |  |     int first_row_from_history = 0; | 
					
						
							|  |  |  |     int row_with_cursor = m_terminal.cursor_row(); | 
					
						
							|  |  |  |     if (m_scrollbar->value() != m_scrollbar->max()) { | 
					
						
							|  |  |  |         rows_from_history = min((int)m_terminal.rows(), m_scrollbar->max() - m_scrollbar->value()); | 
					
						
							|  |  |  |         first_row_from_history = m_terminal.history().size() - (m_scrollbar->max() - m_scrollbar->value()); | 
					
						
							|  |  |  |         row_with_cursor = m_terminal.cursor_row() + rows_from_history; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto line_for_visual_row = [&](u16 row) -> const VT::Terminal::Line& { | 
					
						
							|  |  |  |         if (row < rows_from_history) | 
					
						
							|  |  |  |             return m_terminal.history().at(first_row_from_history + row); | 
					
						
							|  |  |  |         return m_terminal.line(row - rows_from_history); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     for (u16 row = 0; row < m_terminal.rows(); ++row) { | 
					
						
							| 
									
										
										
										
											2019-08-13 13:55:14 +02:00
										 |  |  |         auto row_rect = this->row_rect(row); | 
					
						
							|  |  |  |         if (!event.rect().contains(row_rect)) | 
					
						
							|  |  |  |             continue; | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |         auto& line = line_for_visual_row(row); | 
					
						
							| 
									
										
										
										
											2019-01-25 02:09:29 +01:00
										 |  |  |         bool has_only_one_background_color = line.has_only_one_background_color(); | 
					
						
							| 
									
										
										
										
											2019-05-31 14:51:06 -07:00
										 |  |  |         if (m_visual_beep_timer.is_active()) | 
					
						
							| 
									
										
										
										
											2019-08-13 13:55:14 +02:00
										 |  |  |             painter.fill_rect(row_rect, Color::Red); | 
					
						
							| 
									
										
										
										
											2019-05-31 12:43:58 -07:00
										 |  |  |         else if (has_only_one_background_color) | 
					
						
							| 
									
										
										
										
											2019-08-13 13:55:14 +02:00
										 |  |  |             painter.fill_rect(row_rect, lookup_color(line.attributes[0].background_color).with_alpha(m_opacity)); | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |         for (u16 column = 0; column < m_terminal.columns(); ++column) { | 
					
						
							| 
									
										
										
										
											2019-05-29 10:53:21 -07:00
										 |  |  |             char ch = line.characters[column]; | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |             bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == row_with_cursor && column == m_terminal.cursor_column()) | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  |                 || selection_contains({ row, column }); | 
					
						
							| 
									
										
										
										
											2019-01-25 02:09:29 +01:00
										 |  |  |             auto& attribute = line.attributes[column]; | 
					
						
							| 
									
										
										
										
											2019-01-17 16:19:49 +01:00
										 |  |  |             auto character_rect = glyph_rect(row, column); | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  |             if (!has_only_one_background_color || should_reverse_fill_for_cursor_or_selection) { | 
					
						
							| 
									
										
										
										
											2019-02-08 00:21:02 +01:00
										 |  |  |                 auto cell_rect = character_rect.inflated(0, m_line_spacing); | 
					
						
							| 
									
										
										
										
											2019-06-28 21:41:13 +02:00
										 |  |  |                 painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.foreground_color : attribute.background_color).with_alpha(m_opacity)); | 
					
						
							| 
									
										
										
										
											2019-02-03 16:11:28 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-01-15 04:44:47 +01:00
										 |  |  |             if (ch == ' ') | 
					
						
							|  |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2019-08-04 08:15:30 +02:00
										 |  |  |             painter.draw_glyph( | 
					
						
							|  |  |  |                 character_rect.location(), | 
					
						
							|  |  |  |                 ch, | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |                 attribute.flags & VT::Attribute::Bold ? Font::default_bold_fixed_width_font() : font(), | 
					
						
							| 
									
										
										
										
											2019-08-04 08:15:30 +02:00
										 |  |  |                 lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.background_color : attribute.foreground_color)); | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     if (!m_in_active_window && row_with_cursor < m_terminal.rows()) { | 
					
						
							|  |  |  |         auto& cursor_line = line_for_visual_row(row_with_cursor); | 
					
						
							|  |  |  |         if (m_terminal.cursor_row() < (m_terminal.rows() - rows_from_history)) { | 
					
						
							|  |  |  |             auto cell_rect = glyph_rect(row_with_cursor, m_terminal.cursor_column()).inflated(0, m_line_spacing); | 
					
						
							|  |  |  |             painter.draw_rect(cell_rect, lookup_color(cursor_line.attributes[m_terminal.cursor_column()].foreground_color)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-02-01 05:40:27 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-15 04:30:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::set_window_title(const StringView& title) | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* w = window(); | 
					
						
							|  |  |  |     if (!w) | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-05-12 14:57:15 +02:00
										 |  |  |     w->set_title(title); | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::invalidate_cursor() | 
					
						
							| 
									
										
										
										
											2019-01-18 04:37:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     m_terminal.invalidate_cursor(); | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::flush_dirty_lines() | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     // FIXME: Update smarter when scrolled
 | 
					
						
							|  |  |  |     if (m_terminal.m_need_full_flush || m_scrollbar->value() != m_scrollbar->max()) { | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |         update(); | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |         m_terminal.m_need_full_flush = false; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  |     Rect rect; | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     for (int i = 0; i < m_terminal.rows(); ++i) { | 
					
						
							| 
									
										
										
										
											2019-08-13 13:55:14 +02:00
										 |  |  |         if (m_terminal.line(i).dirty) { | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  |             rect = rect.united(row_rect(i)); | 
					
						
							| 
									
										
										
										
											2019-08-13 13:55:14 +02:00
										 |  |  |             m_terminal.line(i).dirty = false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     update(rect); | 
					
						
							| 
									
										
										
										
											2019-01-17 17:38:04 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::force_repaint() | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-11 02:27:06 +02:00
										 |  |  |     m_needs_background_fill = true; | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  |     update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::resize_event(GResizeEvent& event) | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     auto base_size = compute_base_size(); | 
					
						
							|  |  |  |     int new_columns = (event.size().width() - base_size.width()) / font().glyph_width('x'); | 
					
						
							|  |  |  |     int new_rows = (event.size().height() - base_size.height()) / m_line_height; | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     m_terminal.set_size(new_columns, new_rows); | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Rect scrollbar_rect = { | 
					
						
							|  |  |  |         event.size().width() - m_scrollbar->width() - frame_thickness(), | 
					
						
							|  |  |  |         frame_thickness(), | 
					
						
							|  |  |  |         m_scrollbar->width(), | 
					
						
							|  |  |  |         event.size().height() - frame_thickness() * 2, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     m_scrollbar->set_relative_rect(scrollbar_rect); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Size TerminalWidget::compute_base_size() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int base_width = frame_thickness() * 2 + m_inset * 2 + m_scrollbar->width(); | 
					
						
							|  |  |  |     int base_height = frame_thickness() * 2 + m_inset * 2; | 
					
						
							|  |  |  |     return { base_width, base_height }; | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-21 00:21:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::apply_size_increments_to_window(GWindow& window) | 
					
						
							| 
									
										
										
										
											2019-02-21 00:21:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-06 11:03:10 +01:00
										 |  |  |     window.set_size_increment({ font().glyph_width('x'), m_line_height }); | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  |     window.set_base_size(compute_base_size()); | 
					
						
							| 
									
										
										
										
											2019-02-21 00:21:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-03-30 21:40:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::update_cursor() | 
					
						
							| 
									
										
										
										
											2019-03-30 21:40:27 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     invalidate_cursor(); | 
					
						
							|  |  |  |     flush_dirty_lines(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-29 19:24:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::set_opacity(u8 new_opacity) | 
					
						
							| 
									
										
										
										
											2019-04-29 19:24:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-28 21:41:13 +02:00
										 |  |  |     if (m_opacity == new_opacity) | 
					
						
							| 
									
										
										
										
											2019-04-29 19:24:18 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-06-28 21:41:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     window()->set_has_alpha_channel(new_opacity < 255); | 
					
						
							|  |  |  |     m_opacity = new_opacity; | 
					
						
							| 
									
										
										
										
											2019-04-29 19:24:18 +02:00
										 |  |  |     force_repaint(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | VT::Position TerminalWidget::normalized_selection_start() const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_selection_start < m_selection_end) | 
					
						
							|  |  |  |         return m_selection_start; | 
					
						
							|  |  |  |     return m_selection_end; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | VT::Position TerminalWidget::normalized_selection_end() const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_selection_start < m_selection_end) | 
					
						
							|  |  |  |         return m_selection_end; | 
					
						
							|  |  |  |     return m_selection_start; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | bool TerminalWidget::has_selection() const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     return m_selection_start.is_valid() && m_selection_end.is_valid(); | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | bool TerminalWidget::selection_contains(const VT::Position& position) const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (!has_selection()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return position >= normalized_selection_start() && position <= normalized_selection_end(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | VT::Position TerminalWidget::buffer_position_at(const Point& position) const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     auto adjusted_position = position.translated(-(frame_thickness() + m_inset), -(frame_thickness() + m_inset)); | 
					
						
							|  |  |  |     int row = adjusted_position.y() / m_line_height; | 
					
						
							|  |  |  |     int column = adjusted_position.x() / font().glyph_width('x'); | 
					
						
							| 
									
										
										
										
											2019-06-23 15:34:36 +02:00
										 |  |  |     if (row < 0) | 
					
						
							|  |  |  |         row = 0; | 
					
						
							| 
									
										
										
										
											2019-06-30 15:11:56 +02:00
										 |  |  |     if (column < 0) | 
					
						
							| 
									
										
										
										
											2019-06-23 15:34:36 +02:00
										 |  |  |         column = 0; | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |     if (row >= m_terminal.rows()) | 
					
						
							|  |  |  |         row = m_terminal.rows() - 1; | 
					
						
							|  |  |  |     if (column >= m_terminal.columns()) | 
					
						
							|  |  |  |         column = m_terminal.columns() - 1; | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  |     return { row, column }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 19:59:27 +02:00
										 |  |  | void TerminalWidget::doubleclick_event(GMouseEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (event.button() == GMouseButton::Left) { | 
					
						
							|  |  |  |         auto position = buffer_position_at(event.position()); | 
					
						
							|  |  |  |         auto& line = m_terminal.line(position.row()); | 
					
						
							|  |  |  |         bool want_whitespace = line.characters[position.column()] == ' '; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int start_column = 0; | 
					
						
							|  |  |  |         int end_column = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int column = position.column(); column >= 0 && (line.characters[column] == ' ') == want_whitespace; --column) { | 
					
						
							|  |  |  |             start_column = column; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int column = position.column(); column < m_terminal.columns() && (line.characters[column] == ' ') == want_whitespace; ++column) { | 
					
						
							|  |  |  |             end_column = column; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_selection_start = { position.row(), start_column }; | 
					
						
							|  |  |  |         m_selection_end = { position.row(), end_column }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (has_selection()) | 
					
						
							|  |  |  |             GClipboard::the().set_data(selected_text()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     GFrame::doubleclick_event(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::mousedown_event(GMouseEvent& event) | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (event.button() == GMouseButton::Left) { | 
					
						
							|  |  |  |         m_selection_start = buffer_position_at(event.position()); | 
					
						
							|  |  |  |         m_selection_end = {}; | 
					
						
							|  |  |  |         update(); | 
					
						
							|  |  |  |     } else if (event.button() == GMouseButton::Right) { | 
					
						
							|  |  |  |         auto text = GClipboard::the().data(); | 
					
						
							|  |  |  |         if (text.is_empty()) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         int nwritten = write(m_ptm_fd, text.characters(), text.length()); | 
					
						
							|  |  |  |         if (nwritten < 0) { | 
					
						
							|  |  |  |             perror("write"); | 
					
						
							|  |  |  |             ASSERT_NOT_REACHED(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::mousemove_event(GMouseEvent& event) | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (!(event.buttons() & GMouseButton::Left)) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto old_selection_end = m_selection_end; | 
					
						
							|  |  |  |     m_selection_end = buffer_position_at(event.position()); | 
					
						
							|  |  |  |     if (old_selection_end != m_selection_end) | 
					
						
							|  |  |  |         update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::mouseup_event(GMouseEvent& event) | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (event.button() != GMouseButton::Left) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     if (!has_selection()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     GClipboard::the().set_data(selected_text()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 20:11:56 +02:00
										 |  |  | void TerminalWidget::mousewheel_event(GMouseEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!is_scrollable()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     m_scrollbar->set_value(m_scrollbar->value() + event.wheel_delta()); | 
					
						
							|  |  |  |     GFrame::mousewheel_event(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TerminalWidget::is_scrollable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_scrollbar->is_scrollable(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | String TerminalWidget::selected_text() const | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     auto start = normalized_selection_start(); | 
					
						
							|  |  |  |     auto end = normalized_selection_end(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int row = start.row(); row <= end.row(); ++row) { | 
					
						
							| 
									
										
										
										
											2019-08-25 11:20:32 -05:00
										 |  |  |         int first_column = first_selection_column_on_row(row); | 
					
						
							|  |  |  |         int last_column = last_selection_column_on_row(row); | 
					
						
							| 
									
										
										
										
											2019-07-01 18:14:08 +02:00
										 |  |  |         for (int column = first_column; column <= last_column; ++column) { | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  |             auto& line = m_terminal.line(row); | 
					
						
							| 
									
										
										
										
											2019-07-01 18:14:08 +02:00
										 |  |  |             if (line.attributes[column].is_untouched()) { | 
					
						
							|  |  |  |                 builder.append('\n'); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             builder.append(line.characters[column]); | 
					
						
							|  |  |  |             if (column == line.m_length - 1) { | 
					
						
							|  |  |  |                 builder.append('\n'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-06-23 09:18:17 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return builder.to_string(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-25 11:20:32 -05:00
										 |  |  | int TerminalWidget::first_selection_column_on_row(int row) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return row == normalized_selection_start().row() ? normalized_selection_start().column() : 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TerminalWidget::last_selection_column_on_row(int row) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return row == normalized_selection_end().row() ? normalized_selection_end().column() : m_terminal.columns() - 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 19:12:34 +02:00
										 |  |  | void TerminalWidget::terminal_history_changed() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool was_max = m_scrollbar->value() == m_scrollbar->max(); | 
					
						
							|  |  |  |     m_scrollbar->set_max(m_terminal.history().size()); | 
					
						
							|  |  |  |     if (was_max) | 
					
						
							|  |  |  |         m_scrollbar->set_value(m_scrollbar->max()); | 
					
						
							|  |  |  |     m_scrollbar->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::terminal_did_resize(u16 columns, u16 rows) | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_pixel_width = (frame_thickness() * 2) + (m_inset * 2) + (columns * font().glyph_width('x')); | 
					
						
							|  |  |  |     m_pixel_height = (frame_thickness() * 2) + (m_inset * 2) + (rows * (font().glyph_height() + m_line_spacing)) - m_line_spacing; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); | 
					
						
							|  |  |  |     set_preferred_size(m_pixel_width, m_pixel_height); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_needs_background_fill = true; | 
					
						
							|  |  |  |     force_repaint(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     winsize ws; | 
					
						
							|  |  |  |     ws.ws_row = rows; | 
					
						
							|  |  |  |     ws.ws_col = columns; | 
					
						
							|  |  |  |     int rc = ioctl(m_ptm_fd, TIOCSWINSZ, &ws); | 
					
						
							|  |  |  |     ASSERT(rc == 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 13:21:58 +02:00
										 |  |  | void TerminalWidget::beep() | 
					
						
							| 
									
										
										
										
											2019-08-12 17:32:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_should_beep) { | 
					
						
							|  |  |  |         sysbeep(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     m_visual_beep_timer.restart(200); | 
					
						
							|  |  |  |     m_visual_beep_timer.set_single_shot(true); | 
					
						
							|  |  |  |     m_visual_beep_timer.on_timeout = [this] { | 
					
						
							|  |  |  |         force_repaint(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     force_repaint(); | 
					
						
							|  |  |  | } |