added a line numbers option

This commit is contained in:
SpookyDervish
2025-10-31 07:34:52 +11:00
parent ff3137419a
commit 084d7b4dff
3 changed files with 18 additions and 2 deletions

View File

@@ -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"):

View File

@@ -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():

View File

@@ -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",