diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-01-07 21:00:59 +0900 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-01-07 21:00:59 +0900 |
commit | 03e459e7dff84c44644b1eccc0e00b73d846fe2a (patch) | |
tree | 00269e56bdf53906396199e22dcabe8bbee9592f /libterm/examples/invisible_input.c | |
parent | 0ab31d63699467d72f09327171b735ed2152bf2c (diff) | |
download | microbbs-03e459e7dff84c44644b1eccc0e00b73d846fe2a.tar.gz microbbs-03e459e7dff84c44644b1eccc0e00b73d846fe2a.zip |
Small fixes about loging and libterm
Diffstat (limited to 'libterm/examples/invisible_input.c')
-rw-r--r-- | libterm/examples/invisible_input.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/libterm/examples/invisible_input.c b/libterm/examples/invisible_input.c new file mode 100644 index 0000000..5fadfb3 --- /dev/null +++ b/libterm/examples/invisible_input.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <term.h> + +int main() +{ + int c; + int new_c=0, new_r=0, old_r=0, old_c=0; + const int in_size = 32; + int counter=0; + int i=0; + char in_buf[in_size]; + + struct term_screen ts; memset( &ts, 0, sizeof(ts) ); + + if ( term_init( &ts ) == -1 ) + printf("Some err when init\n"); + + term_clr_scr( &ts ); + + new_c = term_get_maxcol( &ts ); + new_r = term_get_maxrow( &ts ); + old_r = new_r; + old_c = new_c; + + memset( in_buf, 0, in_size ); + + term_cur_set_c( &ts, 0); + term_cur_set_r( &ts, old_r); + printf("Your name is?: %s", in_buf); + while ( (c = getchar() ) != 13 ) + { + 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 + printf("%d",c); + term_clr_scr( &ts ); + new_r = term_get_maxrow( &ts ); + if ( old_r != new_r ) old_r = new_r; + term_cur_set_c( &ts, 0); + term_cur_set_r( &ts, old_r); + printf("Your name is?: "); + for ( i=0; i<counter;i++) printf("*"); + + } + + term_clr_scr( &ts ); + + term_set_orig_mode( &ts ); + + printf("Hidden input was: %s\n", in_buf ); + + return 0; +}
\ No newline at end of file |