summaryrefslogtreecommitdiff
path: root/libterm/examples
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-01-07 21:00:59 +0900
committerFreeArtMan <dos21h@gmail.com>2015-01-07 21:00:59 +0900
commit03e459e7dff84c44644b1eccc0e00b73d846fe2a (patch)
tree00269e56bdf53906396199e22dcabe8bbee9592f /libterm/examples
parent0ab31d63699467d72f09327171b735ed2152bf2c (diff)
downloadmicrobbs-03e459e7dff84c44644b1eccc0e00b73d846fe2a.tar.gz
microbbs-03e459e7dff84c44644b1eccc0e00b73d846fe2a.zip
Small fixes about loging and libterm
Diffstat (limited to 'libterm/examples')
-rw-r--r--libterm/examples/Makefile8
-rw-r--r--libterm/examples/detect_resize.c63
-rw-r--r--libterm/examples/detect_screen_size.c39
-rw-r--r--libterm/examples/filtered_input.c63
-rw-r--r--libterm/examples/invisible_input.c67
-rw-r--r--libterm/examples/restore_screen.c24
6 files changed, 264 insertions, 0 deletions
diff --git a/libterm/examples/Makefile b/libterm/examples/Makefile
new file mode 100644
index 0000000..64009bd
--- /dev/null
+++ b/libterm/examples/Makefile
@@ -0,0 +1,8 @@
+CC=gcc
+
+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
diff --git a/libterm/examples/detect_resize.c b/libterm/examples/detect_resize.c
new file mode 100644
index 0000000..27c88c6
--- /dev/null
+++ b/libterm/examples/detect_resize.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <term.h>
+
+int main()
+{
+ int c;
+ int max_r, max_c;
+
+ struct term_screen ts; memset( &ts, 0, sizeof(ts) );
+
+ if ( term_init( &ts ) == -1 )
+ printf("Some err when init\n");
+
+ term_clr_scr( &ts );
+
+ {
+ char buf[32];
+ int c;
+ c = term_get_maxcol( &ts );
+ snprintf( buf, 32, "MaxCol:%d\n", c );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+
+ {
+ char buf[32];
+ int r;
+ r = term_get_maxrow( &ts );
+ snprintf( buf, 32, "MaxRow:%d\n", r );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+
+ while ( (c = getchar() ) != 'q' )
+ {
+ term_clr_scr( &ts );
+
+ {
+ char buf[32];
+ max_c = term_get_maxcol( &ts );
+ snprintf( buf, 32, "MaxCol:%d\n", max_c );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+
+ {
+ char buf[32];
+ max_r = term_get_maxrow( &ts );
+ snprintf( buf, 32, "MaxRow:%d\n", max_r );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+ {
+ term_cur_set_r( &ts, max_r );
+ term_cur_set_c( &ts, max_c );
+ printf("+");
+ }
+ }
+
+ term_clr_scr( &ts );
+
+ term_set_orig_mode( &ts );
+
+ return 0;
+} \ No newline at end of file
diff --git a/libterm/examples/detect_screen_size.c b/libterm/examples/detect_screen_size.c
new file mode 100644
index 0000000..f309253
--- /dev/null
+++ b/libterm/examples/detect_screen_size.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <term.h>
+
+int main()
+{
+ struct term_screen ts; memset( &ts, 0, sizeof(ts) );
+
+ if ( term_init( &ts ) == -1 )
+ printf("Some err when init\n");
+
+ term_clr_scr( &ts );
+
+ {
+ char buf[32];
+ int c;
+ c = term_get_maxcol( &ts );
+ snprintf( buf, 32, "MaxCol:%d\n", c );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+
+ {
+ char buf[32];
+ int r;
+ r = term_get_maxrow( &ts );
+ snprintf( buf, 32, "MaxRow:%d\n", r );
+ write( ts.ofd, buf, strlen(buf) );
+ }
+
+
+ sleep(3);
+
+ term_clr_scr( &ts );
+
+ term_set_orig_mode( &ts );
+
+ return 0;
+} \ No newline at end of file
diff --git a/libterm/examples/filtered_input.c b/libterm/examples/filtered_input.c
new file mode 100644
index 0000000..170e474
--- /dev/null
+++ b/libterm/examples/filtered_input.c
@@ -0,0 +1,63 @@
+#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;
+ 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?: %s", in_buf);
+
+ }
+
+ term_clr_scr( &ts );
+
+ term_set_orig_mode( &ts );
+
+ return 0;
+} \ No newline at end of file
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
diff --git a/libterm/examples/restore_screen.c b/libterm/examples/restore_screen.c
new file mode 100644
index 0000000..5323d78
--- /dev/null
+++ b/libterm/examples/restore_screen.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <term.h>
+#include <debug.h>
+
+int main()
+{
+ struct term_screen ts; memset( &ts, 0, sizeof(ts) );
+
+
+ PRINT("asd\n");
+ if ( term_init( &ts ) == -1 )
+ printf("Some err when init\n");
+ PRINT("asd\n");
+
+ printf("set mode\n");
+
+ sleep(1);
+
+ term_set_orig_mode( &ts );
+
+ return 0;
+} \ No newline at end of file