#include #include #include int main() { int run_loop = 1; int c; int prev_rows, prev_columns; int start_rows=0, start_columns=0; const int in_size = 32; int counter=0; char in_buf[in_size], cpy_buf[in_size]; int i; struct term_screen ts; memset( &ts, 0, sizeof(ts) ); if ( term_init( &ts ) == -1 ) printf("Some err when init\n"); term_set_raw_mode( &ts ); term_clr_scr( &ts ); //DETECT HOW MANY COLUMNS TERMINAL HAVE IF NOT ENOUGHT EXIT { int c = term_get_maxcol( &ts ); if ( c <= term_mode_columns( &ts )) { printf("Wider screen needed\n"); goto exit_unitialise; } } //DETECT HOW MANY ROWS NOW TERMINAL HAVE IF NOT ENOUGHT EXIT { int r = term_get_maxrow( &ts ); if ( r <= term_mode_rows( &ts )) { printf("No enought row supported\n"); goto exit_unitialise; } } //run while ESC is not pressed //if enter pressed clear buffer and print value //if resize then redraw rectangle and input buffer values memset( in_buf, 0, in_size ); memset( cpy_buf, 0, in_size ); run_loop = 1; while ( run_loop ) { int cur_rows = term_get_maxrow( &ts ); int cur_columns = term_get_maxcol( &ts ); c = term_getc( &ts ); if ( c == 27 ) break; if ( cur_rows != prev_rows ) { prev_rows = cur_rows; start_rows = cur_rows/2; } if ( cur_columns != prev_columns) { prev_columns = cur_columns; start_columns = cur_columns/2; } if ( isalpha(c) ) { if ( counter < in_size-1 ) { in_buf[counter] = c; counter++; } } else if ( c == 127 ) { if ( counter > 0) { in_buf[counter-1] = 0x0; counter--; } } else if ( c == 13 ) { memcpy( cpy_buf, in_buf, in_size); } term_clr_scr( &ts ); if ( (cur_rows < 25) || (cur_columns < 80 ) ) { printf("!Please use larger screen size!\n"); continue; } //draw rectangle around buffer term_cur_set_c( &ts, start_columns); term_cur_set_r( &ts, start_rows-1); for (i = 0; i