summaryrefslogtreecommitdiff
path: root/libterm/term_io.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-01-11 17:49:03 +0900
committerFreeArtMan <dos21h@gmail.com>2015-01-11 17:49:03 +0900
commit9b3d5f87e7718b00f786531b58bf102cdadc8264 (patch)
tree51c445bbfd347353bcbc1412aaec654819739555 /libterm/term_io.c
parent4e148546810a2902dff9444526e47c9569c79b64 (diff)
downloadmicrobbs-9b3d5f87e7718b00f786531b58bf102cdadc8264.tar.gz
microbbs-9b3d5f87e7718b00f786531b58bf102cdadc8264.zip
Added primitive authentification support
Diffstat (limited to 'libterm/term_io.c')
-rw-r--r--libterm/term_io.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/libterm/term_io.c b/libterm/term_io.c
index 5ef682b..cd1b3c1 100644
--- a/libterm/term_io.c
+++ b/libterm/term_io.c
@@ -102,4 +102,111 @@ int term_getc( term_screen *ts )
return ret;
}
+int term_putc( term_screen *ts, char c )
+{
+ int ret = 0;
+ int fret = -1;
+ fret = write( ts->ofd, &c, 1 );
+ if ( fret != 1 )
+ {
+ ret = -1;
+ }
+
+ return ret;
+}
+
+//return amoutn fo characters readed
+//on error or if nothing is imputed 0 returned
+int term_readline( term_screen *ts, char *str, size_t str_size, int flag )
+{
+ int ret = 0;
+ int max_row, max_column;
+ char *buf = NULL;
+ int buf_size = str_size-1;
+ int buf_curent = 0;
+ int menu_input=0;
+ char menu_cmd = 0;
+ int orig_row;
+ int orig_col;
+
+ buf = malloc( buf_size );
+ memset( buf, 0, buf_size );
+
+ max_row = term_get_maxrow( ts );
+ max_column = term_get_maxcol( ts );
+ orig_row = term_cur_get_r( ts );
+ orig_col = term_cur_get_c( ts );
+
+ menu_cmd = 0;
+ buf_curent = 0;
+ 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 ) )
+ {
+ if ( buf_curent < buf_size )
+ {
+ buf[ buf_curent ] = menu_cmd;
+ buf_curent += 1;
+ }
+ //deleteone char from buffer
+ } else if ( menu_cmd == TK_BACKSPACE )
+ {
+ if ( buf_curent > 0)
+ {
+ buf[ buf_curent ] = 0x0;
+ buf_curent -= 1;
+ }
+ //input ready
+ } else if ( menu_cmd == TK_ENTER )
+ {
+ ret = buf_curent;
+ memcpy( str, buf, buf_size );
+ str[ str_size-1 ] = 0x0;
+ break;
+ } else if ( menu_cmd == TK_ESC )
+ {
+ ret = -1;
+ }
+
+ {
+ int i;
+ term_cur_set_r( ts, orig_row );
+ term_cur_set_c( ts, orig_col );
+ for (i=0;i<buf_size;i++)
+ {
+ if ( i < buf_curent )
+ {
+ if ( (flag == READLINE_TEXT) || (flag == READLINE_ALPHA) )
+ {
+ term_putc( ts, buf[i] );
+ } else if ( flag == READLINE_HIDDEN )
+ {
+ term_putc( ts, '*');
+ }
+ } else
+ {
+ term_putc( ts, ' ' );
+ }
+ }
+ term_cur_set_c( ts, orig_col+buf_curent );
+ term_cur_set_r( ts, orig_row );
+ }
+ }
+ }
+
+ if ( buf != NULL)
+ {
+ free( buf );
+ buf = NULL;
+ }
+
+ return ret;
+}