Implement tabs

This commit is contained in:
Keith Winstein
2011-01-31 06:10:02 -05:00
parent e4dce8f6e2
commit 92d80accf9
5 changed files with 63 additions and 3 deletions
+1
View File
@@ -16,3 +16,4 @@ template class std::vector<Terminal::Cell *>;
template class std::vector<wchar_t>;
template class std::vector<int>;
template class std::map<std::string, Terminal::Function>;
template class std::vector<bool>;
+1 -1
View File
@@ -63,7 +63,7 @@ void Emulator::print( Parser::Print *act )
switch ( chwidth ) {
case 1: /* normal character */
case 2: /* wide character */
if ( fb.ds.next_print_will_wrap ) {
if ( fb.ds.auto_wrap_mode && fb.ds.next_print_will_wrap ) {
fb.ds.move_col( 0 );
fb.move_rows_autoscroll( 1 );
}
+22 -2
View File
@@ -56,8 +56,8 @@ void Cell::reset( void )
DrawState::DrawState( int s_width, int s_height )
: width( s_width ), height( s_height ),
cursor_col( 0 ), cursor_row( 0 ),
combining_char_col( 0 ), combining_char_row( 0 ),
next_print_will_wrap( false )
combining_char_col( 0 ), combining_char_row( 0 ), tabs( s_width ),
next_print_will_wrap( false ), auto_wrap_mode( true )
{}
Framebuffer::Framebuffer( int s_width, int s_height )
@@ -179,3 +179,23 @@ void Framebuffer::claim_overlap( int row, int col )
}
}
}
void DrawState::set_tab( void )
{
tabs[ cursor_col ] = true;
}
void DrawState::clear_tab( int col )
{
tabs[ col ] = false;
}
int DrawState::get_next_tab( void )
{
for ( int i = cursor_col + 1; i < width; i++ ) {
if ( tabs[ i ] ) {
return i;
}
}
return -1;
}
+7
View File
@@ -40,8 +40,11 @@ namespace Terminal {
int cursor_col, cursor_row;
int combining_char_col, combining_char_row;
std::vector<bool> tabs;
public:
bool next_print_will_wrap;
bool auto_wrap_mode;
/* bold, etc. */
@@ -55,6 +58,10 @@ namespace Terminal {
int get_width( void ) { return width; }
int get_height( void ) { return height; }
void set_tab( void );
void clear_tab( int col );
int get_next_tab( void );
DrawState( int s_width, int s_height );
};
+32
View File
@@ -141,3 +141,35 @@ void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
}
static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL );
void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
int col = fb->ds.get_next_tab();
if ( col == -1 ) { /* no tabs, go to end of line */
fb->ds.move_col( fb->ds.get_width() - 1 );
} else {
fb->ds.move_col( col );
}
}
static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT );
void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
fb->ds.set_tab();
}
static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HT );
void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch )
{
if ( dispatch->getparam( 0, 0 ) == 3 ) { /* clear all tab stops */
for ( int x = 0; x < fb->ds.get_width(); x++ ) {
fb->ds.clear_tab( x );
}
} else {
fb->ds.clear_tab( fb->ds.get_cursor_col() );
}
}
static Function func_CSI_TBC( CSI, "g", CSI_TBC );