diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-06-22 12:35:37 +0300 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-06-22 12:35:37 +0300 |
commit | 43d3e330b0064c8ab962a7e77b4f26ac2c63f8ec (patch) | |
tree | f12c6b3a2e87d4fd58689d94b612b4a7833ea335 /libterm | |
parent | 712439932ce9ac04fa6354cd4603046232121974 (diff) | |
download | microbbs-43d3e330b0064c8ab962a7e77b4f26ac2c63f8ec.tar.gz microbbs-43d3e330b0064c8ab962a7e77b4f26ac2c63f8ec.zip |
Replaced print to term_printf. Fixed warning
Diffstat (limited to 'libterm')
-rw-r--r-- | libterm/term.c | 2 | ||||
-rw-r--r-- | libterm/term_io.c | 59 | ||||
-rw-r--r-- | libterm/term_io.h | 13 |
3 files changed, 63 insertions, 11 deletions
diff --git a/libterm/term.c b/libterm/term.c index 532dc92..2a726b4 100644 --- a/libterm/term.c +++ b/libterm/term.c @@ -27,6 +27,8 @@ int term_init( term_screen *term ) //if you whant raw mode then you should set it man if ( tcgetattr( term->ifd, &term->orig_i ) == -1 ) goto exit_error; term->raw_i = term->orig_i; + if ( tcgetattr( term->ofd, &term->orig_o ) == -1 ) goto exit_error; + term->raw_o = term->orig_o; term->mode = SCREEN_MODE_80x25; diff --git a/libterm/term_io.c b/libterm/term_io.c index cd1b3c1..d305f51 100644 --- a/libterm/term_io.c +++ b/libterm/term_io.c @@ -140,23 +140,51 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) menu_cmd = 0; buf_curent = 0; + //finsih when escape button is setted while ( menu_cmd != TK_ESC ) { menu_input = term_getc( ts ); if ( menu_input != -1 ) { menu_cmd = (char)menu_input; - //add to buffer any pritable char - //if ( (isgraph( menu_cmd ) && flag == READLINE_TEXT ) || - // (isalpha( menu_cmd ) && flag == READLINE_ALPHA ) ) - if ( isalpha( menu_cmd ) ) + //add to buffer any printable alpahnumeric char + if ( isalpha( menu_cmd ) && + (flag == READLINE_TEXT || flag == READLINE_ALPHA + || flag == READLINE_HIDDEN) ) { if ( buf_curent < buf_size ) { buf[ buf_curent ] = menu_cmd; buf_curent += 1; } - //deleteone char from buffer + //add to buffer number 0-9 + } else if ( isdigit( menu_cmd ) && + ( flag == READLINE_TEXT || flag == READLINE_NUMBER + || flag == READLINE_HIDDEN )) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //if space allowed + } else if ( (menu_cmd == ' ') && (flag == READLINE_TEXT) ) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //remaining printable chars for READLINE_TEXT + } else if ( ispunct( menu_cmd ) && + (flag == READLINE_TEXT )) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //deleteone char from buffer with backspace } else if ( menu_cmd == TK_BACKSPACE ) { if ( buf_curent > 0) @@ -164,13 +192,14 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) buf[ buf_curent ] = 0x0; buf_curent -= 1; } - //input ready + //input ready lets finish input } else if ( menu_cmd == TK_ENTER ) { ret = buf_curent; memcpy( str, buf, buf_size ); str[ str_size-1 ] = 0x0; break; + //finsih input without saving result } else if ( menu_cmd == TK_ESC ) { ret = -1; @@ -184,7 +213,8 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) { if ( i < buf_curent ) { - if ( (flag == READLINE_TEXT) || (flag == READLINE_ALPHA) ) + if ( (flag == READLINE_TEXT) || (flag == READLINE_ALPHA) + || (flag == READLINE_NUMBER) ) { term_putc( ts, buf[i] ); } else if ( flag == READLINE_HIDDEN ) @@ -210,3 +240,18 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) return ret; } + +//this is to replace printf,flush code +int term_printf( term_screen *ts, const char *format, ...) +{ + int ret=0; + + va_list args; + va_start(args, format); + + vdprintf(ts->ofd, format, args); + + va_end(args); + + return ret; +} diff --git a/libterm/term_io.h b/libterm/term_io.h index 3c84972..b05af39 100644 --- a/libterm/term_io.h +++ b/libterm/term_io.h @@ -3,14 +3,18 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include "screen_modes.h" #include "term.h" -#define READLINE_NONE 0 -#define READLINE_ALPHA 1 -#define READLINE_TEXT 2 -#define READLINE_HIDDEN 3 +#define READLINE_NONE 0 //none +#define READLINE_ALPHA 1 //isalpsha +#define READLINE_TEXT 2 //[a-zA-Z0-9] + ispunct +#define READLINE_HIDDEN 3 //[a-zA-Z] +#define READLINE_NUMBER 4 //[0-9] +#define READLINE_SYMBOL 5 //not yet +#define READLINE_ALPHANUM 6 //not yet int term_fprint( screen_mode_e mode, FILE *f ); @@ -21,5 +25,6 @@ int term_draw_hline( term_screen *ts, int pc, int pr, int sz, char ch ); int term_getc( term_screen *ts ); int term_putc( term_screen *ts, char c ); int term_readline( term_screen *ts, char *str, size_t str_size, int flag ); +int term_printf( term_screen *ts, const char *format, ...); #endif |