diff options
author | axel <axel@liljencrantz.se> | 2006-05-14 20:16:23 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2006-05-14 20:16:23 +1000 |
commit | 9ebdc16be6bf347dbd0b892f73f4e8329e970916 (patch) | |
tree | c89e80559a598f5c2423e2210082e0a06bc3fa95 /reader.c | |
parent | 92ecc01baa1e762bc726dc51145434137efc65d4 (diff) |
Fix the longstanding hang-on-exit bug in eterm, as well as making sure the history is saved when the terminal emulator exits
darcs-hash:20060514101623-ac50b-f8ce693ec111e3c158640ef8de309bf7e5484c5b.gz
Diffstat (limited to 'reader.c')
-rw-r--r-- | reader.c | 70 |
1 files changed, 51 insertions, 19 deletions
@@ -232,6 +232,11 @@ typedef struct reader_data When this is true, the reader will exit */ int end_loop; + /** + If this is true, exit reader even if there are running + jobs. This happens if we press e.g. ^D twice. + */ + int prev_end_loop; /** Pointer to previous reader_data @@ -299,6 +304,11 @@ static void reader_save_status(); static void reader_check_status(); static void reader_super_highlight_me_plenty( wchar_t * buff, int *color, int pos, array_list_t *error ); +/** + Variable to keep track of forced exits - see \c reader_exit_forced(); +*/ +static int exit_forced; + /** Give up control of terminal @@ -370,6 +380,12 @@ static int room_for_usec(struct stat *st) return res; } +int reader_exit_forced() +{ + return exit_forced; +} + + /** string_buffer used as temporary storage for the reader_readline function */ @@ -869,11 +885,14 @@ void reader_destroy() } -void reader_exit( int do_exit ) +void reader_exit( int do_exit, int forced ) { if( data ) data->end_loop=do_exit; end_loop=do_exit; + if( forced ) + exit_forced = 1; + } void repaint() @@ -2230,7 +2249,6 @@ int exit_status() */ static int read_i() { - int prev_end_loop=0; reader_push(L"fish"); reader_set_complete_function( &complete ); @@ -2238,6 +2256,7 @@ static int read_i() reader_set_test_function( &shell_test ); data->prompt_width=60; + data->prev_end_loop=0; while( (!data->end_loop) && (!sanity_check()) ) { @@ -2254,12 +2273,7 @@ static int read_i() during evaluation. */ - tmp = wcsdup( reader_readline() ); - - data->buff_pos=data->buff_len=0; - data->buff[data->buff_len]=L'\0'; - reader_run_command( tmp ); - free( tmp ); + tmp = reader_readline(); if( data->end_loop) { @@ -2275,17 +2289,24 @@ static int read_i() } } - if( !prev_end_loop && has_job ) + if( !reader_exit_forced() && !data->prev_end_loop && has_job ) { writestr(_( L"There are stopped jobs\n" )); write_prompt(); data->end_loop = 0; - prev_end_loop=1; + data->prev_end_loop=1; } } else { - prev_end_loop=0; + tmp = wcsdup( tmp ); + + data->buff_pos=data->buff_len=0; + data->buff[data->buff_len]=L'\0'; + reader_run_command( tmp ); + free( tmp ); + + data->prev_end_loop=0; } } @@ -2442,6 +2463,14 @@ wchar_t *reader_readline() break; } + case R_EOF: + { + exit_forced = 1; + data->end_loop=1; + debug( 1, L"got R_EOF" ); + break; + } + /* complete */ case R_COMPLETE: { @@ -2833,14 +2862,17 @@ wchar_t *reader_readline() } al_destroy( &comp ); - if( tcsetattr(0,TCSANOW,&old_modes)) /* return to previous mode */ - { - wperror(L"tcsetattr"); - exit(1); - } - - set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); - + if( !reader_exit_forced() ) + { + if( tcsetattr(0,TCSANOW,&old_modes)) /* return to previous mode */ + { + wperror(L"tcsetattr"); + exit(1); + } + + set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); + } + return data->buff; } |