summaryrefslogtreecommitdiff
path: root/microbbs.c
diff options
context:
space:
mode:
Diffstat (limited to 'microbbs.c')
-rw-r--r--microbbs.c245
1 files changed, 135 insertions, 110 deletions
diff --git a/microbbs.c b/microbbs.c
index f620502..d0d03ba 100644
--- a/microbbs.c
+++ b/microbbs.c
@@ -5,24 +5,30 @@
#include "logs.h"
#include "motd.h"
#include "libterm/term.h"
+#include "libterm/term_io.h"
#include "ini.h"
int main( int argc, char **argv )
{
int ret_len;
+ int quit_main_menu = 0;
+ int column, row;
- size_t str_size=128;
- char *str=malloc(str_size);
+ int main_menu_input=0;
+ char main_menu_cmd;
term_screen ts;
term_init( &ts );
+ term_set_raw_mode( &ts );
term_clr_scr( &ts );
//lunch captcha and try to detect if its random bot
#ifdef CONFIG_CAPTCHA
- if ( captcha_test1() != 1)
- return 1;
+ if ( captcha_test1( ts ) != 1)
+ {
+ goto exit_restore_terminal;
+ }
bbs_log_captcha( NULL );
#endif
@@ -30,12 +36,20 @@ int main( int argc, char **argv )
//too much fake stuff comes to log
bbs_log_main( NULL ); //write to default place
#ifdef CONFIG_MOTD
- bbs_login_motd( NULL, "art/motd.txt" );
+ bbs_motd_draw( &ts, "art/motd.txt" );
+ sleep( 3 );
print_build_info();
#endif
- while ( strncmp( str, "q", 1 ) && strncmp( str, "Q", 1 ) )
+ while ( quit_main_menu == 0 )
{
+ //prepare screen for main menu output
+ term_clr_scr( &ts );
+ //column = term_cur_pos_c( &ts );
+ //row = term_cur_pos_r( &ts );
+ term_cur_set_r( &ts, 0 );
+ term_cur_set_c( &ts, 0 );
+
#ifdef CONFIG_MOTD
printf("(M)otd ");
#endif
@@ -68,116 +82,127 @@ int main( int argc, char **argv )
printf("Mesa(G)es ");
#endif
- printf("(Q)uit (S)ysinfo: ");
- ret_len = getline( &str, &str_size, stdin );
- if ( ret_len > 0)
+ printf("(Q)uit (S)ysinfo"); fflush( stdout );
+
+ term_cur_set_c( &ts, 0 );
+ term_cur_set_r( &ts, term_get_maxrow( &ts ) );
+ printf(":"); fflush( stdout );
+ //ret_len = getline( &str, &str_size, stdin );
+ main_menu_input = term_getc( &ts );
+ //if something whent wrong dont know why, need to get some test case
+ if ( main_menu_input == -1 )
+ continue;
+ main_menu_cmd = (char)main_menu_input;
+
+ switch ( main_menu_cmd )
{
- switch ( str[0] )
- {
- //------------------------------------------------------------------
- #ifdef CONFIG_MOTD
- case 'm':
- case 'M':
- {
- bbs_login_motd( &ts, "art/motd.txt" );
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- case 's':
- case 'S':
- {
- bbs_sysinfo( &ts );
- }
- break;
-
- //------------------------------------------------------------------
- #ifdef CONFIG_ARTICLES
- case 'a':
- case 'A':
- {
- bbs_article_list( &ts, "./article/" );
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifdef CONFIG_TWIT
- case 't':
- case 'T':
- {
- printf("Twitter like\n");
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifdef CONFIG_DOORGAMES
- case 'd':
- case 'D':
- {
- printf("Door games\n");
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifndef CONFIG_MESSAGING
- case 'g':
- case 'G':
- {
- printf("Messages\n");
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifdef CONFIG_BOARD
- case 'b':
- case 'B':
- {
- printf("Board\n");
- }
- break;
- #endif
-
-
- //------------------------------------------------------------------
- #ifdef CONFIG_LOGIN
- case 'l':
- case 'L':
- {
- printf("Login?\n");
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifdef CONFIG_TODO
- case 'o':
- case 'O':
- {
- printf("Todo list\n");
- bbs_todo( &ts, NULL );
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- case 'q':
- case 'Q':
- bbs_log_quit( NULL );
- break;
- default:
- printf("Unknow command\n");
- }
+ //------------------------------------------------------------------
+ #ifdef CONFIG_MOTD
+ case 'm':
+ case 'M':
+ {
+ bbs_motd_draw( &ts, "art/motd.txt" );
+ sleep( 3 );
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ case 's':
+ case 'S':
+ {
+ bbs_sysinfo( &ts );
+ }
+ break;
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_ARTICLES
+ case 'a':
+ case 'A':
+ {
+ bbs_article_list( &ts, "./article/" );
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_TWIT
+ case 't':
+ case 'T':
+ {
+ printf("Twitter like\n");
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_DOORGAMES
+ case 'd':
+ case 'D':
+ {
+ printf("Door games\n");
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ #ifndef CONFIG_MESSAGING
+ case 'g':
+ case 'G':
+ {
+ printf("Messages\n");
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_BOARD
+ case 'b':
+ case 'B':
+ {
+ printf("Board\n");
+ }
+ break;
+ #endif
+
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_LOGIN
+ case 'l':
+ case 'L':
+ {
+ printf("Login?\n");
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ #ifdef CONFIG_TODO
+ case 'o':
+ case 'O':
+ {
+ printf("Todo list\n");
+ bbs_todo( &ts, NULL );
+ }
+ break;
+ #endif
+
+ //------------------------------------------------------------------
+ case 'q':
+ case 'Q':
+ quit_main_menu = 1;
+ bbs_log_quit( NULL );
+ break;
+ default:
+ printf("Unknow command\n");
}
}
#ifdef CONFIG_MOTD
- bbs_quit_motd( &ts, "art/quit.txt" );
+ bbs_motd_draw( &ts, "art/quit.txt" );
+ sleep( 3 );
#endif
+exit_restore_terminal:
term_clr_scr( &ts );
term_set_orig_mode( &ts );
return 0;