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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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;
}
|