Detect and handle terminals size changes

darcs-hash:20061004214502-ac50b-aaf5b76a6281c0ba8757e794b0a802793ce92916.gz
This commit is contained in:
axel 2006-10-05 07:45:02 +10:00
parent 0ea668b260
commit d1078f8582
5 changed files with 24 additions and 13 deletions

View file

@ -123,7 +123,7 @@ static const wchar_t *name_arr[] =
L"kill-word",
L"backward-kill-word",
L"dump-functions",
L"clear-screen",
L"winch",
L"exit",
L"history-token-search-backward",
L"history-token-search-forward",
@ -200,7 +200,7 @@ static const wchar_t code_arr[] =
R_KILL_WORD,
R_BACKWARD_KILL_WORD,
R_DUMP_FUNCTIONS,
R_CLEAR_SCREEN,
R_WINCH,
R_EXIT,
R_HISTORY_TOKEN_SEARCH_BACKWARD,
R_HISTORY_TOKEN_SEARCH_FORWARD,
@ -1398,7 +1398,7 @@ static int interrupt_handler()
return 3;
}
return 0;
return R_WINCH;
}
int input_init()

View file

@ -39,7 +39,7 @@ enum
R_KILL_WORD,
R_BACKWARD_KILL_WORD,
R_DUMP_FUNCTIONS,
R_CLEAR_SCREEN,
R_WINCH,
R_EXIT,
R_HISTORY_TOKEN_SEARCH_BACKWARD,
R_HISTORY_TOKEN_SEARCH_FORWARD,

View file

@ -2171,6 +2171,12 @@ wchar_t *reader_readline()
break;
}
case R_WINCH:
{
repaint();
break;
}
case R_EOF:
{
exit_forced = 1;
@ -2521,15 +2527,6 @@ wchar_t *reader_readline()
break;
}
case R_CLEAR_SCREEN:
{
if( clear_screen )
writembs( clear_screen );
s_reset( &data->screen );
repaint();
break;
}
case R_BEGINNING_OF_HISTORY:
{
history_first();

View file

@ -490,10 +490,18 @@ static void s_update( screen_t *scr, wchar_t *prompt )
int i, j, k;
int prompt_width = calc_prompt_width( prompt );
int current_width=0;
int screen_width = common_get_width();
buffer_t output;
b_init( &output );
if( scr->actual_width != screen_width )
{
s_move( scr, &output, 0, 0 );
scr->actual_width = screen_width;
s_reset( scr );
}
if( wcscmp( prompt, (wchar_t *)scr->actual_prompt.buff ) )
{
s_move( scr, &output, 0, 0 );

View file

@ -34,6 +34,12 @@ typedef struct
the screen.
*/
string_buffer_t actual_prompt;
/*
The actual width of the screen at the time of the last screen
write.
*/
int actual_width;
}
screen_t;