1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#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_set_raw_mode( &ts );
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;
}
|