I'm currently new in making OS and i want to save all commands entered in the CLI.
here is the code given to me to get the input in the CLI
Code: Select all
void get_input (char* buf, int n) {
KEYCODE key = KEY_UNKNOWN;
bool BufChar;
//! get command string
int i=0;
int x= 0;
while ( i < n ) {
//! buffer the next char
BufChar = true;
//! grab next char
key = getch ();
//! end of command if enter is pressed
if (key==KEY_RETURN){
break;
}
//! backspace
if (key==KEY_BACKSPACE) {
//! dont buffer this char
BufChar = false;
if (i > 0) {
//! go back one char
unsigned y, x;
DebugGetXY (&x, &y);
if (x>0)
DebugGotoXY (--x, y);
else {
//! x is already 0, so go back one line
y--;
x = DebugGetHorz ();
}
//! erase the character from display
DebugPutc (' ');
DebugGotoXY (x, y);
//! go back one char in cmd buf
i--;
}
}
//! only add the char if it is to be buffered
if (BufChar) {
//! convert key to an ascii char and put it in buffer
char c = kkybrd_key_to_ascii (key);
if (c != 0) { //insure its an ascii char
DebugPutc (c);
buf [i++] = c;
}
}
//! wait for next key. You may need to adjust this to suite your needs
sleep (10);
}
//! null terminate the string
buf [i] = '\0';
}
i tried creating a char* history above it then equate it with buf when enter key is pressed
Code: Select all
if (key==KEY_RETURN){
history = buf;
break;
}
For example i typed history to print the CLI command history but the only output i get is "history" which is the last input before printing the CLI command history
thank you for your help!