Handle cursor key mode (application vs. ANSI). "less" now works.
This commit is contained in:
+2
-1
@@ -68,5 +68,6 @@ void OSC_End::act_on_terminal( Terminal::Emulator *emu )
|
|||||||
|
|
||||||
void UserByte::act_on_terminal( Terminal::Emulator *emu )
|
void UserByte::act_on_terminal( Terminal::Emulator *emu )
|
||||||
{
|
{
|
||||||
emu->dispatch.terminal_to_host.append( emu->user.input( this ) );
|
emu->dispatch.terminal_to_host.append( emu->user.input( this,
|
||||||
|
emu->fb.ds.application_mode_cursor_keys ) );
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-4
@@ -127,28 +127,32 @@ void emulate_terminal( int fd, int debug_fd )
|
|||||||
pollfds[ 1 ].fd = fd;
|
pollfds[ 1 ].fd = fd;
|
||||||
pollfds[ 1 ].events = POLLIN;
|
pollfds[ 1 ].events = POLLIN;
|
||||||
|
|
||||||
|
swrite( STDOUT_FILENO, terminal.open().c_str() );
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
int active_fds = poll( pollfds, 2, -1 );
|
int active_fds = poll( pollfds, 2, -1 );
|
||||||
if ( active_fds <= 0 ) {
|
if ( active_fds <= 0 ) {
|
||||||
perror( "poll" );
|
perror( "poll" );
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pollfds[ 0 ].revents & POLLIN ) {
|
if ( pollfds[ 0 ].revents & POLLIN ) {
|
||||||
if ( termemu( fd, STDIN_FILENO, true, debug_fd, &parser, &terminal ) < 0 ) {
|
if ( termemu( fd, STDIN_FILENO, true, debug_fd, &parser, &terminal ) < 0 ) {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
} else if ( pollfds[ 1 ].revents & POLLIN ) {
|
} else if ( pollfds[ 1 ].revents & POLLIN ) {
|
||||||
if ( termemu( fd, fd, false, debug_fd, &parser, &terminal ) < 0 ) {
|
if ( termemu( fd, fd, false, debug_fd, &parser, &terminal ) < 0 ) {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
} else if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
|
} else if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
|
||||||
& (POLLERR | POLLHUP | POLLNVAL) ) {
|
& (POLLERR | POLLHUP | POLLNVAL) ) {
|
||||||
return;
|
break;
|
||||||
} else {
|
} else {
|
||||||
fprintf( stderr, "poll mysteriously woken up\n" );
|
fprintf( stderr, "poll mysteriously woken up\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swrite( STDOUT_FILENO, terminal.close().c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
int termemu( int host_fd, int src_fd, bool user, int debug_fd,
|
int termemu( int host_fd, int src_fd, bool user, int debug_fd,
|
||||||
|
|||||||
@@ -183,3 +183,15 @@ void Emulator::debug_printout( int fd )
|
|||||||
|
|
||||||
swrite( fd, screen.c_str() );
|
swrite( fd, screen.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Emulator::open( void )
|
||||||
|
{
|
||||||
|
char appmode[ 6 ] = { 0x1b, '[', '?', '1', 'h', 0 };
|
||||||
|
return std::string( appmode );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Emulator::close( void )
|
||||||
|
{
|
||||||
|
char ansimode[ 6 ] = { 0x1b, '[', '?', '1', 'l', 0 };
|
||||||
|
return std::string( ansimode );
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ namespace Terminal {
|
|||||||
std::string read_octets_to_host( void );
|
std::string read_octets_to_host( void );
|
||||||
|
|
||||||
void debug_printout( int fd );
|
void debug_printout( int fd );
|
||||||
|
|
||||||
|
std::string open( void ); /* put user cursor keys in application mode */
|
||||||
|
std::string close( void ); /* restore user cursor keys */
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ DrawState::DrawState( int s_width, int s_height )
|
|||||||
scrolling_region_top_row( 0 ), scrolling_region_bottom_row( height - 1 ),
|
scrolling_region_top_row( 0 ), scrolling_region_bottom_row( height - 1 ),
|
||||||
renditions(), save(),
|
renditions(), save(),
|
||||||
next_print_will_wrap( false ), origin_mode( false ), auto_wrap_mode( true ),
|
next_print_will_wrap( false ), origin_mode( false ), auto_wrap_mode( true ),
|
||||||
insert_mode( false ), cursor_visible( true )
|
insert_mode( false ), cursor_visible( true ), application_mode_cursor_keys( false )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < width; i++ ) {
|
for ( int i = 0; i < width; i++ ) {
|
||||||
tabs[ i ] = ( (i % 8) == 0 );
|
tabs[ i ] = ( (i % 8) == 0 );
|
||||||
@@ -346,6 +346,8 @@ void Framebuffer::soft_reset( void )
|
|||||||
{
|
{
|
||||||
ds.insert_mode = false;
|
ds.insert_mode = false;
|
||||||
ds.origin_mode = false;
|
ds.origin_mode = false;
|
||||||
|
ds.cursor_visible = true; /* per xterm and gnome-terminal */
|
||||||
|
ds.application_mode_cursor_keys = false;
|
||||||
ds.set_scrolling_region( 0, ds.get_height() - 1 );
|
ds.set_scrolling_region( 0, ds.get_height() - 1 );
|
||||||
ds.clear_renditions();
|
ds.clear_renditions();
|
||||||
ds.clear_saved_cursor();
|
ds.clear_saved_cursor();
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ namespace Terminal {
|
|||||||
bool insert_mode;
|
bool insert_mode;
|
||||||
bool cursor_visible;
|
bool cursor_visible;
|
||||||
|
|
||||||
|
bool application_mode_cursor_keys;
|
||||||
|
|
||||||
/* bold, etc. */
|
/* bold, etc. */
|
||||||
|
|
||||||
void move_row( int N, bool relative = false );
|
void move_row( int N, bool relative = false );
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ static Function func_CSI_TBC( CSI, "g", CSI_TBC );
|
|||||||
|
|
||||||
static bool *get_DEC_mode( int param, Framebuffer *fb ) {
|
static bool *get_DEC_mode( int param, Framebuffer *fb ) {
|
||||||
switch ( param ) {
|
switch ( param ) {
|
||||||
|
case 1: /* cursor key mode */
|
||||||
|
return &(fb->ds.application_mode_cursor_keys);
|
||||||
case 3: /* 80/132 */
|
case 3: /* 80/132 */
|
||||||
/* clear screen */
|
/* clear screen */
|
||||||
fb->ds.move_row( 0 );
|
fb->ds.move_row( 0 );
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
|
|
||||||
std::string UserInput::input( Parser::UserByte *act )
|
std::string UserInput::input( Parser::UserByte *act,
|
||||||
|
bool application_mode_cursor_keys )
|
||||||
{
|
{
|
||||||
char translated_str[ 2 ] = { act->c, 0 };
|
char translated_str[ 2 ] = { act->c, 0 };
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ std::string UserInput::input( Parser::UserByte *act )
|
|||||||
|
|
||||||
/* We don't need lookahead to do this for 7-bit. */
|
/* We don't need lookahead to do this for 7-bit. */
|
||||||
|
|
||||||
if ( (!application_mode_cursor)
|
if ( (!application_mode_cursor_keys)
|
||||||
&& (last_byte == 0x1b) /* ESC */
|
&& (last_byte == 0x1b) /* ESC */
|
||||||
&& (act->c == 'O') ) { /* ESC O = 7-bit SS3 = application mode */
|
&& (act->c == 'O') ) { /* ESC O = 7-bit SS3 = application mode */
|
||||||
translated_str[ 0 ] = '[';
|
translated_str[ 0 ] = '[';
|
||||||
@@ -21,6 +22,8 @@ std::string UserInput::input( Parser::UserByte *act )
|
|||||||
/* This doesn't handle the 8-bit SS3 C1 control, which would be
|
/* This doesn't handle the 8-bit SS3 C1 control, which would be
|
||||||
two octets in UTF-8. Fortunately nobody seems to send this. */
|
two octets in UTF-8. Fortunately nobody seems to send this. */
|
||||||
|
|
||||||
|
last_byte = act->c;
|
||||||
|
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
|
|
||||||
return std::string( translated_str );
|
return std::string( translated_str );
|
||||||
|
|||||||
@@ -7,17 +7,15 @@
|
|||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
class UserInput {
|
class UserInput {
|
||||||
private:
|
private:
|
||||||
bool last_byte;
|
short last_byte;
|
||||||
bool application_mode_cursor;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UserInput()
|
UserInput()
|
||||||
: last_byte( 0 ),
|
: last_byte( -1 )
|
||||||
application_mode_cursor( false )
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string input( Parser::UserByte *act );
|
std::string input( Parser::UserByte *act,
|
||||||
void set_cursor_application_mode( bool mode ) { application_mode_cursor = mode; }
|
bool application_mode_cursor_keys );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user