summaryrefslogtreecommitdiff
path: root/libterm/examples/invisible_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'libterm/examples/invisible_input.c')
-rw-r--r--libterm/examples/invisible_input.c67
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