summaryrefslogtreecommitdiff
path: root/libterm/term_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'libterm/term_io.c')
-rw-r--r--libterm/term_io.c59
1 files changed, 52 insertions, 7 deletions
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;
+}