diff --git a/terminalframebuffer.cpp b/terminalframebuffer.cpp index a60c1d4..dcb4ef3 100644 --- a/terminalframebuffer.cpp +++ b/terminalframebuffer.cpp @@ -63,7 +63,7 @@ DrawState::DrawState( int s_width, int s_height ) cursor_col( 0 ), cursor_row( 0 ), combining_char_col( 0 ), combining_char_row( 0 ), tabs( s_width ), scrolling_region_top_row( 0 ), scrolling_region_bottom_row( height - 1 ), - renditions(), + renditions(), save(), next_print_will_wrap( false ), origin_mode( false ), auto_wrap_mode( true ) { for ( int i = 0; i < width; i++ ) { @@ -270,3 +270,31 @@ void Framebuffer::apply_renditions_to_current_cell( void ) this_cell->renditions = ds.get_renditions(); } + +SavedCursor::SavedCursor() + : cursor_col( 0 ), cursor_row( 0 ), + renditions(), + auto_wrap_mode( true ), + origin_mode( false ) +{} + +void DrawState::save_cursor( void ) +{ + save.cursor_col = cursor_col; + save.cursor_row = cursor_row; + save.renditions = renditions; + save.auto_wrap_mode = auto_wrap_mode; + save.origin_mode = origin_mode; +} + +void DrawState::restore_cursor( void ) +{ + cursor_col = save.cursor_col; + cursor_row = save.cursor_row; + renditions = save.renditions; + auto_wrap_mode = save.auto_wrap_mode; + origin_mode = save.origin_mode; + + snap_cursor_to_border(); + new_grapheme(); +} diff --git a/terminalframebuffer.hpp b/terminalframebuffer.hpp index ea5db22..dd8603d 100644 --- a/terminalframebuffer.hpp +++ b/terminalframebuffer.hpp @@ -31,6 +31,18 @@ namespace Terminal { Row( size_t s_width ); }; + class SavedCursor { + public: + int cursor_col, cursor_row; + std::vector renditions; + /* character set shift state */ + bool auto_wrap_mode; + bool origin_mode; + /* state of selective erase */ + + SavedCursor(); + }; + class DrawState { private: int width, height; @@ -47,6 +59,8 @@ namespace Terminal { std::vector renditions; + SavedCursor save; + public: bool next_print_will_wrap; bool origin_mode; @@ -82,6 +96,9 @@ namespace Terminal { void add_rendition( int x ) { renditions.push_back( x ); } const std::vector get_renditions( void ) { return renditions; } + void save_cursor( void ); + void restore_cursor( void ); + DrawState( int s_width, int s_height ); }; diff --git a/terminalfunctions.cpp b/terminalfunctions.cpp index 569e2be..43d350c 100644 --- a/terminalfunctions.cpp +++ b/terminalfunctions.cpp @@ -274,3 +274,17 @@ void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) } static Function func_CSI_SGR( CSI, "m", CSI_SGR ); + +/* save and restore cursor */ +void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +{ + fb->ds.save_cursor(); +} + +void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +{ + fb->ds.restore_cursor(); +} + +static Function func_Esc_DECSC( ESCAPE, "7", Esc_DECSC ); +static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC );