summaryrefslogtreecommitdiff
path: root/Applications/Terminal/Terminal.cpp
diff options
context:
space:
mode:
authorChristopher Dumas <christopherdumas@gmail.com>2019-05-28 15:40:44 -0700
committerAndreas Kling <awesomekling@gmail.com>2019-06-03 20:48:34 +0200
commitce15a4021db0a77e32d40b4e5b85c7719f5541e7 (patch)
tree357f050a53d73a267657b591b9b2690e3a457afe /Applications/Terminal/Terminal.cpp
parentab004f73bf042d118da2ff326640c912703192af (diff)
downloadserenity-ce15a4021db0a77e32d40b4e5b85c7719f5541e7.zip
Terminal: Implement scroll region termcodes
Diffstat (limited to 'Applications/Terminal/Terminal.cpp')
-rw-r--r--Applications/Terminal/Terminal.cpp77
1 files changed, 71 insertions, 6 deletions
diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp
index 4ec4bb6c57..d4f70098b8 100644
--- a/Applications/Terminal/Terminal.cpp
+++ b/Applications/Terminal/Terminal.cpp
@@ -254,7 +254,13 @@ void Terminal::escape$r(const ParamVector& params)
top = params[0];
if (params.size() >= 2)
bottom = params[1];
- dbgprintf("FIXME: escape$r: Set scrolling region: %u-%u\n", top, bottom);
+ if ((bottom - top) < 2 || bottom > m_rows) {
+ dbgprintf("Error: escape: scrolling region invalid: %u-%u\n", top, bottom);
+ return;
+ }
+ m_scroll_region_top = top;
+ m_scroll_region_bottom = bottom;
+ set_cursor(0, 0);
}
void Terminal::escape$H(const ParamVector& params)
@@ -415,6 +421,42 @@ void Terminal::escape$J(const ParamVector& params)
}
}
+void Terminal::escape$S(const ParamVector& params)
+{
+ int count = 1;
+ if (params.size() >= 1)
+ count = params[0];
+ dbgprintf("Terminal: Scrolling up %d lines\n", count);
+
+ for (word i = 0; i < count; i++)
+ scroll_up();
+}
+
+void Terminal::escape$T(const ParamVector& params)
+{
+ int count = 1;
+ if (params.size() >= 1)
+ count = params[0];
+ dbgprintf("Terminal: Scrolling down %d lines\n", count);
+
+ for (word i = 0; i < count; i++)
+ scroll_down();
+}
+
+void Terminal::escape$L(const ParamVector& params)
+{
+ int count = 1;
+ if (params.size() >= 1)
+ count = params[0];
+ dbgprintf("Terminal: Adding %d lines below cursor (at line %d)\n", count, m_cursor_row);
+ invalidate_cursor();
+ for (word row = m_rows; row > m_cursor_row; --row)
+ m_lines[row] = m_lines[row - 1];
+ m_lines[m_cursor_row] = new Line(m_columns);
+ ++m_rows_to_scroll_backing_store;
+ m_need_full_flush = true;
+}
+
void Terminal::escape$M(const ParamVector& params)
{
int count = 1;
@@ -430,8 +472,11 @@ void Terminal::escape$M(const ParamVector& params)
count = min(count, max_count);
dbgprintf("Delete %d line(s) starting from %d\n", count, m_cursor_row);
- // FIXME: Implement.
- ASSERT_NOT_REACHED();
+ for (word i = 0; i < count; ++i)
+ delete m_lines[m_cursor_row + i];
+ for (word row = m_cursor_row + count + 1; row < rows(); ++row)
+ m_lines[row - 1] = m_lines[row];
+ m_lines[m_rows - 1]->clear(m_current_attribute);
}
void Terminal::execute_xterm_command()
@@ -480,6 +525,9 @@ void Terminal::execute_escape_sequence(byte final)
case 'J': escape$J(params); break;
case 'K': escape$K(params); break;
case 'M': escape$M(params); break;
+ case 'S': escape$S(params); break;
+ case 'T': escape$T(params); break;
+ case 'L': escape$L(params); break;
case 'G': escape$G(params); break;
case 'X': escape$X(params); break;
case 'd': escape$d(params); break;
@@ -512,14 +560,25 @@ void Terminal::scroll_up()
{
// NOTE: We have to invalidate the cursor first.
invalidate_cursor();
- delete m_lines[0];
- for (word row = 1; row < rows(); ++row)
+ delete m_lines[m_scroll_region_top];
+ for (word row = m_scroll_region_top + 1; row < m_scroll_region_bottom; ++row)
m_lines[row - 1] = m_lines[row];
- m_lines[m_rows - 1] = new Line(m_columns);
+ m_lines[m_scroll_region_bottom - 1] = new Line(m_columns);
++m_rows_to_scroll_backing_store;
m_need_full_flush = true;
}
+void Terminal::scroll_down()
+{
+ // NOTE: We have to invalidate the cursor first.
+ invalidate_cursor();
+ for (word row = m_scroll_region_bottom; row > m_scroll_region_top; --row)
+ m_lines[row] = m_lines[row - 1];
+ m_lines[m_scroll_region_top] = new Line(m_columns);
+ --m_rows_to_scroll_backing_store;
+ m_need_full_flush = true;
+}
+
void Terminal::set_cursor(unsigned a_row, unsigned a_column)
{
unsigned row = min(a_row, m_rows - 1u);
@@ -718,6 +777,9 @@ void Terminal::set_size(word columns, word rows)
m_columns = columns;
m_rows = rows;
+ m_scroll_region_top = 0;
+ m_scroll_region_bottom = rows;
+
m_cursor_row = 0;
m_cursor_column = 0;
m_saved_cursor_row = 0;
@@ -825,6 +887,9 @@ void Terminal::keydown_event(GKeyEvent& event)
case KeyCode::Key_End:
write(m_ptm_fd, "\033[F", 3);
break;
+ case KeyCode::Key_RightShift:
+ dbgprintf("Terminal: A wild Right Shift key is pressed. Not handled.\n");
+ break;
default:
write(m_ptm_fd, &ch, 1);
break;