Skip to content

Commit ad7c446

Browse files
cli exercises app is now pip installable
1 parent e6106f5 commit ad7c446

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

Diff for: CLI-Exercises/README.md

+26-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,29 @@ This TUI application includes 40 questions to test your CLI text processing skil
77
88
# Installation
99

10-
You'll need to install `textual` first. See [Textual documentation](https://textual.textualize.io/getting_started/) for more details about installation. After that, you can clone this repository and run the `cli_exercises.py` script. Adjust terminal dimensions as needed. Example instructions shown below, adjust them based on your preferences and OS.
10+
This app is available on PyPI as [cliexercises](https://pypi.org/project/cliexercises/). Example installation instructions are shown below, adjust them based on your preferences and OS.
1111

1212
```bash
13+
# virtual environment
1314
$ python3 -m venv textual_apps
1415
$ cd textual_apps
1516
$ source bin/activate
16-
$ pip install textual==0.14.0
17+
$ pip install cliexercises
1718

18-
$ git clone --depth 1 https://github.com/learnbyexample/TUI-apps.git
19-
$ cd TUI-apps/CLI-Exercises
20-
$ python cli_exercises.py
19+
# launch the app
20+
$ cliexercises
2121
```
2222

23-
After pressing **Ctrl+n** twice, you should get a screen similar to the one shown below:
23+
To run the app without having to enter the virtual environment again, add this alias to `.bashrc` (or equivalent):
24+
25+
```bash
26+
# you'll have to change the path
27+
alias cliexercises='/path/to/textual_apps/bin/cliexercises'
28+
```
29+
30+
As an alternative, you can install `textual` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `cli_exercises.py` file.
31+
32+
Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's a some sample screenshot:
2433

2534
<p align="center"><img src="./cli_exercises.png" alt="Sample screenshot for CLI exercises" /></p>
2635

@@ -55,13 +64,20 @@ After pressing **Ctrl+n** twice, you should get a screen similar to the one show
5564
* **Delete** or **Ctrl+d** delete character under the cursor
5665
* **Enter** submit the code for execution
5766

58-
> **Note**
59-
> Commands you have typed are automatically saved in `user_progress.json` (only when you press **Enter** to execute a command — navigating to another question and closing the app won't trigger the save logic). Theme choice is also saved. If you close the application and open it again, the first unsolved question will be displayed (i.e. already solved questions are skipped). If you use **Ctrl+s**, the solution *won't* be saved in `user_progress.json` — you'll have to navigate to another question and back (or close and open the app) to be considered for saving the changes. Once you have solved a question, only a different correct solution can override the previously saved command.
60-
6167
> **Warning**
6268
> There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session. For example, `ls` will list the contents of the current directory.
6369
64-
## Video demo
70+
# User progress
71+
72+
Commands you have typed are automatically saved in `user_progress.json` in the same directory as the script. This happens only when you press **Enter** to execute a command — navigating to another question and closing the app won't trigger the save logic. Theme choice is also saved.
73+
74+
If you close the application and open it again, the first unsolved question will be displayed (i.e. already solved questions are skipped).
75+
76+
If you use **Ctrl+s**, the solution *won't* be saved in `user_progress.json` — you'll have to navigate to another question and back (or close and open the app) to be considered for saving the changes.
77+
78+
Once you have solved a question, only a different correct solution can override the previously saved command.
79+
80+
# Video demo
6581

6682
https://user-images.githubusercontent.com/17766317/206649676-a913ad0d-1be7-430d-8978-98517347d86b.mp4
6783

Diff for: CLI-Exercises/cli_exercises.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import json
1010
import subprocess
1111
from functools import partial
12+
import os
13+
from pathlib import Path
1214

1315
class CLIExercisesApp(App):
1416
CSS_PATH = 'cli_exercises.css'
@@ -176,7 +178,10 @@ def action_toggle_theme(self):
176178
self.write_progress_file()
177179

178180

179-
if __name__ == '__main__':
181+
def main():
182+
os.chdir(Path(__file__).parent.resolve())
180183
app = CLIExercisesApp()
181184
app.run()
182185

186+
if __name__ == '__main__':
187+
main()

Diff for: CLI-Exercises/user_progress.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"-1": false
3+
}

0 commit comments

Comments
 (0)