Skip to content

Commit b5b52d9

Browse files
shortcuts based on current tab, toggle solution, updated colors
1 parent 162827c commit b5b52d9

File tree

8 files changed

+31
-14
lines changed

8 files changed

+31
-14
lines changed

AwkExercises/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $ pipx install awkexercises
3434
$ awkexercises
3535
```
3636

37-
As yet another alternative, you can install `textual` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `awk_exercises.py` file.
37+
As yet another alternative, you can install `textual==0.85.2` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `awk_exercises.py` file.
3838

3939
Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's a sample screenshot:
4040

AwkExercises/app_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can either click the buttons using mouse or press the key combinations liste
4444
* **F3** view directory
4545
* **Ctrl+n** go to the next question
4646
* **Ctrl+p** go to the previous question
47-
* **Ctrl+s** show reference solution box
47+
* **Ctrl+s** toggle reference solution box
4848
* **Ctrl+t** toggle the theme between **light** and **dark** modes
4949
* **Ctrl+c** or **Ctrl+q** quit the application
5050

AwkExercises/awk_exercises.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ContentSwitcher {
2020
#solution {
2121
width: 100%;
2222
padding: 0 1 0 1;
23-
border: round black;
2423
}
2524

2625
.container {

AwkExercises/awk_exercises.png

-99 Bytes
Loading

AwkExercises/awk_exercises.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from textual.containers import Horizontal, VerticalScroll, Vertical
44
from textual.widgets import Footer, Label, Input, Button
55
from textual.widgets import MarkdownViewer, ContentSwitcher, DirectoryTree
6-
from rich.markdown import Markdown
6+
from rich.markup import escape as rich_escape
77

88
import json
99
import subprocess
1010
import os
11+
import re
1112
from pathlib import Path
1213

1314
SCRIPT_DIR = Path(__file__).parent.resolve()
@@ -118,6 +119,7 @@ def process_user_cmd(self):
118119
self.i_cmd.styles.background = 'green'
119120
self.solved = True
120121
self.action_show_solution()
122+
self.show_solution = True
121123
else:
122124
self.i_cmd.styles.background = 'lightgray'
123125
self.save_progress()
@@ -131,10 +133,11 @@ def l_cmd_output_style(self, color, title, subtitle):
131133
def set_quest_ip_op(self):
132134
self.l_ref_solution_clear()
133135
self.solved = False
134-
self.l_question.update(
135-
Markdown(f'(Q:{self.q_idx+1}/{self.q_max_idx+1}) ' +
136-
self.questions[self.q_idx]['question']))
136+
self.l_question.update(self.style_inline_code(
137+
f'(Q:{self.q_idx+1}/{self.q_max_idx+1}) ' +
138+
self.questions[self.q_idx]['question']))
137139
self.ref_solution = self.questions[self.q_idx]['ref_solution']
140+
self.show_solution = False
138141

139142
self.h_ip_op.remove()
140143
ip_files = self.questions[self.q_idx]['ip_file']
@@ -189,6 +192,7 @@ def write_progress_file(self):
189192
json.dump(self.user_progress, f, indent=2)
190193

191194
def on_button_pressed(self, event):
195+
self.refresh_bindings()
192196
name = event.button.name
193197
self.cs_tabs.current = name
194198
for b in self.b_tabs:
@@ -213,8 +217,22 @@ def l_ref_solution_clear(self):
213217
self.l_ref_solution.styles.border = ('none', 'green')
214218

215219
def action_show_solution(self):
216-
self.l_ref_solution.update('\n'.join(self.ref_solution))
217-
self.l_ref_solution.styles.border = ('round', 'green')
220+
self.show_solution ^= True
221+
if self.show_solution:
222+
self.l_ref_solution.update('\n'.join(self.ref_solution))
223+
self.l_ref_solution.styles.border = ('round', 'green')
224+
else:
225+
self.l_ref_solution_clear()
226+
227+
def style_inline_code(self, s):
228+
return re.sub(r'`([^`]+)`', r'[dark_orange3 on grey84]\1[/]',
229+
rich_escape(s))
230+
231+
def check_action(self, action, parameters):
232+
tab = self.cs_tabs.current
233+
if action in ('previous', 'next', 'show_solution') and tab != 'exercises':
234+
return False
235+
return True
218236

219237
def action_previous(self):
220238
if self.q_idx > 0:

AwkExercises/questions.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
]
1111
},
1212
"2": {
13-
"question": "For the input file `addr.txt`, display the first field of lines *not* containing `y`. Consider space as the field separator for this file.",
13+
"question": "For the input file `addr.txt`, display the first field of lines NOT containing `y`. Consider space as the field separator for this file.",
1414
"ip_file": [
1515
"addr.txt"
1616
],
@@ -181,7 +181,7 @@
181181
]
182182
},
183183
"19": {
184-
"question": "Display lines from `sample.txt` that satisfy both of these conditions:\n\n* `to` or `he` matched irrespective of case\n* `World` or `No` matched case sensitively",
184+
"question": "Display lines from `sample.txt` that satisfy both of these conditions:\n\n\u2022 `to` or `he` matched irrespective of case\n\u2022 `World` or `No` matched case sensitively",
185185
"ip_file": [
186186
"sample.txt"
187187
],
@@ -457,7 +457,7 @@
457457
]
458458
},
459459
"46": {
460-
"question": "For the input file `scores.csv`, add another column named **GP** which is calculated out of 100 by giving 50% weightage to Maths and 25% each for Physics and Chemistry.",
460+
"question": "For the input file `scores.csv`, add another column named GP which is calculated out of 100 by giving 50% weightage to Maths and 25% each for Physics and Chemistry.",
461461
"ip_file": [
462462
"scores.csv"
463463
],

AwkTutorial/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $ pipx install awktutorial
3131
$ awktutorial
3232
```
3333

34-
As yet another alternative, you can install `textual` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `awk_tutorial.py` file.
34+
As yet another alternative, you can install `textual==0.85.2` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `awk_tutorial.py` file.
3535

3636
Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's a sample screenshot:
3737

SquareTicTacToe/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ pipx install squaretictactoe
3535
$ squaretictactoe
3636
```
3737

38-
As yet another alternative, you can install `textual` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `square_tictactoe.py` file.
38+
As yet another alternative, you can install `textual==0.85.2` (see [Textual documentation](https://textual.textualize.io/getting_started/) for more details), clone this repository and run the `square_tictactoe.py` file.
3939

4040
Terminal dimension should be at least 84x25 (characters x lines) for the game widgets to appear properly. You should get an initial screen similar to the one shown below:
4141

0 commit comments

Comments
 (0)