Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced

Source of release 0.4.1

0.4.1 / src / configuration / settings.luc

from luce_config.toml import Table
from luce_ui import ui

pub class Settings:
    pub let font_family: str
    pub let font_size: float
    pub let word_wrap: bool
    pub let width: int
    pub let height: int
    pub let luce: str
    pub let base: str
    pub let shortcuts: map[str, str]

    pub func init(self, source: str = "") -> unit!:
        let table = Table(source)
        table.check_within(["editor.font_family", "editor.font_size", "editor.word_wrap", "window.width", "window.height", "compiler.luce", "compiler.luce_base"], ["shortcuts"])
        var shortcuts: map[str, str] = {}
        for id in table.keys("shortcuts"):
            shortcuts[id] = table.string("shortcuts." + id, "")
        self.shortcuts = shortcuts
        self.font_family = table.string("editor.font_family", "")
        self.font_size = table.number("editor.font_size", ui.default_font_size, 8.0, 40.0)
        self.word_wrap = table.boolean("editor.word_wrap", false)
        let width = table.number("window.width", 1180.0, 480.0, 4096.0)
        let height = table.number("window.height", 800.0, 300.0, 4096.0)
        if float(int(width)) != width or float(int(height)) != height:
            error(ui.invalid, "Window dimensions must be whole numbers")
        self.width = int(width)
        self.height = int(height)
        self.luce = table.string("compiler.luce", "luce")
        self.base = table.string("compiler.luce_base", "luce-base")

pub func defaults() -> str:
    return f"# luced user settings. Save to apply font/compiler/shortcut changes.\n# Window dimensions apply on the next launch. Empty font_family uses the OS monospace face.\n\n[editor]\nfont_family = \"\"\nfont_size = {ui.default_font_size}\nword_wrap = false\n\n[window]\nwidth = 1180\nheight = 800\n\n[compiler]\nluce = \"luce\"\nluce_base = \"luce-base\"\n\n" + shortcut_defaults()

## Command shortcuts, keyed by command id. A chord is `+`-separated and case
## insensitive: `cmd`/`ctrl`/`super` is the primary modifier, plus `shift`/`alt`;
## the last token is the key (a letter, digit, `f1`..`f12`, a symbol, or a named
## key like `enter`). Use \"none\" to unbind. Editing keys (undo, cut, copy, paste)
## are handled inside the text editor.
pub func shortcut_defaults() -> str:
    return "# Command shortcuts by id; a chord like \"cmd+shift+s\", \"f5\" or \"none\".\n[shortcuts]\nnew_tab = \"cmd+n\"\nsave = \"cmd+s\"\nsave_all = \"cmd+shift+s\"\nbuild = \"cmd+b\"\nrun = \"f5\"\nstop = \"shift+f5\"\nfold = \"cmd+alt+[\"\nfold_all = \"cmd+shift+alt+[\"\nunfold_all = \"cmd+shift+alt+]\"\ntoggle_word_wrap = \"cmd+alt+z\"\nask_ai = \"cmd+i\"\nwrite_ai = \"cmd+shift+i\"\ncommand_palette = \"cmd+p\"\nnext_pane = \"f6\"\nprevious_pane = \"shift+f6\"\nfocus_explorer = \"cmd+1\"\nfocus_editor = \"cmd+2\"\nfocus_output = \"cmd+3\"\nfocus_left = \"cmd+alt+left\"\nfocus_right = \"cmd+alt+right\"\nfocus_up = \"cmd+alt+up\"\nfocus_down = \"cmd+alt+down\"\n"