summaryrefslogtreecommitdiff
path: root/libterm/examples
diff options
context:
space:
mode:
Diffstat (limited to 'libterm/examples')
-rw-r--r--libterm/examples/Makefile17
-rw-r--r--libterm/examples/detect_resize.c2
-rw-r--r--libterm/examples/detect_screen_size.c2
-rw-r--r--libterm/examples/filtered_input.c2
-rw-r--r--libterm/examples/invisible_input.c2
-rw-r--r--libterm/examples/print_8025.c127
6 files changed, 146 insertions, 6 deletions
diff --git a/libterm/examples/Makefile b/libterm/examples/Makefile
index 64009bd..00583f8 100644
--- a/libterm/examples/Makefile
+++ b/libterm/examples/Makefile
@@ -1,8 +1,13 @@
CC=gcc
+CFLAGS=-I../ ../libterm.o
+SOURCES=detect_resize.c detect_screen_size.c filtered_input.c invisible_input.c restore_screen.c print_8025.c
+EXE=$(SOURCES:.c=)
+BUILD_DIR=.
-make:
- $(CC) detect_screen_size.c -o detect_screen_size ../libterm.o -I../
- $(CC) detect_resize.c -o detect_resize ../libterm.o -I../
- $(CC) filtered_input.c -o filtered_input ../libterm.o -I../
- $(CC) invisible_input.c -o invisisble_input ../libterm.o -I../
- $(CC) restore_screen.c -o restore_screen ../libterm.o -I../ \ No newline at end of file
+all: $(EXE)
+
+%: %.c
+ $(CC) $(CFLAGS) $< -o $(BUILD_DIR)/$@
+
+clean:
+ rm -f $(EXE)
diff --git a/libterm/examples/detect_resize.c b/libterm/examples/detect_resize.c
index 27c88c6..2c58bc8 100644
--- a/libterm/examples/detect_resize.c
+++ b/libterm/examples/detect_resize.c
@@ -13,6 +13,8 @@ int main()
if ( term_init( &ts ) == -1 )
printf("Some err when init\n");
+ term_set_raw_mode( &ts );
+
term_clr_scr( &ts );
{
diff --git a/libterm/examples/detect_screen_size.c b/libterm/examples/detect_screen_size.c
index f309253..50ad15f 100644
--- a/libterm/examples/detect_screen_size.c
+++ b/libterm/examples/detect_screen_size.c
@@ -10,6 +10,8 @@ int main()
if ( term_init( &ts ) == -1 )
printf("Some err when init\n");
+ term_set_raw_mode( &ts );
+
term_clr_scr( &ts );
{
diff --git a/libterm/examples/filtered_input.c b/libterm/examples/filtered_input.c
index 170e474..ebd9629 100644
--- a/libterm/examples/filtered_input.c
+++ b/libterm/examples/filtered_input.c
@@ -16,6 +16,8 @@ int main()
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 );
diff --git a/libterm/examples/invisible_input.c b/libterm/examples/invisible_input.c
index 5fadfb3..d0ce89e 100644
--- a/libterm/examples/invisible_input.c
+++ b/libterm/examples/invisible_input.c
@@ -17,6 +17,8 @@ int main()
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 );
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