// //Entry point of the text mode shell. // DWORD ShellEntryPoint(LPVOID pData) { __KERNEL_THREAD_MESSAGE KernelThreadMessage; s_hHiscmdInoObj = His_CreateHisObj(HISCMD_MAX_COUNT); StrCpy(DEF_PROMPT_STR,&s_szPrompt[0]); CD_PrintString(VERSION_INFO,FALSE); CD_SetCursorPos(0,SHELL_INPUT_START_Y_FIRST); PrintPrompt(); while(TRUE) { if(GetMessage(&KernelThreadMessage)) { if(KERNEL_MESSAGE_TERMINAL == KernelThreadMessage.wCommand) { break; } DispatchMessage(&KernelThreadMessage,EventHandler); } } //When reach here,it means the shell thread will terminate.We will reboot //the system in current version's implementation,since there is no interact //mechanism between user and computer in case of no shell. //NOTE:System clean up operations should be put here if necessary. #ifdef __I386__ BIOSReboot(); #endif return 0; }
//Handler for 'cls' command. DWORD ClsHandler(__CMD_PARA_OBJ* pCmdParaObj) { ClearScreen(); CD_SetCursorPos(0,SHELL_INPUT_START_Y); return SHELL_CMD_PARSER_SUCCESS; }
//换行 VOID CD_GotoHome() { #ifdef __I386__ WORD CursorX = 0; WORD CursorY = 0; CD_GetCursorPos(&CursorX,&CursorY); CD_SetCursorPos(0,CursorY); #endif #ifdef __CFG_SYS_CONSOLE Console.GotoHome(); #endif }
//Print out command prompt. static VOID PrintPrompt() { WORD CursorX = 0; WORD CursorY = 0; CD_GetCursorPos(&CursorX,&CursorY); if(CursorX != 0) { CD_ChangeLine(); CD_GetCursorPos(&CursorX,&CursorY); } CD_PrintString(s_szPrompt,FALSE); CursorX = strlen(s_szPrompt); CD_SetCursorPos(CursorX,CursorY); }
//load history cmd to current cmd line static void LoadHisCmd(BOOL bUp) { CHAR szHisCmd[CMD_MAX_LEN] = {0}; WORD CursorX = 0; WORD CursorY = 0; if(His_LoadHisCmd(s_hHiscmdInoObj,bUp,szHisCmd,sizeof(szHisCmd)) == FALSE) { return; } CD_GetCursorPos(&CursorX,&CursorY); CD_SetCursorPos(SHELL_INPUT_START_X,CursorY); CD_DelString(SHELL_INPUT_START_X,CursorY,CMD_MAX_LEN); CD_PrintString(szHisCmd,FALSE); }
//回到上一个字符 VOID CD_GotoPrev() { #ifdef __I386__ WORD CursorX = 0; WORD CursorY = 0; CD_GetCursorPos(&CursorX,&CursorY); if(CursorX > 0 ) { CD_SetCursorPos(CursorX-1,CursorY); } #endif #ifdef __CFG_SYS_CONSOLE Console.GotoPrev(); #endif }
//Entry point of the text mode shell. // DWORD ShellEntryPoint(LPVOID pData) { StrCpy(DEF_PROMPT_STR,&s_szPrompt[0]); CD_PrintString(VERSION_INFO,TRUE); CD_SetCursorPos(0,SHELL_INPUT_START_Y_FIRST); Shell_Msg_Loop(s_szPrompt,CommandParser,QueryCmdName); //When reach here,it means the shell thread will terminate.We will reboot //the system in current version's implementation,since there is no interact //mechanism between user and computer in case of no shell. //NOTE:System clean up operations should be put here if necessary. #ifdef __I386__ BIOSReboot(); #endif return 0; }
static BOOL OnVkKeyControl(BYTE bt) { WORD CursorX = 0; WORD CursorY = 0; CD_GetCursorPos(&CursorX,&CursorY); switch(bt) { case VK_LEFTARROW: { if(CursorX <= SHELL_INPUT_START_X) { break; } CursorX --; CD_SetCursorPos(CursorX,CursorY); } break; case VK_RIGHTARROW: { CHAR szCurChar[2] = {0}; CD_GetString(CursorX,CursorY,szCurChar,1); if(szCurChar[0] > 0) { CD_SetCursorPos(CursorX+1,CursorY); } } break; case VK_UPARROW: { LoadHisCmd(TRUE); } break; case VK_DOWNARROW: { LoadHisCmd(FALSE); } break; case VK_DELETE: { CD_DelChar(DISPLAY_DELCHAR_CURR); } break; case VK_HOME: { CD_SetCursorPos(SHELL_INPUT_START_X,CursorY); } break; case VK_END: { CHAR szCmdBuf[CMD_MAX_LEN] = {0}; CursorX = SHELL_INPUT_START_X; CD_GetString(CursorX,CursorY,szCmdBuf,sizeof(szCmdBuf)); CursorX += strlen(szCmdBuf); CD_SetCursorPos(CursorX,CursorY); } break; default: return FALSE; } return TRUE; }
//Handler for 'cls' command. VOID ClsHandler(LPSTR pstr) { ClearScreen(); CD_SetCursorPos(0,SHELL_INPUT_START_Y); }