Skip to content

Theme toggling is broken in newer Textual versions #9

Description

@Rajtek

I bought the AWK exercises course and noticed that theme toggling stopped working. This happens because newer versions of the textual library replaced the dark attribute with the theme property.

I updated my local copy of awk_exercises.py to support both newer and older versions.

Here is the update for on_mount:
def on_mount(self):
is_dark = self.user_progress.get(-1, False)

    if hasattr(self, 'theme'):
        self.theme = 'textual-dark' if is_dark else 'textual-light'
    else:
        self.dark = is_dark

Here is the update for action_toggle_theme:

def action_toggle_theme(self):
if hasattr(self, 'theme'):
if self.theme == 'textual-dark':
self.theme = 'textual-light'
else:
self.theme = 'textual-dark'
is_dark = (self.theme == 'textual-dark')
else:
self.dark = not self.dark
is_dark = self.dark

    self.user_progress[-1] = is_dark
    self.write_progress_file()

This fix worked for the AWK application. I haven't tested it on the other applications in the repository. They will likely need a similar update since they seem to use the same logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions