Command Execution
The "Enter" key is the computer's cue to start executing a command. When the LWOS is interrupted by the keyboard, and the pressed key is the Enter key, then LWOS will perform the following actions:
- Execute the command specified in shell -> user_input
- Append a new line character "\n" to shell -> buffer.
- If the command has output, append this output to shell -> buffer.
- Copy shell -> buffer to display_io -> data.
- Set display_io -> signal to true, which will interrupt the display.
- Reset shell -> user_input to an empty string ("").
- Reset interrupts -> keyboard to false.
For example, suppose that we entered "cat name.txt" then pressed the "Enter" key at time 10. The keyboard will interrupt the computer as usual:
- hostname: "computer_1"
- status: "idle"
- interrupts
- keyboard: true
- pressed_key: "Enter"
- shell
- user_input: "cat name.txt"
- buffer: "> cat name.txt"
- display_io
- data: "> cat name.txt"
- signal: false
shell -> user_input shows the keys the user has entered so far. LWOS will now ask the display to display the new line (\n) character. Thus any text that follows will be printed on the next line.
The "Enter" key is also the cue for LWOS to execute the command specified on shell -> user_input. LWOS will first split the user input by the space character (" "). Thus, the following user input:
cat name.txt
becomes the following (in Python notation):
["cat", "name.txt"]
The list above is stored in "tokens." The command, which is the first token, is stored in the "command" attribute. In this example, the command is "cat".
LWOS will also reset shell -> user_input. Future keyboard input will start a new command.
Here is the LWOS map at time 10 + 1:
- hostname: "computer_1"
- status: "waiting"
- interrupts
- keyboard: false
- tokens: ["cat", "name.txt"]
- command: "cat"
- pressed_key: "Enter"
- shell
- user_input: ""
- buffer: "> cat name.txt "
- display_io
- data: "> cat name.txt "
- signal: true
- file_system_io
- mode: "READ"
- signal: true
Notice that LWOS's status has changed to "waiting" and the file_system_io submap has been added. We will study these changes when we learn about the file system and the "cat" command.
Try typing "cat name.txt" and pressing Enter on the LWOS shell below:
If the user input in the shell is
mkdir photos
What is the command?
In the example above, when the user pressed the "Enter" key, the stauts changed from idle to
Comments
Please log in to add comments