void tty_command_mode( char *buffer, size_t maxbuf) { char c; int wid; int bufptr = 0; vt100_cursor_save (); vt100_cursor_set( tty_winsize.ws_row, 1 ); vt100_erase_line(); tty_write_char(':'); wid = tty_winsize.ws_col - 1; maxbuf--; if ( maxbuf < wid ) wid = maxbuf; while ( ( c = tty_read_input() ) != '\r' ) { if ( c >= ' ' && c < 0x7F ) { if ( bufptr == wid ) { tty_write_char( '\a' ); } else { buffer[bufptr++] = c; tty_write_char( c ); } } else if ( c == '\b' || c == 0x7F ) { if ( bufptr == 0 ) { tty_write_char( '\a' ); } else { tty_erase_char(); bufptr--; } } else if ( c == '\r' || c == '\n' ) { break; } } buffer[bufptr] = 0; vt100_cursor_set( tty_winsize.ws_row, 1 ); vt100_erase_line(); vt100_cursor_load(); }
/* * definition */ void task_tty(){ int i; MSG *p_msg; /* * Can not change */ init_console(); init_tty(); // tty_write_str("LeiMing" , (TTY *)&tty_table[TTY_ENABLE]); // tty_write_ctrl((TTY *)&tty_table[TTY_ENABLE]); // tty_write_str("is Best!" , (TTY *)&tty_table[TTY_ENABLE]); /* * Test msg = get_msg(); msg -> type = 8; tty_write_int((u32)msg -> type , (TTY *)&tty_table[TTY_ENABLE]); del_msg(msg); msg = get_msg(); tty_write_int((u32)msg -> type , (TTY *)&tty_table[TTY_ENABLE]); */ // int i; // char *src = {"Lei Ming is best hahaha"}; // char dest[20]; // for(i = 0; i < 20; i++){ // dest[i] = '0'; // } // strcpy(dest , src , sizeof(dest) - 1); // tty_write_str(dest , (TTY *)&tty_table[TTY_ENABLE]); // disp_int(i); // set_start_vmem((u32)(80 * 1)); while(1){ p_msg = recv_msg(); if(p_msg == (MSG *)NULL){ }else{ switch(p_msg -> type){ //根据消息的不同类型来不同地处理 // case MSG_WRITE_ENTER: case MSG_WRITE_CHAR: tty_write_char(p_msg -> int_info[0] , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; case MSG_WRITE_INT: tty_write_int(p_msg -> int_info[0] , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; case MSG_WRITE_STR: tty_write_str(p_msg -> str_info , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); //第二个参数是进程所在的p_tty del_msg(p_msg); break; case MSG_PRINT_CTRL: tty_print_ctrl((TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; default: break; } } key_control((TTY *)&tty_table[TTY_ENABLE]); } }