From 61251bf0bf91165968d8d4577662ae60e4f9815a Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Thu, 10 Feb 2011 19:59:49 -0500 Subject: [PATCH] Implement wrapped flag on output (can turn on and off wrap in terminal) --- terminal.cpp | 14 ++++++++++++++ terminaldisplay.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/terminal.cpp b/terminal.cpp index 8e76f4d..6d21a1f 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -45,6 +45,20 @@ void Emulator::print( Parser::Print *act ) fb.move_rows_autoscroll( 1 ); } + /* wrap 2-cell chars if no room, even without will-wrap flag */ + if ( fb.ds.auto_wrap_mode + && (chwidth == 2) + && (fb.ds.get_cursor_col() == fb.ds.get_width() - 1) ) { + this_cell->reset(); + fb.get_row( -1 )->wrap = false; + /* There doesn't seem to be a consistent way to get the + downstream terminal emulator to set the wrap-around + copy-and-paste flag on a row that ends with an empty cell + because a wide char was wrapped to the next line. */ + fb.ds.move_col( 0 ); + fb.move_rows_autoscroll( 1 ); + } + if ( fb.ds.insert_mode ) { for ( int i = 0; i < chwidth; i++ ) { fb.insert_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() ); diff --git a/terminaldisplay.cpp b/terminaldisplay.cpp index 3611169..71091ec 100644 --- a/terminaldisplay.cpp +++ b/terminaldisplay.cpp @@ -1,3 +1,5 @@ +#include + #include "terminaldisplay.hpp" using namespace Terminal; @@ -49,7 +51,36 @@ std::string Display::new_frame( Framebuffer &f ) /* iterate for every cell */ for ( y = 0; y < f.ds.get_height(); y++ ) { + int last_x = 0; for ( x = 0; x < f.ds.get_width(); /* let charwidth handle advance */ ) { + last_x = x; + put_cell( f ); + + /* To hint that a word-select should group the end of one line + with the beginning of the next, we let the real cursor + actually wrap around in cases where it wrapped around for us. */ + + if ( (cursor_x >= f.ds.get_width()) + && (y < f.ds.get_height() - 1) + && f.get_row( y )->wrap + && (!initialized || !last_frame.get_row( y )->wrap) ) { + /* next write will wrap */ + cursor_x = 0; + cursor_y++; + } + } + + /* Turn off wrap */ + if ( (y < f.ds.get_height() - 1) + && (!f.get_row( y )->wrap) + && (!initialized || last_frame.get_row( y )->wrap) ) { + x = last_x; + last_frame.get_cell( y, x )->reset(); + + snprintf( tmp, 64, "\033[%d;%dH\033[K", y + 1, x + 1 ); + str.append( tmp ); + cursor_x = x; + put_cell( f ); } }