diff options
| author | KatolaZ <katolaz@freaknet.org> | 2019-07-19 19:39:04 +0100 | 
|---|---|---|
| committer | KatolaZ <katolaz@freaknet.org> | 2019-07-19 19:39:04 +0100 | 
| commit | a4c6053e9df10cc4060696d6c29e84fa3105ad0e (patch) | |
| tree | 9eb9b853ba081c97aab04db813c279bf1472d572 | |
| parent | 575703d810415c9f427104ab0225a1e5916983ec (diff) | |
check if modified before exit, and save
| -rw-r--r-- | TODO | 1 | ||||
| -rw-r--r-- | gramscii.c | 30 | 
2 files changed, 26 insertions, 5 deletions
| @@ -13,6 +13,7 @@    (also do not print unmanaged chars!)  - get screen geometry  - allow scrolling (both vertical and horizontal) +* check if modified on exit  * write to new file / default file  * delete -- 'x'   * save to file @@ -146,9 +146,11 @@ char* state_str(){  void status_bar(){  	printf("\033[%d;1f\033[7m", HEIGHT+1); +	printf("%100s", " "); +	printf("\033[%d;1f\033[7m", HEIGHT+1);  	printf(" x: %3d y: %3d -- mode: %4s hl: %c vl: %c cn: %c <: %c >: %c %10s",   		x, y, state_str(), line_h, line_v, corner, mark_st, mark_end, ""); - +	printf(" [%s]", fname );  	printf("\033[0m");  } @@ -302,8 +304,10 @@ void get_box(){  		status_bar();  		show_cursor();  	} -	if (c == 'b') +	if (c == 'b'){  		draw_box(orig_x, orig_y, FIX); +		modified = 1; +	}  	redraw();  	state = MOVE;  } @@ -392,8 +396,10 @@ void get_arrow(){  		status_bar();  		show_cursor();  	} -	if (c == 'a') +	if (c == 'a'){  		draw_arrow(orig_x, orig_y, arrow, arrow_len, FIX); +		modified = 1; +	}  	redraw();  	state = MOVE;  } @@ -435,7 +441,7 @@ void write_file(){  	if (!fname[0] || force_new){  		get_string(fname, 255);  		if (f=fopen(fname, "r")){ -			if (!is_yes(get_key("File exists. Overwrite [y/N]?")) ){ +			if (!is_yes(get_key("File exists. Overwrite [y/n]?")) ){  				fclose(f);  				return;  			} @@ -450,6 +456,7 @@ void write_file(){  		fprintf(f, "%s\n", screen[i]);  	}  	fclose(f); +	modified = 0;  	get_key("File saved.");  } @@ -533,6 +540,7 @@ void delete(){  		check_bound();  		step = 1;  		do_delete(orig_x, orig_y); +		modified = 1;  		orig_x = x;  		orig_y = y;  		redraw(); @@ -542,6 +550,17 @@ void delete(){  	state = MOVE;  } +void check_modified(){ + +	if (modified){ +		if (!is_yes(get_key("Unsaved changes. Write to file [y/n]?")) ){ +			return; +		} +		write_file(0); +	} +} + +  void commands(){ @@ -617,8 +636,9 @@ void commands(){  			case '>':  				toggle_end_mark();  				break; -			case 'Q':  			case 'q': +				check_modified(); +			case 'Q':  				cleanup(0);  				exit(0);  				break; | 
