Implement wrapped flag on output (can turn on and off wrap in terminal)

This commit is contained in:
Keith Winstein
2011-02-10 19:59:49 -05:00
parent 71dfd5a763
commit 61251bf0bf
2 changed files with 45 additions and 0 deletions
+14
View File
@@ -45,6 +45,20 @@ void Emulator::print( Parser::Print *act )
fb.move_rows_autoscroll( 1 ); 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 ) { if ( fb.ds.insert_mode ) {
for ( int i = 0; i < chwidth; i++ ) { for ( int i = 0; i < chwidth; i++ ) {
fb.insert_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() ); fb.insert_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() );
+31
View File
@@ -1,3 +1,5 @@
#include <assert.h>
#include "terminaldisplay.hpp" #include "terminaldisplay.hpp"
using namespace Terminal; using namespace Terminal;
@@ -49,7 +51,36 @@ std::string Display::new_frame( Framebuffer &f )
/* iterate for every cell */ /* iterate for every cell */
for ( y = 0; y < f.ds.get_height(); y++ ) { 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 */ ) { 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 ); put_cell( f );
} }
} }