Keypress Handling
If the current state of LWOS is:
- Interrupts
- Keyboard: true
- Pressed Key: k
And k is not the Enter key, then LWOS performs the following actions:
- Append "k" to Shell -> User Input.
- Append "k" to Shell -> Buffer.
- Reset Interrupts -> Keyboard to false.
For example, when a user presses the "p" key, the keyboard interrupts LWOS as follows:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: true
- Pressed Key: "p"
- Shell
- User Input: ""
- Buffer: "> "
In response, LWOS updates Interrupts -> Keyboard and the Shell as follows:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: false
- Pressed Key: "p"
- Shell
- User Input: "p"
- Buffer: "> p"
Interrupts -> Keyboard then stays false until the user presses a key again.
Suppose that the user then enters "w" and "d." Then the LWOS state becomes:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: false
- Pressed_key: "d"
- Shell
- User Input: "pwd"
- Buffer: "> pwd"
Next, the user presses the Enter key. This prompts LWOS to perform the following actions:
- Append a new line character (\n) to Shell -> Buffer.
- Execute the command that is stored in Shell -> User input (pwd).
- If the command produces any output, append it to Shell -> Buffer.
- Reset Shell -> User Input to an empty string ("").
- Reset Interrupts -> Keyboard to false.
Here is the final LWOS state:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: false
- Pressed_key: "Enter"
- Shell
- User Input: ""
- Buffer: "> pwd
/
> "
The output of the "pwd" command is the working directory, which is currently the root folder (/). LWOS prints the working directory and then prints the prompt so that the user can enter more commands.
Try running the "pwd" command in the shell below:
Current Folder | / |
> ▮
Suppose that the LWOS state is currently as follows:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: true
- Pressed Key: "d"
- Shell
- User Input: "c"
- Buffer: "> c"
Please check all the actions that will take place.
Suppose that the LWOS state is currently as follows:
- Hostname: "computer_1"
- Status: "idle"
- Interrupts
- Keyboard: true
- Pressed Key: Enter
- Shell
- User Input: "cd"
- Buffer: "> cd"
Please check all the actions that will take place.
Comments
Please log in to add comments