From 0fbc15ed4f3a5085e2aa2fcb6e6a137e2e8121c4 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 5 Jul 2026 01:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20enabling=20a?= =?UTF-8?q?=20monospace=20editor=20font=20via=20an=20environment=20variabl?= =?UTF-8?q?e=20or=20configuration=20file.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main.go b/main.go index d09a180..20f3e73 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "image/color" "os" "path/filepath" + "strings" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" @@ -89,6 +90,31 @@ func isReadonly() bool { return os.Getenv("READONLY") == "true" } +// fixedPitchEnabled reports whether the user opted into a monospace +// (programmer) font. The value comes from the TINY_ENCRYPT_ENABLE_FIXED_PITCH +// environment variable; when that is unset it falls back to the file at +// ~/.config/envs/TINY_ENCRYPT_ENABLE_FIXED_PITCH (content trimmed). The values +// true/on/yes/1 are accepted, case-insensitively. +func fixedPitchEnabled() bool { + v := os.Getenv("TINY_ENCRYPT_ENABLE_FIXED_PITCH") + if v == "" { + home, err := os.UserHomeDir() + if err != nil { + return false + } + data, err := os.ReadFile(filepath.Join(home, ".config", "envs", "TINY_ENCRYPT_ENABLE_FIXED_PITCH")) + if err != nil { + return false + } + v = strings.TrimSpace(string(data)) + } + switch strings.ToLower(v) { + case "true", "on", "yes", "1": + return true + } + return false +} + // windowConfig is persisted to ~/.cache/secure-editor-go-config.json so the // editor remembers its window size across runs. type windowConfig struct { @@ -246,6 +272,10 @@ func main() { textEntry := widget.NewMultiLineEntry() textEntry.Wrapping = fyne.TextWrapWord + if fixedPitchEnabled() { + // Use Fyne's bundled monospace font for a programmer-style editor. + textEntry.TextStyle = fyne.TextStyle{Monospace: true} + } initialText := string(plaintext) textEntry.SetText(initialText)