diff options
Diffstat (limited to 'libterm/examples/print_8025.c')
-rw-r--r-- | libterm/examples/print_8025.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libterm/examples/print_8025.c b/libterm/examples/print_8025.c new file mode 100644 index 0000000..95b16c5 --- /dev/null +++ b/libterm/examples/print_8025.c @@ -0,0 +1,127 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <term.h> + +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<in_size-1;i++) printf("+"); printf("\n"); + term_cur_set_c( &ts, start_columns); + term_cur_set_r( &ts, start_rows+1); + for (i = 0; i<in_size-1;i++) printf("+"); printf("\n"); + + //draw buffer + term_cur_set_c( &ts, start_columns ); + term_cur_set_r( &ts, start_rows ); + printf("%s\n", in_buf); + + term_cur_set_c( &ts, 0); + term_cur_set_r( &ts, prev_columns ); + printf("%s\n", cpy_buf); + } + + + + //HA! UNITILISE STUFF +exit_unitialise: + term_clr_scr( &ts ); + + term_set_orig_mode( &ts ); + + return 0; +}
\ No newline at end of file |