From c896055d15b029aa15a1b03fbea7fce3592c95e4 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Fri, 16 Mar 2012 13:17:28 -0400 Subject: [PATCH] Correctly render on terminals without BCE (fixes #56 github issue) --- src/terminal/terminaldisplay.cc | 8 ++++++-- src/terminal/terminaldisplay.h | 2 ++ src/terminal/terminaldisplayinit.cc | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/terminal/terminaldisplay.cc b/src/terminal/terminaldisplay.cc index ac8cb02..9b4bd35 100644 --- a/src/terminal/terminaldisplay.cc +++ b/src/terminal/terminaldisplay.cc @@ -244,12 +244,15 @@ void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer & assert( frame.x + clear_count <= f.ds.get_width() ); + bool can_use_erase = has_bce || (cell->renditions == initial_rendition()); + /* can we go to the end of the line? */ - if ( frame.x + clear_count == f.ds.get_width() ) { + if ( (frame.x + clear_count == f.ds.get_width()) + && can_use_erase ) { frame.append( "\033[K" ); frame.x += clear_count; } else { - if ( has_ech ) { + if ( has_ech && can_use_erase ) { if ( clear_count == 1 ) { frame.append( "\033[X" ); } else { @@ -258,6 +261,7 @@ void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer & } frame.x += clear_count; } else { /* no ECH, so just print a space */ + /* unlike erases, this will use background color irrespective of BCE */ frame.append( " " ); frame.cursor_x++; frame.x++; diff --git a/src/terminal/terminaldisplay.h b/src/terminal/terminaldisplay.h index d4bffea..0161c4c 100644 --- a/src/terminal/terminaldisplay.h +++ b/src/terminal/terminaldisplay.h @@ -52,6 +52,8 @@ namespace Terminal { bool has_ech; /* erase character is part of vt200 but not supported by tmux (or by "screen" terminfo entry, which is what tmux advertises) */ + bool has_bce; /* erases result in cell filled with background color */ + void put_cell( bool initialized, FrameState &frame, const Framebuffer &f ) const; public: diff --git a/src/terminal/terminaldisplayinit.cc b/src/terminal/terminaldisplayinit.cc index 22a2cd5..3b8f972 100644 --- a/src/terminal/terminaldisplayinit.cc +++ b/src/terminal/terminaldisplayinit.cc @@ -29,7 +29,7 @@ using namespace Terminal; Display::Display( bool use_environment ) - : has_ech( true ) + : has_ech( true ), has_bce( true ) { if ( use_environment ) { int errret = -2; @@ -52,12 +52,24 @@ Display::Display( bool use_environment ) } } + /* check for ECH */ char ech_name[] = "ech"; char *val = tigetstr( ech_name ); - if ( val == (char *)-1 ) + if ( val == (char *)-1 ) { throw std::string( "Invalid terminfo string capability " ) + ech_name; + } if ( val == 0 ) { has_ech = false; } + + /* check for BCE */ + char bce_name[] = "bce"; + int bce_val = tigetflag( bce_name ); + if ( bce_val == -1 ) { + throw std::string( "Invalid terminfo boolean capability " ) + bce_name; + } + if ( bce_val == 0 ) { + has_bce = false; + } } }