From c95c835853fe48f26c9f3e2ab1291d81fa65ddb2 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Tue, 1 Feb 2011 00:25:16 -0500 Subject: [PATCH] Insert and delete lines --- terminalframebuffer.cpp | 22 ++++++++++++++++++++++ terminalframebuffer.hpp | 2 ++ terminalfunctions.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/terminalframebuffer.cpp b/terminalframebuffer.cpp index dcb4ef3..8bcf954 100644 --- a/terminalframebuffer.cpp +++ b/terminalframebuffer.cpp @@ -298,3 +298,25 @@ void DrawState::restore_cursor( void ) snap_cursor_to_border(); new_grapheme(); } + +void Framebuffer::insert_line( int before_row ) +{ + if ( (before_row < ds.get_scrolling_region_top_row()) + || (before_row > ds.get_scrolling_region_bottom_row() + 1) ) { + return; + } + + rows.erase( rows.begin() + ds.get_scrolling_region_bottom_row() ); + rows.insert( rows.begin() + before_row, Row( ds.get_width() ) ); +} + +void Framebuffer::delete_line( int row ) +{ + if ( (row < ds.get_scrolling_region_top_row()) + || (row > ds.get_scrolling_region_bottom_row() + 1) ) { + return; + } + + rows.erase( rows.begin() + row ); + rows.insert( rows.begin() + ds.get_scrolling_region_bottom_row(), Row( ds.get_width() ) ); +} diff --git a/terminalframebuffer.hpp b/terminalframebuffer.hpp index dd8603d..112befd 100644 --- a/terminalframebuffer.hpp +++ b/terminalframebuffer.hpp @@ -120,6 +120,8 @@ namespace Terminal { void apply_renditions_to_current_cell( void ); void claim_overlap( int row, int col ); + void insert_line( int before_row ); + void delete_line( int row ); }; } diff --git a/terminalfunctions.cpp b/terminalfunctions.cpp index 7c23b7b..daacb46 100644 --- a/terminalfunctions.cpp +++ b/terminalfunctions.cpp @@ -309,3 +309,35 @@ void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) } static Function func_CSI_DSR( CSI, "n", CSI_DSR ); + +/* insert line */ +void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) +{ + int lines = dispatch->getparam( 0, 1 ); + + for ( int i = 0; i < lines; i++ ) { + fb->insert_line( fb->ds.get_cursor_row() ); + } + + /* vt220 manual and Ecma-48 say to move to first column */ + /* but xterm and gnome-terminal don't */ + fb->ds.move_col( 0 ); +} + +static Function func_CSI_IL( CSI, "L", CSI_IL ); + +/* delete line */ +void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) +{ + int lines = dispatch->getparam( 0, 1 ); + + for ( int i = 0; i < lines; i++ ) { + fb->delete_line( fb->ds.get_cursor_row() ); + } + + /* same story -- xterm and gnome-terminal don't + move to first column */ + fb->ds.move_col( 0 ); +} + +static Function func_CSI_DL( CSI, "M", CSI_DL );