Use TERM env var / terminfo to decide whether to send ECH. Fixes tmux bug.

Closes #28 github issue.
This commit is contained in:
Keith Winstein
2012-03-10 05:41:03 -05:00
parent ac16f9127c
commit b8457dd308
13 changed files with 114 additions and 23 deletions
+1 -2
View File
@@ -3,5 +3,4 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) -fno-default-inline -pipe
noinst_LIBRARIES = libmoshterminal.a
libmoshterminal_a_SOURCES = parseraction.cc parseraction.h parser.cc parser.h parserstate.cc parserstatefamily.h parserstate.h parsertransition.h terminal.cc terminaldispatcher.cc terminaldispatcher.h terminaldisplay.cc terminaldisplay.h terminalframebuffer.cc terminalframebuffer.h terminalfunctions.cc terminal.h terminaluserinput.cc terminaluserinput.h
libmoshterminal_a_SOURCES = parseraction.cc parseraction.h parser.cc parser.h parserstate.cc parserstatefamily.h parserstate.h parsertransition.h terminal.cc terminaldispatcher.cc terminaldispatcher.h terminaldisplay.cc terminaldisplayinit.cc terminaldisplay.h terminalframebuffer.cc terminalframebuffer.h terminalfunctions.cc terminal.h terminaluserinput.cc terminaluserinput.h
+21 -6
View File
@@ -25,7 +25,7 @@ using namespace Terminal;
/* Print a new "frame" to the terminal, using ANSI/ECMA-48 escape codes. */
std::string Display::new_frame( bool initialized, const Framebuffer &last, const Framebuffer &f )
std::string Display::new_frame( bool initialized, const Framebuffer &last, const Framebuffer &f ) const
{
FrameState frame( last );
@@ -201,7 +201,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
return frame.str;
}
void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer &f )
void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer &f ) const
{
char tmp[ 64 ];
@@ -238,13 +238,28 @@ void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer &
}
}
frame.x += clear_count;
if ( frame.x >= f.ds.get_width() ) {
assert( frame.x + clear_count <= f.ds.get_width() );
/* can we go to the end of the line? */
if ( frame.x + clear_count == f.ds.get_width() ) {
snprintf( tmp, 64, "\033[K" );
frame.append( tmp );
frame.x += clear_count;
} else {
snprintf( tmp, 64, "\033[%dX", clear_count );
if ( has_ech ) {
if ( clear_count == 1 ) {
frame.append( "\033[X" );
} else {
snprintf( tmp, 64, "\033[%dX", clear_count );
frame.append( tmp );
}
frame.x += clear_count;
} else { /* no ECH, so just print a space */
frame.append( " " );
frame.cursor_x++;
frame.x++;
}
}
frame.append( tmp );
return;
}
+7 -2
View File
@@ -49,10 +49,15 @@ namespace Terminal {
class Display {
private:
static void put_cell( bool initialized, FrameState &frame, const Framebuffer &f );
bool has_ech; /* erase character is part of vt200 but not supported by tmux
(or by "screen" terminfo entry, which is what tmux advertises) */
void put_cell( bool initialized, FrameState &frame, const Framebuffer &f ) const;
public:
static std::string new_frame( bool initialized, const Framebuffer &last, const Framebuffer &f );
std::string new_frame( bool initialized, const Framebuffer &last, const Framebuffer &f ) const;
Display( bool use_environment );
};
}
+60
View File
@@ -0,0 +1,60 @@
/*
Mosh: the mobile shell
Copyright 2012 Keith Winstein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* This is in its own file because otherwise the ncurses #defines
alias our own variable names. */
#include "terminaldisplay.h"
#include <string>
#include <curses.h>
#include <term.h>
using namespace Terminal;
Display::Display( bool use_environment )
: has_ech( true )
{
if ( use_environment ) {
int errret = -2;
int ret = setupterm( (char *)0, 1, &errret );
if ( ret != OK ) {
switch ( errret ) {
case 1:
throw std::string( "Terminal is hardcopy and cannot be used by curses applications." );
break;
case 0:
throw std::string( "Unknown terminal type." );
break;
case -1:
throw std::string( "Terminfo database could not be found." );
break;
default:
throw std::string( "Unknown terminfo error." );
break;
}
}
char *val = tigetstr( "ech" );
if ( val <= 0 ) {
has_ech = false;
}
}
}