Hello all (for the first time),
So I have implemented working idt,gdt and keyboard queue. I would like to move forward and implement a commands to use like 'clean' 'print' etc.
So I am wondering how to achieve that in proper way.
Waiting for your advices!
Best approach to implement command line
-
- Posts: 9
- Joined: Mon Nov 30, 2020 6:24 pm
- Libera.chat IRC: verynewbienoob
Re: Best approach to implement command line
You have a keyboard queue? Great. You want to print the letters as they come through the queue, and at the same time add the characters to a buffer. When you get the keycode for "enter pressed", print a newline, and parse the input from the buffer. If you don't have a filesystem, you can just create some hardcoded commands. If you do, create executables for these commands and put them in a path of some sort, (/bin on Unix, %PATH% on Windows), then laod the associated executables when you type in a command.
That's my take.
That's my take.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: Best approach to implement command line
First of all, you'll need a readline library. You can port an existing one, or write one yourself. A very very simple implementation can be found here (about 70 SLoC, replace uart_getc() and printf() with your kernel's functions). This is responsible for getting the user input. Basically it is a line editor, where the user can move the cursor around and can edit and modify the line until they press Enter (it also displays the edited line so that the user can see what they are doing).verynewbienoob wrote:So I am wondering how to achieve that in proper way.
Once an Enter is pressed, you should split the line string into a string array (like char **argc). The first element will be the command verb, and the rest its parameters. You could use other command parsing methods of course, but it worth splitting the line in advance.
Finally you dispatch the command verbs (in the first element of the string array) to different functions.
Cheers,
bzt
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Best approach to implement command line
First, you need user mode so your command interpreter can be a standalone program instead of part of your kernel.
What's best depends on how you want your kernel to work. Do you want your command interpreter to be part of your kernel? Do you want it to be an ordinary program that runs in user mode? Do you have some other idea for how you want to design your OS?
What's best depends on how you want your kernel to work. Do you want your command interpreter to be part of your kernel? Do you want it to be an ordinary program that runs in user mode? Do you have some other idea for how you want to design your OS?
-
- Posts: 9
- Joined: Mon Nov 30, 2020 6:24 pm
- Libera.chat IRC: verynewbienoob
Re: Best approach to implement command line
I'll go with that way since I've no memory management yet so I can't use readline lib.rizxt wrote:You have a keyboard queue? Great. You want to print the letters as they come through the queue, and at the same time add the characters to a buffer. When you get the keycode for "enter pressed", print a newline, and parse the input from the buffer. If you don't have a filesystem, you can just create some hardcoded commands. If you do, create executables for these commands and put them in a path of some sort, (/bin on Unix, %PATH% on Windows), then laod the associated executables when you type in a command.
That's my take.
Thanks for replies dudes