From 084d7b4dff5e09d29d2bf0a524daf0d9177796ee Mon Sep 17 00:00:00 2001 From: SpookyDervish <78246495+SpookyDervish@users.noreply.github.com> Date: Fri, 31 Oct 2025 07:34:52 +1100 Subject: [PATCH] added a line numbers option --- main.py | 2 +- settings.py | 9 +++++++++ settings_store.py | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 5bbeeed..aa6a44d 100644 --- a/main.py +++ b/main.py @@ -66,7 +66,7 @@ class Berry(App): first_tab, id="file-tabs" ) - yield TextArea.code_editor(placeholder="This file is empty.", theme="css", id="code-editor", disabled=True, soft_wrap=True) + yield TextArea.code_editor(placeholder="This file is empty.", theme="css", id="code-editor", disabled=True, soft_wrap=True, show_line_numbers=bool(int(self.config_handler.get("editor", "line_numbers")))) #if os.name == "nt": #with Vertical(id="console-container"): diff --git a/settings.py b/settings.py index 9b59ddc..f785275 100644 --- a/settings.py +++ b/settings.py @@ -73,6 +73,9 @@ class SettingsScreen(ModalScreen): if event.switch.id == "word-wrap": self.app.query_one("#code-editor").soft_wrap = event.value self.app.config_handler.set("editor", "word_wrap", str(int(event.value))) + elif event.switch.id == "line-numbers": + self.app.query_one("#code-editor").show_line_numbers = event.value + self.app.config_handler.set("editor", "line_numbers", str(int(event.value))) elif event.switch.id == "plugins-enabled": self.app.config_handler.set("plugins", "enabled", str(int(event.value))) self.notify("Restart for changes to apply.", title="Restart Required", severity="warning") @@ -122,6 +125,12 @@ class SettingsScreen(ModalScreen): yield Label("Word Wrap", classes="setting-name") yield Label("Enable word wrap in the code editor.", classes="setting-desc") yield Switch(value=bool(int(self.app.config_handler.get("editor", "word_wrap"))), id="word-wrap") + + with HorizontalGroup(classes="setting"): + with VerticalGroup(): + yield Label("Line Numbers", classes="setting-name") + yield Label("Show line numbers in the editor.", classes="setting-desc") + yield Switch(value=bool(int(self.app.config_handler.get("editor", "line_numbers"))), id="line-numbers") with TabPane("Plugins"): with VerticalScroll(): diff --git a/settings_store.py b/settings_store.py index 08b4934..195daae 100644 --- a/settings_store.py +++ b/settings_store.py @@ -55,6 +55,12 @@ class ConfigHandler: return config_dir def get(self, section: str, option: str): + if not self.config.has_section(section): + self.config.add_section(section) + if not self.config.has_option(section, option): + self.set(section, option, "0") + return "0" + return self.config.get(section, option, fallback=None) def set(self, section: str, option: str, new_value: str): @@ -86,7 +92,8 @@ class ConfigHandler: "version": "1" } self.config["editor"] = { - "word_wrap": "0" + "word_wrap": "0", + "line_numbers": "1" } self.config["plugins"] = { "enabled": "1",