diff options
Diffstat (limited to 'todo.c')
-rw-r--r-- | todo.c | 80 |
1 files changed, 53 insertions, 27 deletions
@@ -4,12 +4,15 @@ int bbs_todo( term_screen *ts, const char *fname) { - int ret=-1; + int ret=0; int ret_len; size_t in_size=0; char *in_buf=NULL; int quit_loop=0; + int menu_input = 0; + char menu_cmd = 0; + int row = 0; if ( ts == NULL ) return ret; @@ -43,41 +46,64 @@ int bbs_todo( term_screen *ts, const char *fname) //log that someone use todo - bbs_log( NULL, "we are in todo" ); + bbs_log( NULL, "visited TODO" ); while( (quit_loop == 0) ) { + term_clr_scr( ts ); + term_cur_set_c( ts, 0 ); + printf("(Q)uit"); fflush( stdout ); - printf("(S)how todo list,(Q)uit:"); - ret_len = getline( &in_buf, &in_size, stdin ); - if ( ret_len > 0 ) + //dispaly todo list + row = term_get_maxrow( ts ); + term_cur_set_c( ts, 0 ); { - char ch = in_buf[0]; - switch( ch ) + struct ListNode *iter=todo_list->first; + int cnt = 1; + while ( (iter != NULL) || ( cnt > row - 2)) { - case 'q': - case 'Q': - quit_loop = 1; - ret = 0; - break; - - case 's': - case 'S': + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, 1+cnt ); + printf( "[%02d] -> %s\n", cnt, (char *)iter->val); + cnt += 1; + iter = iter->next; + } + } + + + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, term_get_maxrow( ts ) ); + printf(":"); fflush( stdout ); + + menu_input = term_getc( ts ); + //if something whent wrong dont know why, need to get some test case + if ( menu_input == -1 ) + continue; + menu_cmd = (char)menu_input; + + switch( menu_cmd ) + { + case 'q': + case 'Q': + quit_loop = 1; + break; + + case 's': + case 'S': + { + struct ListNode *iter=todo_list->first; + int cnt = 1; + while (iter != NULL) { - struct ListNode *iter=todo_list->first; - int cnt = 1; - while (iter != NULL) - { - printf( "[%02d] -> %s\n", cnt, (char *)iter->val); - cnt += 1; - iter = iter->next; - } + printf( "[%02d] -> %s\n", cnt, (char *)iter->val); + cnt += 1; + iter = iter->next; } - break; + } + break; - default: - printf("Try more\n"); - } + default: + printf("Try more\n"); } } |