✨ Add support for enabling a monospace editor font via an environment variable or configuration file.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user