diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-01-08 00:28:11 +0900 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-01-08 00:28:11 +0900 |
commit | 3d489fe502178d2d4e58eb8d5736be2fbda38077 (patch) | |
tree | 153d134b43fb8929e0725bb923742466b6e2f1cd /libterm | |
parent | 03e459e7dff84c44644b1eccc0e00b73d846fe2a (diff) | |
download | microbbs-3d489fe502178d2d4e58eb8d5736be2fbda38077.tar.gz microbbs-3d489fe502178d2d4e58eb8d5736be2fbda38077.zip |
Bumped libterm version
Diffstat (limited to 'libterm')
-rw-r--r-- | libterm/Makefile | 11 | ||||
-rw-r--r-- | libterm/debug.h | 4 | ||||
-rw-r--r-- | libterm/examples/Makefile | 17 | ||||
-rw-r--r-- | libterm/examples/detect_resize.c | 2 | ||||
-rw-r--r-- | libterm/examples/detect_screen_size.c | 2 | ||||
-rw-r--r-- | libterm/examples/filtered_input.c | 2 | ||||
-rw-r--r-- | libterm/examples/invisible_input.c | 2 | ||||
-rw-r--r-- | libterm/examples/print_8025.c | 127 | ||||
-rw-r--r-- | libterm/screen_modes.c | 3 | ||||
-rw-r--r-- | libterm/screen_modes.h | 2 | ||||
-rw-r--r-- | libterm/term.c | 55 | ||||
-rw-r--r-- | libterm/term.h | 3 | ||||
-rw-r--r-- | libterm/term_io.c | 67 | ||||
-rw-r--r-- | libterm/term_io.h | 14 |
14 files changed, 287 insertions, 24 deletions
diff --git a/libterm/Makefile b/libterm/Makefile index 5cc090c..98962f5 100644 --- a/libterm/Makefile +++ b/libterm/Makefile @@ -1,9 +1,12 @@ +PROJECT=libterm +CC=gcc +LD=ld make: - gcc -c term.c - gcc -c screen_modes.c - gcc -c print_utils.c - ld -r term.o screen_modes.o print_utils.o -o libterm.o + $(CC) -c term.c + $(CC) -c screen_modes.c + $(CC) -c term_io.c + $(LD) -r term.o screen_modes.o term_io.o -o $(PROJECT).o clean: rm *.o diff --git a/libterm/debug.h b/libterm/debug.h index a8bf211..a79ea77 100644 --- a/libterm/debug.h +++ b/libterm/debug.h @@ -1,5 +1,5 @@ -#ifndef __RB_DEBUG_UTILS_H -#define __RB_DEBUG_UTILS_H +#ifndef __LIBTERM_DEBUG_UTILS_H +#define __LIBTERM_DEBUG_UTILS_H //what about kprintf? 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 diff --git a/libterm/screen_modes.c b/libterm/screen_modes.c deleted file mode 100644 index 709b332..0000000 --- a/libterm/screen_modes.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "screen_modes.h" - - diff --git a/libterm/screen_modes.h b/libterm/screen_modes.h index 73a66a6..261cbf5 100644 --- a/libterm/screen_modes.h +++ b/libterm/screen_modes.h @@ -4,7 +4,7 @@ typedef enum { SCREEN_MODE_NONE=0, - SCREEN_MODE_80x24 + SCREEN_MODE_80x25 } screen_mode_e; typedef struct term_screen_mode diff --git a/libterm/term.c b/libterm/term.c index 1aa7afa..f1dbf40 100644 --- a/libterm/term.c +++ b/libterm/term.c @@ -50,9 +50,7 @@ int term_init( term_screen *term ) if ( tcgetattr( term->ifd, &term->orig_i ) == -1 ) goto exit_error; term->raw_i = term->orig_i; - //if (term_set_raw_mode( term ) == -1 ) goto exit_error; - - term->mode = SCREEN_MODE_80x24; + term->mode = SCREEN_MODE_80x25; return ret; @@ -116,7 +114,6 @@ int term_get_maxrow( term_screen *ts ) goto exit_error; ret = cur_r; - //PNL(); /* restore position */ { char buf[32]; @@ -124,12 +121,9 @@ int term_get_maxrow( term_screen *ts ) write( ts->ofd, buf, strlen(buf) ); } - //PNL(); - return ret; exit_error: - //PNL(); return -1; } @@ -306,6 +300,53 @@ exit_error: } +//if there is no mode with some rows/columns , then just show that no mode setet +// up and user should decide by his own what to do +int term_mode_rows( term_screen *ts ) +{ + int ret = -1; + + if ( ts == NULL) return -1; + + switch ( ts->mode ) + { + //--------------------- + case SCREEN_MODE_80x25: + ret = 25; + break; + //-------------------- + case SCREEN_MODE_NONE: + default: + ret = -1; + } + + return ret; +} + + +//if there is no mode with some rows/columns , then just show that no mode setet +// up and user should decide by his own what to do +int term_mode_columns( term_screen *ts ) +{ + int ret = -1; + + if ( ts == NULL) return -1; + + switch ( ts->mode ) + { + //--------------------- + case SCREEN_MODE_80x25: + ret = 80; + break; + //-------------------- + case SCREEN_MODE_NONE: + default: + ret = -1; + } + + return ret; +} + void term_set_orig_mode( term_screen *ts ) { diff --git a/libterm/term.h b/libterm/term.h index b290a43..de4fede 100644 --- a/libterm/term.h +++ b/libterm/term.h @@ -22,7 +22,6 @@ typedef struct term_screen struct termios orig_i, orig_o; struct termios raw_i, raw_o; screen_mode_e mode; - int term_col, term_row; } term_screen; int term_init( term_screen* ); @@ -36,6 +35,8 @@ int term_cur_set_r( term_screen*, unsigned int ); int term_set_speed( term_screen* ); int term_clr_scr( term_screen* ); int term_set_raw_mode( term_screen* ); +int term_mode_rows( term_screen* ); +int term_mode_columns( term_screen* ); void term_set_orig_mode( term_screen* ); #endif diff --git a/libterm/term_io.c b/libterm/term_io.c new file mode 100644 index 0000000..1a934f9 --- /dev/null +++ b/libterm/term_io.c @@ -0,0 +1,67 @@ +#include "term_io.h" + +int term_fprint( screen_mode_e mode, FILE *f ) +{ + int ret=-1; + if (f == NULL) + return -1; + + switch ( mode ) + { + case SCREEN_MODE_80x25: + { + } + break; + default: + printf("Unknown screen mode\n"); + } + + return ret; +} + + +//print data to terminal starting from x,y +int term_print( term_screen *ts, const char *buf, size_t size, + int init_column, int init_row ) +{ + int pos_column=0, pos_row=0; + int ret=-1; + if ( buf == NULL ) + { + return -1; + } + + if ( size <= 0 ) + { + return -1; + } + + switch ( ts->mode ) + { + case SCREEN_MODE_80x25: + { + + } + break; + default: + printf("Unknown mode\n"); + } + + return ret; +} + +//read one character from stream +int term_getc( term_screen *ts ) +{ + int ret=-1; + int fret=-1; + char buf; + + fret = read( ts->ifd, &buf, 1 ); + if ( fret == 1 ) + ret = buf; + + return ret; +} + + diff --git a/libterm/term_io.h b/libterm/term_io.h new file mode 100644 index 0000000..3d9243f --- /dev/null +++ b/libterm/term_io.h @@ -0,0 +1,14 @@ +#ifndef __LIBTERM_PRINT_UTILS_H +#define __LIBTERM_PRINT_UTILS_H + +#include <stdio.h> +#include <stdlib.h> + +#include "screen_modes.h" +#include "term.h" + +int term_fprint( screen_mode_e, FILE* ); +int term_print( term_screen*, const char*, size_t, int, int ); +int term_getc( term_screen* ); + +#endif |