Running Code
In this chapter, we will run code using the terminal inside VS Code. We will cover how to read output and some other commands that will help you effectively navigate the terminal. You will run the code and submit the output as the assignment for this chapter.
Before we run code, I will walk you through some steps to change the default shell from PowerShell to Git Bash on Windows. This is necessary to effectively use the terminal as some integration issues currently cause screen readers to not always interact well with PowerShell inside VS Code.
Steps to Change Shell
- Open VS Code and press Control+Shift+P to open the Command Palette.
- Type “Terminal: Select Default Profile” and press Enter
- You will see a list of available terminal profiles (PowerShell, Command Prompt, Git Bash, etc.)
- Use the arrow keys to navigate to “Git Bash” and press Enter
- Close any existing terminal windows by pressing Control+Shift+` or using the Command Palette to run “Terminal: Kill All Terminals”
- Open a new terminal with Control+` - it should now use Git Bash as the default shell
- You should hear “bash” or the Git Bash prompt instead of the PowerShell prompt
Note: If Git Bash is not available in the list, you may need to install Git for Windows first.
Using the Terminal
You can get screen reader focus to the terminal by pressing Control+`. Once you get focus to the terminal, you should hear the default Git Bash prompt. Here, you can enter commands and press Enter to run them. I highly encourage you to review the accessibility help (Alt+F1) for the terminal.
I will explain how the terminal works with a simple example of getting your current working directory.
Try It Yourself
- Switch to the terminal by pressing Control+`
- Type
pwd
and press Enter. You should hear the Terminal command Succeeded signal and announcement. 3. The command will be run and the screen reader may start reading the output. You can review the output character-by-character and line-by-line using the accessible view.
Assignment 5: Terminal Practice
Conduct the try it yourself exercise and submit the output of your pwd command.
Other helpful terminal functionality
Terminal inside VS Code offers several useful commands. I will highlight a few here. * Ctrl+r: opens a list of recent commands. You can select a command and press enter to run, or press alt+enter to edit. * Ctrl+.: applies a terminal quick fix if one is available. Very helpful if you type an incorrect command. * Terminal: Copy last command. copies the output. * Terminal: Copy last command and output. copies the last command and output.
Assignment 6: Running Code
Run the read_exampleCode.py code and submit the output. What are the numbers generated? Which of them were primes? Which of them were not primes?
Great! you have learned how to read, write, and run code using VS Code. In the next module, I introduce GitHub Copilot, VS Code’s AI coding assistance tool.