diff --git a/src/terminal/parser.cc b/src/terminal/parser.cc index 5bee08d..003bd9d 100644 --- a/src/terminal/parser.cc +++ b/src/terminal/parser.cc @@ -80,10 +80,15 @@ void Parser::UTF8Parser::input( char c, Actions &ret ) { assert( buf_len < BUF_SIZE ); + /* 1-byte UTF-8 character, aka ASCII? Cheat. */ + if ( buf_len == 0 && static_cast(c) <= 0x7f ) { + parser.input( static_cast(c), ret ); + return; + } + buf[ buf_len++ ] = c; /* This function will only work in a UTF-8 locale. */ - wchar_t pwc; mbstate_t ps = mbstate_t(); diff --git a/src/terminal/terminal.cc b/src/terminal/terminal.cc index 58f71be..e753cd6 100644 --- a/src/terminal/terminal.cc +++ b/src/terminal/terminal.cc @@ -61,7 +61,13 @@ void Emulator::print( const Parser::Print *act ) { assert( act->char_present ); - int chwidth = act->ch == L'\0' ? -1 : wcwidth( act->ch ); + const wchar_t ch = act->ch; + + /* + * Check for printing ISO 8859-1 first, it's a cheap way to detect + * some common narrow characters. + */ + const int chwidth = ch == L'\0' ? -1 : ( Cell::isprint_iso8859_1( ch ) ? 1 : wcwidth( ch )); Cell *this_cell = fb.get_mutable_cell(); @@ -100,7 +106,7 @@ void Emulator::print( const Parser::Print *act ) } fb.reset_cell( this_cell ); - this_cell->append( act->ch ); + this_cell->append( ch ); this_cell->width = chwidth; fb.apply_renditions_to_cell( this_cell ); @@ -134,7 +140,7 @@ void Emulator::print( const Parser::Print *act ) } if ( combining_cell->contents.size() < 32 ) { /* seems like a reasonable limit on combining characters */ - combining_cell->append( act->ch ); + combining_cell->append( ch ); } act->handled = true; } diff --git a/src/terminal/terminalframebuffer.h b/src/terminal/terminalframebuffer.h index d099bde..6324a32 100644 --- a/src/terminal/terminalframebuffer.h +++ b/src/terminal/terminalframebuffer.h @@ -126,8 +126,19 @@ namespace Terminal { bool compare( const Cell &other ) const; - static void append_to_str( std::string &dest, const wchar_t c ) + // Is this a printing ISO 8859-1 character? + static bool isprint_iso8859_1( const wchar_t c ) { + return ( c <= 0xff && c >= 0xa0 ) || ( c <= 0x7e && c >= 0x20 ); + } + + static void append_to_str( std::string &dest, const wchar_t c ) + { + /* ASCII? Cheat. */ + if ( static_cast(c) <= 0x7f ) { + dest.push_back( static_cast(c) ); + return; + } static mbstate_t ps = mbstate_t(); char tmp[MB_LEN_MAX]; size_t ignore = wcrtomb(NULL, 0, &ps); @@ -138,6 +149,11 @@ namespace Terminal { void append( const wchar_t c ) { + /* ASCII? Cheat. */ + if ( static_cast(c) <= 0x7f ) { + contents.push_back( static_cast(c) ); + return; + } static mbstate_t ps = mbstate_t(); char tmp[MB_LEN_MAX]; size_t ignore = wcrtomb(NULL, 0, &ps);