Compare commits
No commits in common. "main" and "v2.1.1" have entirely different histories.
28 changed files with 497 additions and 1579 deletions
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
* @charmbracelet/everyone
|
||||
31
.github/dependabot.yml
vendored
31
.github/dependabot.yml
vendored
|
|
@ -4,45 +4,38 @@ updates:
|
|||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
time: "05:00"
|
||||
timezone: "America/New_York"
|
||||
labels:
|
||||
- "dependencies"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
groups:
|
||||
all:
|
||||
patterns:
|
||||
- "*"
|
||||
ignore:
|
||||
- dependency-name: github.com/charmbracelet/bubbletea/v2
|
||||
versions:
|
||||
- v2.0.0-beta1
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
time: "05:00"
|
||||
timezone: "America/New_York"
|
||||
labels:
|
||||
- "dependencies"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
groups:
|
||||
all:
|
||||
patterns:
|
||||
- "*"
|
||||
|
||||
- package-ecosystem: "docker"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
time: "05:00"
|
||||
timezone: "America/New_York"
|
||||
labels:
|
||||
- "dependencies"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
groups:
|
||||
all:
|
||||
patterns:
|
||||
- "*"
|
||||
|
|
|
|||
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -22,4 +22,4 @@ jobs:
|
|||
ruleguard:
|
||||
uses: charmbracelet/meta/.github/workflows/ruleguard.yml@main
|
||||
with:
|
||||
go-version: "1.26"
|
||||
go-version: stable
|
||||
|
|
|
|||
4
.github/workflows/coverage.yml
vendored
4
.github/workflows/coverage.yml
vendored
|
|
@ -8,10 +8,10 @@ jobs:
|
|||
GO111MODULE: "on"
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v7
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v7
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: stable
|
||||
|
||||
|
|
|
|||
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
|
|
@ -8,9 +8,9 @@ jobs:
|
|||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/checkout@v4
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v9.3.0
|
||||
uses: golangci/golangci-lint-action@v8.0.0
|
||||
with:
|
||||
# Optional: golangci-lint command line arguments.
|
||||
args: --issues-exit-code=0
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ linters:
|
|||
- exhaustive
|
||||
- goconst
|
||||
- godot
|
||||
- godox
|
||||
- gomoddirectives
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
|
|
@ -26,10 +27,6 @@ linters:
|
|||
- whitespace
|
||||
- wrapcheck
|
||||
exclusions:
|
||||
rules:
|
||||
- text: '(slog|log)\.\w+'
|
||||
linters:
|
||||
- noctx
|
||||
generated: lax
|
||||
presets:
|
||||
- common-false-positives
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -107,7 +107,7 @@ packages. ARM builds are also available for macOS, Linux, FreeBSD and OpenBSD.
|
|||
Or just install it with `go`:
|
||||
|
||||
```bash
|
||||
go install charm.land/glow/v3@latest
|
||||
go install github.com/charmbracelet/glow@latest
|
||||
```
|
||||
|
||||
### Build (requires Go 1.21+)
|
||||
|
|
@ -209,18 +209,8 @@ pager: true
|
|||
width: 80
|
||||
# show all files, including hidden and ignored.
|
||||
all: false
|
||||
# show line numbers (TUI-mode only)
|
||||
showLineNumbers: false
|
||||
# preserve newlines in the output
|
||||
preserveNewLines: false
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
See [contributing][contribute].
|
||||
|
||||
[contribute]: https://github.com/charmbracelet/glow/contribute
|
||||
|
||||
## Feedback
|
||||
|
||||
We’d love to hear your thoughts on this project. Feel free to drop us a note!
|
||||
|
|
|
|||
81
go.mod
81
go.mod
|
|
@ -1,76 +1,77 @@
|
|||
module charm.land/glow/v3
|
||||
module github.com/charmbracelet/glow/v2
|
||||
|
||||
go 1.26.7
|
||||
go 1.23.6
|
||||
|
||||
toolchain go1.24.1
|
||||
|
||||
require (
|
||||
charm.land/bubbles/v2 v2.1.1
|
||||
charm.land/bubbletea/v2 v2.0.8
|
||||
charm.land/glamour/v2 v2.0.1
|
||||
charm.land/lipgloss/v2 v2.0.6
|
||||
github.com/atotto/clipboard v0.1.4
|
||||
github.com/caarlos0/env/v11 v11.3.1
|
||||
github.com/charmbracelet/bubbles v0.21.0
|
||||
github.com/charmbracelet/bubbletea v1.3.5
|
||||
github.com/charmbracelet/glamour v0.10.0
|
||||
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834
|
||||
github.com/charmbracelet/log v0.4.2
|
||||
github.com/charmbracelet/x/editor v0.1.0
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/fsnotify/fsnotify v1.9.0
|
||||
github.com/mattn/go-runewidth v0.0.24
|
||||
github.com/mattn/go-runewidth v0.0.16
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/muesli/cancelreader v0.2.2
|
||||
github.com/muesli/gitcha v0.3.0
|
||||
github.com/muesli/go-app-paths v0.2.2
|
||||
github.com/muesli/mango-cobra v1.3.0
|
||||
github.com/muesli/mango-cobra v1.2.0
|
||||
github.com/muesli/reflow v0.3.0
|
||||
github.com/muesli/roff v0.1.0
|
||||
github.com/muesli/termenv v0.16.0
|
||||
github.com/rivo/uniseg v0.4.7
|
||||
github.com/sahilm/fuzzy v0.1.3
|
||||
github.com/spf13/cobra v1.10.2
|
||||
github.com/spf13/viper v1.21.0
|
||||
golang.org/x/sys v0.47.0
|
||||
golang.org/x/term v0.44.0
|
||||
golang.org/x/text v0.39.0
|
||||
mvdan.cc/sh/v3 v3.13.1
|
||||
github.com/sahilm/fuzzy v0.1.1
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/spf13/viper v1.20.1
|
||||
golang.org/x/sys v0.33.0
|
||||
golang.org/x/term v0.32.0
|
||||
golang.org/x/text v0.25.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/aymerick/douceur v0.2.0 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.8 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
|
||||
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
||||
github.com/gorilla/css v1.0.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
|
||||
github.com/muesli/mango v0.2.0 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/mango v0.1.0 // indirect
|
||||
github.com/muesli/mango-pflag v0.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.12.0 // indirect
|
||||
github.com/spf13/cast v1.7.1 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/yuin/goldmark v1.7.17 // indirect
|
||||
github.com/yuin/goldmark v1.7.8 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.5 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
|
||||
golang.org/x/net v0.56.0 // indirect
|
||||
golang.org/x/sync v0.22.0 // indirect
|
||||
golang.org/x/net v0.40.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
159
go.sum
159
go.sum
|
|
@ -1,11 +1,3 @@
|
|||
charm.land/bubbles/v2 v2.1.1 h1:7r55WzBxpo/R3z98hGmY7KKPd3ET6vsf0Fb9sDHOV60=
|
||||
charm.land/bubbles/v2 v2.1.1/go.mod h1:GE6M31gaWZVXzGw73OeuTTgy4lX+OtkH0E5ymnNsHxo=
|
||||
charm.land/bubbletea/v2 v2.0.8 h1:SxTJMhCAI3lbPmy4SgX5LWZ24AdINr4I6UEqzZvYJuY=
|
||||
charm.land/bubbletea/v2 v2.0.8/go.mod h1:2SkdgoTXluXJHOUwAoRlRXF/28vklb1rFl6GcgV1/ss=
|
||||
charm.land/glamour/v2 v2.0.1 h1:xl+r00A4aJWU0z8fgwKd9fQQ4rsphqGUzuEiXZP5n+c=
|
||||
charm.land/glamour/v2 v2.0.1/go.mod h1:jo9z8XqVKPeEFMVdvCRLGk++RyJ3CdUwgNr7EvXLw3k=
|
||||
charm.land/lipgloss/v2 v2.0.6 h1:EaGKeuA8FvF+v2BT5VmZd2LoYLaMZJXA5n34th8nCIQ=
|
||||
charm.land/lipgloss/v2 v2.0.6/go.mod h1:ipDDJNSGa1hlwDtSfW1s2/xR8Vdhbut4PXh2zEKZd0Q=
|
||||
github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE=
|
||||
github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
|
||||
|
|
@ -16,40 +8,36 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
|
|||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
|
||||
github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
|
||||
github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
|
||||
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
|
||||
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
|
||||
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
|
||||
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
|
||||
github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc=
|
||||
github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
||||
github.com/charmbracelet/glamour v0.10.0 h1:MtZvfwsYCx8jEPFJm3rIBFIMZUfUJ765oX8V6kXldcY=
|
||||
github.com/charmbracelet/glamour v0.10.0/go.mod h1:f+uf+I/ChNmqo087elLnVdCiVgjSKWuXa/l6NU2ndYk=
|
||||
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 h1:ZR7e0ro+SZZiIZD7msJyA+NjkCNNavuiPBLgerbOziE=
|
||||
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834/go.mod h1:aKC/t2arECF6rNOnaKaVU6y4t4ZeHQzqfxedE/VkVhA=
|
||||
github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig=
|
||||
github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 h1:rdnVWKgJpTVXKuKuJyxDJ+NFJdUaUqGvyGy61OcvlbA=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886/go.mod h1:nAw0d9PhFp1qdzi2xhQU5YOu5sVpDIHWlaW2Uz/bCro=
|
||||
github.com/charmbracelet/x/ansi v0.11.8 h1:JMFwp0CgDC2+jcOB162HH5k7I3FVbgFSMMYg7dSPBQQ=
|
||||
github.com/charmbracelet/x/ansi v0.11.8/go.mod h1:ZNN+3mXny/516oTQPLMPIBeSINvNJJQ8uQXDgbeJxY0=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
|
||||
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
||||
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||
github.com/charmbracelet/x/editor v0.1.0 h1:p69/dpvlwRTs9uYiPeAWruwsHqTFzHhTvQOd/WVSX98=
|
||||
github.com/charmbracelet/x/editor v0.1.0/go.mod h1:oivrEbcP/AYt/Hpvk5pwDXXrQ933gQS6UzL6fxqAGSA=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf h1:rLG0Yb6MQSDKdB52aGX55JT1oi0P0Kuaj7wi1bLUpnI=
|
||||
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf/go.mod h1:B3UgsnsBZS/eX42BlaNiJkD1pPOUa+oF1IYC6Yd2CEU=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
|
||||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
|
@ -58,18 +46,18 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK
|
|||
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
|
||||
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
|
||||
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
|
||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
|
|
@ -85,27 +73,31 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU=
|
||||
github.com/mattn/go-runewidth v0.0.24/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/gitcha v0.3.0 h1:+PJkVKrDXVB0VgRn/yVx2CqSVSDGMSepzvohsCrPYtQ=
|
||||
github.com/muesli/gitcha v0.3.0/go.mod h1:vX3jFL+XcEUq1uY74RCjLSZfAV+ZuvLg70/NGPdXn84=
|
||||
github.com/muesli/go-app-paths v0.2.2 h1:NqG4EEZwNIhBq/pREgfBmgDmt3h1Smr1MjZiXbpZUnI=
|
||||
github.com/muesli/go-app-paths v0.2.2/go.mod h1:SxS3Umca63pcFcLtbjVb+J0oD7cl4ixQWoBKhGEtEho=
|
||||
github.com/muesli/mango v0.2.0 h1:iNNc0c5VLQ6fsMgAqGQofByNUBH2Q2nEbD6TaI+5yyQ=
|
||||
github.com/muesli/mango v0.2.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
|
||||
github.com/muesli/mango-cobra v1.3.0 h1:vQy5GvPg3ndOSpduxutqFoINhWk3vD5K2dXo5E8pqec=
|
||||
github.com/muesli/mango-cobra v1.3.0/go.mod h1:Cj1ZrBu3806Qw7UjxnAUgE+7tllUBj1NCLQDwwGx19E=
|
||||
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
|
||||
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
|
||||
github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg=
|
||||
github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA=
|
||||
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
|
||||
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
|
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||
|
|
@ -114,69 +106,70 @@ github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
|
|||
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 h1:G04eS0JkAIVZfaJLjla9dNxkJCPiKIGZlw9AfOhzOD0=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94/go.mod h1:b18R55ulyQ/h3RaWyloPyER7fWQVZvimKKhnI5OfrJQ=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||
github.com/sahilm/fuzzy v0.1.3 h1:juByESSS32nVD81vr6tHmKmA/8zde7gE+x5CLxrzXPU=
|
||||
github.com/sahilm/fuzzy v0.1.3/go.mod h1:au6//VbVSqu6DFrkL2CfjlJ5iURpNCPeE+1GwY3XsT8=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
|
||||
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
|
||||
github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
|
||||
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
|
||||
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
|
||||
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
|
||||
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
github.com/yuin/goldmark v1.7.17 h1:p36OVWwRb246iHxA/U4p8OPEpOTESm4n+g+8t0EE5uA=
|
||||
github.com/yuin/goldmark v1.7.17/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
github.com/yuin/goldmark-emoji v1.0.5 h1:EMVWyCGPlXJfUXBXpuMu+ii3TIaxbVBnEX9uaDC4cIk=
|
||||
github.com/yuin/goldmark-emoji v1.0.5/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM=
|
||||
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
|
||||
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
|
||||
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
|
||||
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
||||
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
||||
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
|
||||
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
|
||||
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
|
||||
golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus=
|
||||
golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
mvdan.cc/sh/v3 v3.13.1 h1:DP3TfgZhDkT7lerUdnp6PTGKyxxzz6T+cOlY/xEvfWk=
|
||||
mvdan.cc/sh/v3 v3.13.1/go.mod h1:lXJ8SexMvEVcHCoDvAGLZgFJ9Wsm2sulmoNEXGhYZD0=
|
||||
|
|
|
|||
33
main.go
33
main.go
|
|
@ -13,13 +13,12 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"mvdan.cc/sh/v3/shell"
|
||||
|
||||
"charm.land/glamour/v2"
|
||||
"charm.land/glamour/v2/styles"
|
||||
"charm.land/glow/v3/ui"
|
||||
"charm.land/glow/v3/utils"
|
||||
"github.com/caarlos0/env/v11"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/charmbracelet/glamour/styles"
|
||||
"github.com/charmbracelet/glow/v2/ui"
|
||||
"github.com/charmbracelet/glow/v2/utils"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/log"
|
||||
gap "github.com/muesli/go-app-paths"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -171,7 +170,6 @@ func validateOptions(cmd *cobra.Command) error {
|
|||
tui = viper.GetBool("tui")
|
||||
showAllFiles = viper.GetBool("all")
|
||||
preserveNewLines = viper.GetBool("preserveNewLines")
|
||||
showLineNumbers = viper.GetBool("showLineNumbers")
|
||||
|
||||
if pager && tui {
|
||||
return errors.New("cannot use both pager and tui")
|
||||
|
|
@ -291,6 +289,7 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
|||
|
||||
// initialize glamour
|
||||
r, err := glamour.NewTermRenderer(
|
||||
glamour.WithColorProfile(lipgloss.ColorProfile()),
|
||||
utils.GlamourStyle(style, isCode),
|
||||
glamour.WithWordWrap(int(width)), //nolint:gosec
|
||||
glamour.WithBaseURL(baseURL),
|
||||
|
|
@ -311,8 +310,6 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
|||
return fmt.Errorf("unable to render markdown: %w", err)
|
||||
}
|
||||
|
||||
out = utils.ApplyTextSizing(out)
|
||||
|
||||
// display
|
||||
switch {
|
||||
case pager || cmd.Flags().Changed("pager"):
|
||||
|
|
@ -321,11 +318,8 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
|||
pagerCmd = "less -r"
|
||||
}
|
||||
|
||||
fields, err := shell.Fields(pagerCmd, os.Getenv)
|
||||
if err != nil || len(fields) == 0 {
|
||||
return fmt.Errorf("unable to parse PAGER command: %s", pagerCmd)
|
||||
}
|
||||
c := exec.Command(fields[0], fields[1:]...) //nolint:gosec
|
||||
pa := strings.Split(pagerCmd, " ")
|
||||
c := exec.Command(pa[0], pa[1:]...) //nolint:gosec
|
||||
c.Stdin = strings.NewReader(out)
|
||||
c.Stdout = os.Stdout
|
||||
if err := c.Run(); err != nil {
|
||||
|
|
@ -347,9 +341,6 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
|||
}
|
||||
|
||||
func runTUI(path string, content string) error {
|
||||
// detect text sizing support before bubbletea takes over the terminal
|
||||
_ = utils.TextSizingEnabled()
|
||||
|
||||
// Read environment to get debugging stuff
|
||||
cfg, err := env.ParseAs[ui.Config]()
|
||||
if err != nil {
|
||||
|
|
@ -369,9 +360,7 @@ func runTUI(path string, content string) error {
|
|||
cfg.PreserveNewLines = preserveNewLines
|
||||
|
||||
// Run Bubble Tea program
|
||||
prog, cleanup := ui.NewProgram(cfg, content)
|
||||
defer cleanup()
|
||||
if _, err := prog.Run(); err != nil {
|
||||
if _, err := ui.NewProgram(cfg, content).Run(); err != nil {
|
||||
return fmt.Errorf("unable to run tui program: %w", err)
|
||||
}
|
||||
|
||||
|
|
@ -407,7 +396,7 @@ func init() {
|
|||
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", fmt.Sprintf("config file (default %s)", viper.GetViper().ConfigFileUsed()))
|
||||
rootCmd.Flags().BoolVarP(&pager, "pager", "p", false, "display with pager")
|
||||
rootCmd.Flags().BoolVarP(&tui, "tui", "t", false, "display with tui")
|
||||
rootCmd.Flags().StringVarP(&style, "style", "s", "auto", "style name or JSON path")
|
||||
rootCmd.Flags().StringVarP(&style, "style", "s", styles.AutoStyle, "style name or JSON path")
|
||||
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width (set to 0 to disable)")
|
||||
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
|
||||
rootCmd.Flags().BoolVarP(&showLineNumbers, "line-numbers", "l", false, "show line numbers (TUI-mode only)")
|
||||
|
|
@ -426,7 +415,7 @@ func init() {
|
|||
_ = viper.BindPFlag("showLineNumbers", rootCmd.Flags().Lookup("line-numbers"))
|
||||
_ = viper.BindPFlag("all", rootCmd.Flags().Lookup("all"))
|
||||
|
||||
viper.SetDefault("style", "auto")
|
||||
viper.SetDefault("style", styles.AutoStyle)
|
||||
viper.SetDefault("width", 0)
|
||||
viper.SetDefault("all", true)
|
||||
|
||||
|
|
|
|||
2
style.go
2
style.go
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
import "charm.land/lipgloss/v2"
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
var (
|
||||
keyword = lipgloss.NewStyle().
|
||||
|
|
|
|||
|
|
@ -15,5 +15,6 @@ type Config struct {
|
|||
Path string
|
||||
|
||||
// For debugging the UI
|
||||
GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" envDefault:"true"`
|
||||
HighPerformancePager bool `env:"GLOW_HIGH_PERFORMANCE_PAGER" envDefault:"true"`
|
||||
GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" envDefault:"true"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/editor"
|
||||
)
|
||||
|
||||
|
|
|
|||
130
ui/pager.go
130
ui/pager.go
|
|
@ -7,12 +7,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"charm.land/bubbles/v2/viewport"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/glamour/v2"
|
||||
"charm.land/glow/v3/utils"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/charmbracelet/glow/v2/utils"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
|
|
@ -26,7 +26,56 @@ const (
|
|||
lineNumberWidth = 4
|
||||
)
|
||||
|
||||
var pagerHelpHeight int
|
||||
var (
|
||||
pagerHelpHeight int
|
||||
|
||||
mintGreen = lipgloss.AdaptiveColor{Light: "#89F0CB", Dark: "#89F0CB"}
|
||||
darkGreen = lipgloss.AdaptiveColor{Light: "#1C8760", Dark: "#1C8760"}
|
||||
|
||||
lineNumberFg = lipgloss.AdaptiveColor{Light: "#656565", Dark: "#7D7D7D"}
|
||||
|
||||
statusBarNoteFg = lipgloss.AdaptiveColor{Light: "#656565", Dark: "#7D7D7D"}
|
||||
statusBarBg = lipgloss.AdaptiveColor{Light: "#E6E6E6", Dark: "#242424"}
|
||||
|
||||
statusBarScrollPosStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.AdaptiveColor{Light: "#949494", Dark: "#5A5A5A"}).
|
||||
Background(statusBarBg).
|
||||
Render
|
||||
|
||||
statusBarNoteStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(statusBarBg).
|
||||
Render
|
||||
|
||||
statusBarHelpStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(lipgloss.AdaptiveColor{Light: "#DCDCDC", Dark: "#323232"}).
|
||||
Render
|
||||
|
||||
statusBarMessageStyle = lipgloss.NewStyle().
|
||||
Foreground(mintGreen).
|
||||
Background(darkGreen).
|
||||
Render
|
||||
|
||||
statusBarMessageScrollPosStyle = lipgloss.NewStyle().
|
||||
Foreground(mintGreen).
|
||||
Background(darkGreen).
|
||||
Render
|
||||
|
||||
statusBarMessageHelpStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#B6FFE4")).
|
||||
Background(green).
|
||||
Render
|
||||
|
||||
helpViewStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(lipgloss.AdaptiveColor{Light: "#f2f2f2", Dark: "#1B1B1B"}).
|
||||
Render
|
||||
|
||||
lineNumberStyle = lipgloss.NewStyle().
|
||||
Foreground(lineNumberFg).
|
||||
Render
|
||||
)
|
||||
|
||||
type (
|
||||
contentRenderedMsg string
|
||||
|
|
@ -58,7 +107,9 @@ type pagerModel struct {
|
|||
|
||||
func newPagerModel(common *commonModel) pagerModel {
|
||||
// Init viewport
|
||||
vp := viewport.New()
|
||||
vp := viewport.New(0, 0)
|
||||
vp.YPosition = 0
|
||||
vp.HighPerformanceRendering = config.HighPerformancePager
|
||||
|
||||
m := pagerModel{
|
||||
common: common,
|
||||
|
|
@ -70,14 +121,14 @@ func newPagerModel(common *commonModel) pagerModel {
|
|||
}
|
||||
|
||||
func (m *pagerModel) setSize(w, h int) {
|
||||
m.viewport.SetWidth(w)
|
||||
m.viewport.SetHeight(h - statusBarHeight)
|
||||
m.viewport.Width = w
|
||||
m.viewport.Height = h - statusBarHeight
|
||||
|
||||
if m.showHelp {
|
||||
if pagerHelpHeight == 0 {
|
||||
pagerHelpHeight = strings.Count(m.helpView(), "\n")
|
||||
}
|
||||
m.viewport.SetHeight(m.viewport.Height() - (statusBarHeight + pagerHelpHeight))
|
||||
m.viewport.Height -= (statusBarHeight + pagerHelpHeight)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +150,7 @@ type pagerStatusMessage struct {
|
|||
}
|
||||
|
||||
// Perform stuff that needs to happen after a successful markdown stash. Note
|
||||
// that the returned command should be sent back the through the pager
|
||||
// that the the returned command should be sent back the through the pager
|
||||
// update function.
|
||||
func (m *pagerModel) showStatusMessage(msg pagerStatusMessage) tea.Cmd {
|
||||
// Show a success message to the user
|
||||
|
|
@ -123,7 +174,7 @@ func (m *pagerModel) unload() {
|
|||
}
|
||||
m.state = pagerStateBrowse
|
||||
m.viewport.SetContent("")
|
||||
m.viewport.SetYOffset(0)
|
||||
m.viewport.YOffset = 0
|
||||
m.unwatchFile()
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +185,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
)
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyPressMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q", keyEsc:
|
||||
if m.state != pagerStateBrowse {
|
||||
|
|
@ -143,14 +194,26 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
}
|
||||
case "home", "g":
|
||||
m.viewport.GotoTop()
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
case "end", "G":
|
||||
m.viewport.GotoBottom()
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
|
||||
case "d":
|
||||
m.viewport.HalfPageDown()
|
||||
m.viewport.HalfViewDown()
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
|
||||
case "u":
|
||||
m.viewport.HalfPageUp()
|
||||
m.viewport.HalfViewUp()
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
|
||||
case "e":
|
||||
lineno := int(math.RoundToEven(float64(m.viewport.TotalLineCount()) * m.viewport.ScrollPercent()))
|
||||
|
|
@ -176,6 +239,9 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
|
||||
case "?":
|
||||
m.toggleHelp()
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
}
|
||||
|
||||
// Glow has rendered the content
|
||||
|
|
@ -183,6 +249,9 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
log.Info("content rendered", "state", m.state)
|
||||
|
||||
m.setContent(string(msg))
|
||||
if m.viewport.HighPerformanceRendering {
|
||||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
cmds = append(cmds, m.watchFile)
|
||||
|
||||
// The file was changed on disk and we're reloading it
|
||||
|
|
@ -232,26 +301,25 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
|
|||
)
|
||||
|
||||
showStatusMessage := m.state == pagerStateStatusMessage
|
||||
styles := m.common.styles
|
||||
|
||||
// Logo
|
||||
logo := glowLogoView(m.common.styles)
|
||||
logo := glowLogoView()
|
||||
|
||||
// Scroll percent
|
||||
percent := math.Max(minPercent, math.Min(maxPercent, m.viewport.ScrollPercent()))
|
||||
scrollPercent := fmt.Sprintf(" %3.f%% ", percent*percentToStringMagnitude)
|
||||
if showStatusMessage {
|
||||
scrollPercent = styles.statusBarMessageScrollPosStyle(scrollPercent)
|
||||
scrollPercent = statusBarMessageScrollPosStyle(scrollPercent)
|
||||
} else {
|
||||
scrollPercent = styles.statusBarScrollPosStyle(scrollPercent)
|
||||
scrollPercent = statusBarScrollPosStyle(scrollPercent)
|
||||
}
|
||||
|
||||
// "Help" note
|
||||
var helpNote string
|
||||
if showStatusMessage {
|
||||
helpNote = styles.statusBarMessageHelpStyle(" ? Help ")
|
||||
helpNote = statusBarMessageHelpStyle(" ? Help ")
|
||||
} else {
|
||||
helpNote = styles.statusBarHelpStyle(" ? Help ")
|
||||
helpNote = statusBarHelpStyle(" ? Help ")
|
||||
}
|
||||
|
||||
// Note
|
||||
|
|
@ -268,9 +336,9 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
|
|||
ansi.PrintableRuneWidth(helpNote),
|
||||
)), ellipsis)
|
||||
if showStatusMessage {
|
||||
note = styles.statusBarMessageStyle(note)
|
||||
note = statusBarMessageStyle(note)
|
||||
} else {
|
||||
note = styles.statusBarNoteStyle(note)
|
||||
note = statusBarNoteStyle(note)
|
||||
}
|
||||
|
||||
// Empty space
|
||||
|
|
@ -283,9 +351,9 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
|
|||
)
|
||||
emptySpace := strings.Repeat(" ", padding)
|
||||
if showStatusMessage {
|
||||
emptySpace = styles.statusBarMessageStyle(emptySpace)
|
||||
emptySpace = statusBarMessageStyle(emptySpace)
|
||||
} else {
|
||||
emptySpace = styles.statusBarNoteStyle(emptySpace)
|
||||
emptySpace = statusBarNoteStyle(emptySpace)
|
||||
}
|
||||
|
||||
fmt.Fprintf(b, "%s%s%s%s%s",
|
||||
|
|
@ -334,7 +402,7 @@ func (m pagerModel) helpView() (s string) {
|
|||
s = strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
return m.common.styles.helpViewStyle(s)
|
||||
return helpViewStyle(s)
|
||||
}
|
||||
|
||||
// COMMANDS
|
||||
|
|
@ -352,14 +420,14 @@ func renderWithGlamour(m pagerModel, md string) tea.Cmd {
|
|||
|
||||
// This is where the magic happens.
|
||||
func glamourRender(m pagerModel, markdown string) (string, error) {
|
||||
trunc := lipgloss.NewStyle().MaxWidth(m.viewport.Width() - lineNumberWidth).Render
|
||||
trunc := lipgloss.NewStyle().MaxWidth(m.viewport.Width - lineNumberWidth).Render
|
||||
|
||||
if !m.common.cfg.GlamourEnabled {
|
||||
if !config.GlamourEnabled {
|
||||
return markdown, nil
|
||||
}
|
||||
|
||||
isCode := !utils.IsMarkdownFile(m.currentDocument.Note)
|
||||
width := max(0, min(int(m.common.cfg.GlamourMaxWidth), m.viewport.Width())) //nolint:gosec
|
||||
width := max(0, min(int(m.common.cfg.GlamourMaxWidth), m.viewport.Width)) //nolint:gosec
|
||||
if isCode {
|
||||
width = 0
|
||||
}
|
||||
|
|
@ -388,8 +456,6 @@ func glamourRender(m pagerModel, markdown string) (string, error) {
|
|||
|
||||
if isCode {
|
||||
out = strings.TrimSpace(out)
|
||||
} else {
|
||||
out = utils.ApplyTextSizing(out)
|
||||
}
|
||||
|
||||
// trim lines
|
||||
|
|
@ -398,7 +464,7 @@ func glamourRender(m pagerModel, markdown string) (string, error) {
|
|||
var content strings.Builder
|
||||
for i, s := range lines {
|
||||
if isCode || m.common.cfg.ShowLineNumbers {
|
||||
content.WriteString(m.common.styles.lineNumberStyle(fmt.Sprintf("%"+fmt.Sprint(lineNumberWidth)+"d", i+1)))
|
||||
content.WriteString(lineNumberStyle(fmt.Sprintf("%"+fmt.Sprint(lineNumberWidth)+"d", i+1)))
|
||||
content.WriteString(trunc(s))
|
||||
} else {
|
||||
content.WriteString(s)
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGlamourRenderTextSizing(t *testing.T) {
|
||||
t.Setenv("GLOW_TEXT_SIZING", "on")
|
||||
|
||||
common := &commonModel{
|
||||
cfg: Config{
|
||||
GlamourEnabled: true,
|
||||
GlamourStyle: "dark",
|
||||
GlamourMaxWidth: 80,
|
||||
},
|
||||
styles: newStyles(true),
|
||||
width: 80,
|
||||
height: 24,
|
||||
}
|
||||
m := newPagerModel(common)
|
||||
m.currentDocument = markdown{Note: "test.md"}
|
||||
m.setSize(80, 24)
|
||||
|
||||
out, err := glamourRender(m, "# Hello\n\n## World\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The dark style's H1 has a background color, which renders broken when
|
||||
// scaled, so it is left at normal size.
|
||||
if strings.Contains(out, "\x1b]66;s=3;") {
|
||||
t.Errorf("expected H1 with background to not be scaled, got %q", out)
|
||||
}
|
||||
if !strings.Contains(out, "Hello") {
|
||||
t.Errorf("expected H1 text in pager output, got %q", out)
|
||||
}
|
||||
if !strings.Contains(out, "\x1b]66;s=2;World\x1b\\") {
|
||||
t.Errorf("expected H2 at 2x scale in pager output, got %q", out)
|
||||
}
|
||||
if strings.Contains(out, "\x1b]6666;") {
|
||||
t.Errorf("expected no leftover markers in pager output, got %q", out)
|
||||
}
|
||||
}
|
||||
139
ui/rawpaint.go
139
ui/rawpaint.go
|
|
@ -1,139 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// rawPainter paints frames directly to the terminal. It is used when kitty
|
||||
// text sizing support is detected: bubbletea's default renderer parses each
|
||||
// frame into a cell buffer which discards OSC 66 sequences along with their
|
||||
// payload text, so the program runs with [tea.WithoutRenderer] and this
|
||||
// painter drives the terminal instead.
|
||||
type rawPainter struct {
|
||||
w io.Writer
|
||||
tty *os.File
|
||||
state *term.State
|
||||
mouse bool
|
||||
done chan struct{}
|
||||
|
||||
mu sync.Mutex
|
||||
gen int
|
||||
painted int
|
||||
}
|
||||
|
||||
func newRawPainter(w io.Writer, tty *os.File, state *term.State, mouse bool) *rawPainter {
|
||||
return &rawPainter{w: w, tty: tty, state: state, mouse: mouse, done: make(chan struct{})}
|
||||
}
|
||||
|
||||
func (p *rawPainter) windowSize() tea.WindowSizeMsg {
|
||||
if p.tty != nil {
|
||||
if w, h, err := term.GetSize(int(p.tty.Fd())); err == nil && w > 0 && h > 0 {
|
||||
return tea.WindowSizeMsg{Width: w, Height: h}
|
||||
}
|
||||
}
|
||||
return tea.WindowSizeMsg{Width: 80, Height: 24}
|
||||
}
|
||||
|
||||
func (p *rawPainter) start() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
_, _ = io.WriteString(p.w, "\x1b[?1049h\x1b[?25l")
|
||||
if p.mouse {
|
||||
_, _ = io.WriteString(p.w, "\x1b[?1002h\x1b[?1006h")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *rawPainter) stop() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.mouse {
|
||||
_, _ = io.WriteString(p.w, "\x1b[?1002l\x1b[?1006l")
|
||||
}
|
||||
_, _ = io.WriteString(p.w, "\x1b[?25h\x1b[?1049l")
|
||||
if p.tty != nil {
|
||||
if p.state != nil {
|
||||
_ = term.Restore(int(p.tty.Fd()), p.state)
|
||||
}
|
||||
_ = p.tty.Close()
|
||||
}
|
||||
select {
|
||||
case <-p.done:
|
||||
default:
|
||||
close(p.done)
|
||||
}
|
||||
}
|
||||
|
||||
// watchResize sends the initial window size to the program and reports
|
||||
// terminal resizes. Without a renderer bubbletea never initializes the tty,
|
||||
// so its own size reporting never happens.
|
||||
func (p *rawPainter) watchResize(prog *tea.Program) {
|
||||
ch := make(chan os.Signal, 1)
|
||||
winchNotify(ch)
|
||||
go func() {
|
||||
prog.Send(p.windowSize())
|
||||
for {
|
||||
select {
|
||||
case <-p.done:
|
||||
winchStop(ch)
|
||||
return
|
||||
case <-ch:
|
||||
prog.Send(p.windowSize())
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (p *rawPainter) paint(frame string) tea.Cmd {
|
||||
p.mu.Lock()
|
||||
p.gen++
|
||||
gen := p.gen
|
||||
p.mu.Unlock()
|
||||
|
||||
return func() tea.Msg {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if gen <= p.painted {
|
||||
return nil
|
||||
}
|
||||
p.painted = gen
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString("\x1b[?2026h\x1b[H\x1b[2J")
|
||||
b.WriteString(strings.ReplaceAll(frame, "\n", "\r\n"))
|
||||
b.WriteString("\x1b[?2026l")
|
||||
_, _ = io.WriteString(p.w, b.String())
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// paintModel wraps the root model, painting a frame after every processed
|
||||
// message. Bubbletea's renderer never calls View when it is disabled, so the
|
||||
// wrapper drives painting itself.
|
||||
type paintModel struct {
|
||||
inner tea.Model
|
||||
painter *rawPainter
|
||||
}
|
||||
|
||||
func (m paintModel) Init() tea.Cmd {
|
||||
m.painter.start()
|
||||
return tea.Batch(m.inner.Init(), m.painter.paint(m.inner.View().Content))
|
||||
}
|
||||
|
||||
func (m paintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if ws, ok := msg.(tea.WindowSizeMsg); ok && (ws.Width <= 0 || ws.Height <= 0) {
|
||||
msg = m.painter.windowSize()
|
||||
}
|
||||
inner, cmd := m.inner.Update(msg)
|
||||
m.inner = inner
|
||||
return m, tea.Batch(cmd, m.painter.paint(inner.View().Content))
|
||||
}
|
||||
|
||||
func (m paintModel) View() tea.View {
|
||||
return m.inner.View()
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
func TestRawPainterPaint(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
p := &rawPainter{w: &buf}
|
||||
|
||||
stale := p.paint("stale frame")
|
||||
fresh := p.paint("fresh\nframe")
|
||||
|
||||
fresh()
|
||||
stale()
|
||||
|
||||
got := buf.String()
|
||||
if strings.Contains(got, "stale") {
|
||||
t.Errorf("stale frame was painted over a newer one: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "\x1b[?2026h\x1b[H\x1b[2Jfresh\r\nframe\x1b[?2026l") {
|
||||
t.Errorf("unexpected frame format: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaintModelRendersDocument(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "test.md")
|
||||
if err := os.WriteFile(path, []byte("# Hello\n\nSome text here.\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
GlamourEnabled: true,
|
||||
GlamourStyle: "dark",
|
||||
GlamourMaxWidth: 80,
|
||||
Path: path,
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
painter := &rawPainter{w: &buf}
|
||||
var pm tea.Model = paintModel{inner: newModel(cfg, ""), painter: painter}
|
||||
|
||||
msgCh := make(chan tea.Msg, 64)
|
||||
var exec func(cmd tea.Cmd)
|
||||
exec = func(cmd tea.Cmd) {
|
||||
if cmd == nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
switch msg := cmd().(type) {
|
||||
case tea.BatchMsg:
|
||||
for _, c := range msg {
|
||||
exec(c)
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
msgCh <- msg
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
exec(pm.Init())
|
||||
msgCh <- tea.WindowSizeMsg{Width: 80, Height: 24}
|
||||
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for {
|
||||
// Frames are painted asynchronously by the paint command, so poll
|
||||
// the buffer instead of only checking after processed messages.
|
||||
painter.mu.Lock()
|
||||
done := strings.Contains(buf.String(), "Some text")
|
||||
painter.mu.Unlock()
|
||||
if done {
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("timed out waiting for content; buf=%q", buf.String())
|
||||
}
|
||||
|
||||
select {
|
||||
case msg := <-msgCh:
|
||||
im, cmd := pm.Update(msg)
|
||||
pm = im
|
||||
exec(cmd)
|
||||
case <-time.After(5 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaintModelZeroSizeSubstitution(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
painter := &rawPainter{w: &buf}
|
||||
pm := paintModel{inner: newModel(Config{}, "body"), painter: painter}
|
||||
|
||||
im, _ := pm.Update(tea.WindowSizeMsg{Width: 0, Height: 0})
|
||||
m := im.(paintModel).inner.(model)
|
||||
if m.common.width != 80 || m.common.height != 24 {
|
||||
t.Errorf("expected fallback size 80x24, got %dx%d", m.common.width, m.common.height)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
//go:build !windows
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
func openRawTerminal() (*os.File, *term.State, error) {
|
||||
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
state, err := term.MakeRaw(int(tty.Fd()))
|
||||
if err != nil {
|
||||
_ = tty.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
return tty, state, nil
|
||||
}
|
||||
|
||||
func winchNotify(ch chan os.Signal) {
|
||||
signal.Notify(ch, syscall.SIGWINCH)
|
||||
}
|
||||
|
||||
func winchStop(ch chan os.Signal) {
|
||||
signal.Stop(ch)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
func openRawTerminal() (*os.File, *term.State, error) {
|
||||
return nil, nil, errors.New("raw terminal is not supported on windows")
|
||||
}
|
||||
|
||||
func winchNotify(chan os.Signal) {}
|
||||
|
||||
func winchStop(chan os.Signal) {}
|
||||
145
ui/stash.go
145
ui/stash.go
|
|
@ -8,12 +8,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"charm.land/bubbles/v2/paginator"
|
||||
"charm.land/bubbles/v2/spinner"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/bubbles/paginator"
|
||||
"github.com/charmbracelet/bubbles/spinner"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/dustin/go-humanize/english"
|
||||
"github.com/muesli/reflow/ansi"
|
||||
"github.com/muesli/reflow/truncate"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
|
@ -29,6 +29,25 @@ const (
|
|||
|
||||
var stashingStatusMessage = statusMessage{normalStatusMessage, "Stashing..."}
|
||||
|
||||
var (
|
||||
dividerDot = darkGrayFg.SetString(" • ")
|
||||
dividerBar = darkGrayFg.SetString(" │ ")
|
||||
|
||||
logoStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#ECFD65")).
|
||||
Background(fuchsia).
|
||||
Bold(true)
|
||||
|
||||
stashSpinnerStyle = lipgloss.NewStyle().
|
||||
Foreground(gray)
|
||||
stashInputPromptStyle = lipgloss.NewStyle().
|
||||
Foreground(yellowGreen).
|
||||
MarginRight(1)
|
||||
stashInputCursorStyle = lipgloss.NewStyle().
|
||||
Foreground(fuchsia).
|
||||
MarginRight(1)
|
||||
)
|
||||
|
||||
// MSG
|
||||
|
||||
type (
|
||||
|
|
@ -63,28 +82,8 @@ type section struct {
|
|||
cursor int
|
||||
}
|
||||
|
||||
// newSections returns the default set of sections.
|
||||
func newSections() map[sectionKey]section {
|
||||
return map[sectionKey]section{
|
||||
documentsSection: {
|
||||
key: documentsSection,
|
||||
paginator: paginator.Model{Type: paginator.Dots},
|
||||
},
|
||||
filterSection: {
|
||||
key: filterSection,
|
||||
paginator: paginator.Model{Type: paginator.Dots},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// stylePaginators updates the paginators with the current styles.
|
||||
func (m *stashModel) stylePaginators(styles Styles) {
|
||||
for i := range m.sections {
|
||||
p := &m.sections[i].paginator
|
||||
p.ActiveDot = styles.brightGrayFg("•")
|
||||
p.InactiveDot = styles.darkGrayFg.Render("•")
|
||||
}
|
||||
}
|
||||
// map sections to their associated types.
|
||||
var sections = map[sectionKey]section{}
|
||||
|
||||
// filterState is the current filtering state in the file listing.
|
||||
type filterState int
|
||||
|
|
@ -111,16 +110,29 @@ type statusMessage struct {
|
|||
message string
|
||||
}
|
||||
|
||||
func initSections() {
|
||||
sections = map[sectionKey]section{
|
||||
documentsSection: {
|
||||
key: documentsSection,
|
||||
paginator: newStashPaginator(),
|
||||
},
|
||||
filterSection: {
|
||||
key: filterSection,
|
||||
paginator: newStashPaginator(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a styled version of the status message appropriate for the
|
||||
// given context.
|
||||
func (s statusMessage) String(styles Styles) string {
|
||||
func (s statusMessage) String() string {
|
||||
switch s.status { //nolint:exhaustive
|
||||
case subtleStatusMessage:
|
||||
return styles.dimGreenFg(s.message)
|
||||
return dimGreenFg(s.message)
|
||||
case errorStatusMessage:
|
||||
return styles.redFg(s.message)
|
||||
return redFg(s.message)
|
||||
default:
|
||||
return styles.greenFg(s.message)
|
||||
return greenFg(s.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,9 +208,9 @@ func (m *stashModel) setSize(width, height int) {
|
|||
m.common.width = width
|
||||
m.common.height = height
|
||||
|
||||
m.filterInput.SetWidth(width - stashViewHorizontalPadding*2 - ansi.PrintableRuneWidth(
|
||||
m.filterInput.Width = width - stashViewHorizontalPadding*2 - ansi.PrintableRuneWidth(
|
||||
m.filterInput.Prompt,
|
||||
))
|
||||
)
|
||||
|
||||
m.updatePagination()
|
||||
}
|
||||
|
|
@ -362,24 +374,16 @@ func (m *stashModel) moveCursorDown() {
|
|||
// INIT
|
||||
|
||||
func newStashModel(common *commonModel) stashModel {
|
||||
styles := common.styles
|
||||
sp := spinner.New()
|
||||
sp.Spinner = spinner.Line
|
||||
sp.Style = styles.stashSpinnerStyle
|
||||
sp.Style = stashSpinnerStyle
|
||||
|
||||
si := textinput.New()
|
||||
si.Prompt = "Find:"
|
||||
// The filter input is rendered inline into the larger stash view, so draw
|
||||
// the cursor as part of the string rather than moving the real one.
|
||||
si.SetVirtualCursor(true)
|
||||
tsi := si.Styles()
|
||||
tsi.Focused.Prompt = styles.stashInputPromptStyle
|
||||
tsi.Blurred.Prompt = styles.stashInputPromptStyle
|
||||
tsi.Cursor.Color = styles.fuchsia
|
||||
si.SetStyles(tsi)
|
||||
si.PromptStyle = stashInputPromptStyle
|
||||
si.Cursor.Style = stashInputCursorStyle
|
||||
si.Focus()
|
||||
|
||||
sections := newSections()
|
||||
s := []section{
|
||||
sections[documentsSection],
|
||||
}
|
||||
|
|
@ -391,11 +395,18 @@ func newStashModel(common *commonModel) stashModel {
|
|||
serverPage: 1,
|
||||
sections: s,
|
||||
}
|
||||
m.stylePaginators(styles)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func newStashPaginator() paginator.Model {
|
||||
p := paginator.New()
|
||||
p.Type = paginator.Dots
|
||||
p.ActiveDot = brightGrayFg("•")
|
||||
p.InactiveDot = darkGrayFg.Render("•")
|
||||
return p
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
|
||||
func (m stashModel) update(msg tea.Msg) (stashModel, tea.Cmd) {
|
||||
|
|
@ -438,7 +449,7 @@ func (m stashModel) update(msg tea.Msg) (stashModel, tea.Cmd) {
|
|||
cmds = append(cmds, m.handleDocumentBrowsing(msg))
|
||||
case stashStateShowingError:
|
||||
// Any key exists the error view
|
||||
if _, ok := msg.(tea.KeyPressMsg); ok {
|
||||
if _, ok := msg.(tea.KeyMsg); ok {
|
||||
m.viewState = stashStateReady
|
||||
}
|
||||
}
|
||||
|
|
@ -454,7 +465,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
|||
|
||||
switch msg := msg.(type) {
|
||||
// Handle keys
|
||||
case tea.KeyPressMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "k", "ctrl+k", "up":
|
||||
m.moveCursorUp()
|
||||
|
|
@ -568,7 +579,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
|||
cmds = append(cmds, cmd)
|
||||
|
||||
// Extra paginator keystrokes
|
||||
if key, ok := msg.(tea.KeyPressMsg); ok {
|
||||
if key, ok := msg.(tea.KeyMsg); ok {
|
||||
switch key.String() {
|
||||
case "b", "u":
|
||||
m.paginator().PrevPage()
|
||||
|
|
@ -591,7 +602,7 @@ func (m *stashModel) handleFiltering(msg tea.Msg) tea.Cmd {
|
|||
var cmds []tea.Cmd
|
||||
|
||||
// Handle keys
|
||||
if msg, ok := msg.(tea.KeyPressMsg); ok { //nolint:nestif
|
||||
if msg, ok := msg.(tea.KeyMsg); ok { //nolint:nestif
|
||||
switch msg.String() {
|
||||
case keyEsc:
|
||||
// Cancel filtering
|
||||
|
|
@ -623,7 +634,7 @@ func (m *stashModel) handleFiltering(msg tea.Msg) tea.Cmd {
|
|||
|
||||
// Add new section if it's not present
|
||||
if m.sections[len(m.sections)-1].key != filterSection {
|
||||
m.sections = append(m.sections, newSections()[filterSection])
|
||||
m.sections = append(m.sections, sections[filterSection])
|
||||
}
|
||||
m.sectionIndex = len(m.sections) - 1
|
||||
|
||||
|
|
@ -660,7 +671,7 @@ func (m stashModel) view() string {
|
|||
var s string
|
||||
switch m.viewState {
|
||||
case stashStateShowingError:
|
||||
return errorView(m.common.styles, m.err, false)
|
||||
return errorView(m.err, false)
|
||||
case stashStateLoadingDocument:
|
||||
s += " " + m.spinner.View() + " Loading document..."
|
||||
case stashStateReady:
|
||||
|
|
@ -676,13 +687,13 @@ func (m stashModel) view() string {
|
|||
// Rules for the logo, filter and status message.
|
||||
logoOrFilter := " "
|
||||
if m.showStatusMessage && m.filterState == filtering {
|
||||
logoOrFilter += m.statusMessage.String(m.common.styles)
|
||||
logoOrFilter += m.statusMessage.String()
|
||||
} else if m.filterState == filtering {
|
||||
logoOrFilter += m.filterInput.View()
|
||||
} else {
|
||||
logoOrFilter += glowLogoView(m.common.styles)
|
||||
logoOrFilter += glowLogoView()
|
||||
if m.showStatusMessage {
|
||||
logoOrFilter += " " + m.statusMessage.String(m.common.styles)
|
||||
logoOrFilter += " " + m.statusMessage.String()
|
||||
}
|
||||
}
|
||||
logoOrFilter = truncate.StringWithTail(logoOrFilter, uint(m.common.width-1), ellipsis) //nolint:gosec
|
||||
|
|
@ -716,9 +727,9 @@ func (m stashModel) view() string {
|
|||
// One could argue, in fact, that using pointers in
|
||||
// a functional framework is an antipattern and our use of
|
||||
// pointers in our model should be refactored away.
|
||||
p := *m.paginator()
|
||||
p := *(m.paginator())
|
||||
p.Type = paginator.Arabic
|
||||
pagination = m.common.styles.paginationStyle.Render(p.View())
|
||||
pagination = paginationStyle.Render(p.View())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -736,12 +747,11 @@ func (m stashModel) view() string {
|
|||
return "\n" + indent(s, stashIndent)
|
||||
}
|
||||
|
||||
func glowLogoView(styles Styles) string {
|
||||
return styles.logoStyle.Render(" Glow ")
|
||||
func glowLogoView() string {
|
||||
return logoStyle.Render(" Glow ")
|
||||
}
|
||||
|
||||
func (m stashModel) headerView() string {
|
||||
styles := m.common.styles
|
||||
localCount := len(m.markdowns)
|
||||
|
||||
var sections []string //nolint:prealloc
|
||||
|
|
@ -749,17 +759,17 @@ func (m stashModel) headerView() string {
|
|||
// Filter results
|
||||
if m.filterState == filtering {
|
||||
if localCount == 0 {
|
||||
return styles.grayFg("Nothing found.")
|
||||
return grayFg("Nothing found.")
|
||||
}
|
||||
if localCount > 0 {
|
||||
sections = append(sections, fmt.Sprintf("%d local", localCount))
|
||||
}
|
||||
|
||||
for i := range sections {
|
||||
sections[i] = styles.grayFg(sections[i])
|
||||
sections[i] = grayFg(sections[i])
|
||||
}
|
||||
|
||||
return strings.Join(sections, styles.dividerDot.String())
|
||||
return strings.Join(sections, dividerDot.String())
|
||||
}
|
||||
|
||||
// Tabs
|
||||
|
|
@ -768,20 +778,21 @@ func (m stashModel) headerView() string {
|
|||
|
||||
switch v.key {
|
||||
case documentsSection:
|
||||
s = fmt.Sprintf("%s", english.Plural(localCount, "document", ""))
|
||||
s = fmt.Sprintf("%d documents", localCount)
|
||||
|
||||
case filterSection:
|
||||
s = fmt.Sprintf("%d “%s”", len(m.filteredMarkdowns), m.filterInput.Value())
|
||||
}
|
||||
|
||||
if m.sectionIndex == i && len(m.sections) > 1 {
|
||||
s = styles.selectedTabStyle.Render(s)
|
||||
s = selectedTabStyle.Render(s)
|
||||
} else {
|
||||
s = styles.tabStyle.Render(s)
|
||||
s = tabStyle.Render(s)
|
||||
}
|
||||
sections = append(sections, s)
|
||||
}
|
||||
|
||||
return strings.Join(sections, styles.dividerBar.String())
|
||||
return strings.Join(sections, dividerBar.String())
|
||||
}
|
||||
|
||||
func (m stashModel) populatedView() string {
|
||||
|
|
@ -792,7 +803,7 @@ func (m stashModel) populatedView() string {
|
|||
// Empty states
|
||||
if len(mds) == 0 {
|
||||
f := func(s string) {
|
||||
b.WriteString(" " + m.common.styles.grayFg(s))
|
||||
b.WriteString(" " + grayFg(s))
|
||||
}
|
||||
|
||||
switch m.sections[m.sectionIndex].key {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func newHelpColumn(pairs ...string) (h helpColumn) {
|
|||
}
|
||||
|
||||
// render returns styled and formatted rows from keys and values.
|
||||
func (h helpColumn) render(styles Styles, height int) (rows []string) {
|
||||
func (h helpColumn) render(height int) (rows []string) {
|
||||
keyWidth, valWidth := h.maxWidths()
|
||||
|
||||
for i := 0; i < height; i++ {
|
||||
|
|
@ -44,11 +44,11 @@ func (h helpColumn) render(styles Styles, height int) (rows []string) {
|
|||
|
||||
switch k {
|
||||
case "s":
|
||||
k = styles.greenFg(k)
|
||||
v = styles.semiDimGreenFg(v)
|
||||
k = greenFg(k)
|
||||
v = semiDimGreenFg(v)
|
||||
default:
|
||||
k = styles.grayFg(k)
|
||||
v = styles.midGrayFg(v)
|
||||
k = grayFg(k)
|
||||
v = midGrayFg(v)
|
||||
}
|
||||
}
|
||||
b.WriteString(k)
|
||||
|
|
@ -181,7 +181,7 @@ func (m stashModel) miniHelpView(entries ...string) string {
|
|||
}
|
||||
|
||||
var (
|
||||
truncationChar = m.common.styles.subtleStyle.Render("…")
|
||||
truncationChar = subtleStyle.Render("…")
|
||||
truncationWidth = ansi.PrintableRuneWidth(truncationChar)
|
||||
)
|
||||
|
||||
|
|
@ -199,13 +199,13 @@ func (m stashModel) miniHelpView(entries ...string) string {
|
|||
k := entries[i]
|
||||
v := entries[i+1]
|
||||
|
||||
k = m.common.styles.grayFg(k)
|
||||
v = m.common.styles.midGrayFg(v)
|
||||
k = grayFg(k)
|
||||
v = midGrayFg(v)
|
||||
|
||||
next = fmt.Sprintf("%s %s", k, v)
|
||||
|
||||
if i < len(entries)-2 {
|
||||
next += m.common.styles.dividerDot.String()
|
||||
next += dividerDot.String()
|
||||
}
|
||||
|
||||
// Only this (and the following) help text items if we have the
|
||||
|
|
@ -243,7 +243,7 @@ func (m stashModel) fullHelpView(groups ...[]string) string {
|
|||
|
||||
// Build columns
|
||||
for _, c := range columns {
|
||||
renderedCols = append(renderedCols, c.render(m.common.styles, tallestCol))
|
||||
renderedCols = append(renderedCols, c.render(tallestCol))
|
||||
}
|
||||
|
||||
// Merge columns
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/muesli/reflow/truncate"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
|
@ -30,7 +30,6 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
|
|||
isSelected := index == m.cursor()
|
||||
isFiltering := m.filterState == filtering
|
||||
singleFilteredItem := isFiltering && len(m.getVisibleMarkdowns()) == 1
|
||||
styles := m.common.styles
|
||||
|
||||
// If there are multiple items being filtered don't highlight a selected
|
||||
// item in the results. If we've filtered down to one item, however,
|
||||
|
|
@ -38,48 +37,48 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
|
|||
if isSelected && !isFiltering || singleFilteredItem { //nolint:nestif
|
||||
// Selected item
|
||||
if m.statusMessage == stashingStatusMessage {
|
||||
gutter = styles.greenFg(verticalLine)
|
||||
icon = styles.dimGreenFg(icon)
|
||||
title = styles.greenFg(title)
|
||||
date = styles.semiDimGreenFg(date)
|
||||
editedBy = styles.semiDimGreenFg(editedBy)
|
||||
separator = styles.semiDimGreenFg(separator)
|
||||
gutter = greenFg(verticalLine)
|
||||
icon = dimGreenFg(icon)
|
||||
title = greenFg(title)
|
||||
date = semiDimGreenFg(date)
|
||||
editedBy = semiDimGreenFg(editedBy)
|
||||
separator = semiDimGreenFg(separator)
|
||||
} else {
|
||||
gutter = styles.dullFuchsiaFg(verticalLine)
|
||||
gutter = dullFuchsiaFg(verticalLine)
|
||||
if m.currentSection().key == filterSection &&
|
||||
m.filterState == filterApplied || singleFilteredItem {
|
||||
s := lipgloss.NewStyle().Foreground(styles.fuchsia)
|
||||
s := lipgloss.NewStyle().Foreground(fuchsia)
|
||||
title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline(true))
|
||||
} else {
|
||||
title = styles.fuchsiaFg(title)
|
||||
icon = styles.fuchsiaFg(icon)
|
||||
title = fuchsiaFg(title)
|
||||
icon = fuchsiaFg(icon)
|
||||
}
|
||||
date = styles.dimFuchsiaFg(date)
|
||||
editedBy = styles.dimDullFuchsiaFg(editedBy)
|
||||
separator = styles.dullFuchsiaFg(separator)
|
||||
date = dimFuchsiaFg(date)
|
||||
editedBy = dimDullFuchsiaFg(editedBy)
|
||||
separator = dullFuchsiaFg(separator)
|
||||
}
|
||||
} else {
|
||||
gutter = " "
|
||||
if m.statusMessage == stashingStatusMessage {
|
||||
icon = styles.dimGreenFg(icon)
|
||||
title = styles.greenFg(title)
|
||||
date = styles.semiDimGreenFg(date)
|
||||
editedBy = styles.semiDimGreenFg(editedBy)
|
||||
separator = styles.semiDimGreenFg(separator)
|
||||
icon = dimGreenFg(icon)
|
||||
title = greenFg(title)
|
||||
date = semiDimGreenFg(date)
|
||||
editedBy = semiDimGreenFg(editedBy)
|
||||
separator = semiDimGreenFg(separator)
|
||||
} else if isFiltering && m.filterInput.Value() == "" {
|
||||
icon = styles.dimGreenFg(icon)
|
||||
title = styles.dimNormalFg(title)
|
||||
date = styles.dimBrightGrayFg(date)
|
||||
editedBy = styles.dimBrightGrayFg(editedBy)
|
||||
separator = styles.dimBrightGrayFg(separator)
|
||||
icon = dimGreenFg(icon)
|
||||
title = dimNormalFg(title)
|
||||
date = dimBrightGrayFg(date)
|
||||
editedBy = dimBrightGrayFg(editedBy)
|
||||
separator = dimBrightGrayFg(separator)
|
||||
} else {
|
||||
icon = styles.greenFg(icon)
|
||||
icon = greenFg(icon)
|
||||
|
||||
s := lipgloss.NewStyle().Foreground(styles.adaptive("#1a1a1a", "#dddddd"))
|
||||
s := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"})
|
||||
title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline(true))
|
||||
date = styles.grayFg(date)
|
||||
editedBy = styles.midGrayFg(editedBy)
|
||||
separator = styles.brightGrayFg(separator)
|
||||
date = grayFg(date)
|
||||
editedBy = midGrayFg(editedBy)
|
||||
separator = brightGrayFg(separator)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
204
ui/styles.go
204
ui/styles.go
|
|
@ -1,168 +1,46 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
// Colors.
|
||||
var (
|
||||
normalDim = lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}
|
||||
gray = lipgloss.AdaptiveColor{Light: "#909090", Dark: "#626262"}
|
||||
midGray = lipgloss.AdaptiveColor{Light: "#B2B2B2", Dark: "#4A4A4A"}
|
||||
darkGray = lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"}
|
||||
brightGray = lipgloss.AdaptiveColor{Light: "#847A85", Dark: "#979797"}
|
||||
dimBrightGray = lipgloss.AdaptiveColor{Light: "#C2B8C2", Dark: "#4D4D4D"}
|
||||
cream = lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}
|
||||
yellowGreen = lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"}
|
||||
fuchsia = lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"}
|
||||
dimFuchsia = lipgloss.AdaptiveColor{Light: "#F1A8FF", Dark: "#99519E"}
|
||||
dullFuchsia = lipgloss.AdaptiveColor{Dark: "#AD58B4", Light: "#F793FF"}
|
||||
dimDullFuchsia = lipgloss.AdaptiveColor{Light: "#F6C9FF", Dark: "#7B4380"}
|
||||
green = lipgloss.Color("#04B575")
|
||||
red = lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}
|
||||
semiDimGreen = lipgloss.AdaptiveColor{Light: "#35D79C", Dark: "#036B46"}
|
||||
dimGreen = lipgloss.AdaptiveColor{Light: "#72D2B0", Dark: "#0B5137"}
|
||||
)
|
||||
|
||||
// Styles contains all styles used in the UI. They are resolved from light and
|
||||
// dark color variants according to the terminal's background color, which
|
||||
// Bubble Tea reports via tea.BackgroundColorMsg. Until then, we default to
|
||||
// a dark background.
|
||||
type Styles struct {
|
||||
lightDark lipgloss.LightDarkFunc
|
||||
|
||||
fuchsia color.Color
|
||||
|
||||
dimNormalFg func(...string) string
|
||||
brightGrayFg func(...string) string
|
||||
dimBrightGrayFg func(...string) string
|
||||
grayFg func(...string) string
|
||||
midGrayFg func(...string) string
|
||||
darkGrayFg lipgloss.Style
|
||||
greenFg func(...string) string
|
||||
semiDimGreenFg func(...string) string
|
||||
dimGreenFg func(...string) string
|
||||
fuchsiaFg func(...string) string
|
||||
dimFuchsiaFg func(...string) string
|
||||
dullFuchsiaFg func(...string) string
|
||||
dimDullFuchsiaFg func(...string) string
|
||||
redFg func(...string) string
|
||||
|
||||
tabStyle lipgloss.Style
|
||||
selectedTabStyle lipgloss.Style
|
||||
errorTitleStyle lipgloss.Style
|
||||
subtleStyle lipgloss.Style
|
||||
paginationStyle lipgloss.Style
|
||||
|
||||
statusBarScrollPosStyle func(...string) string
|
||||
statusBarNoteStyle func(...string) string
|
||||
statusBarHelpStyle func(...string) string
|
||||
statusBarMessageStyle func(...string) string
|
||||
statusBarMessageScrollPosStyle func(...string) string
|
||||
statusBarMessageHelpStyle func(...string) string
|
||||
helpViewStyle func(...string) string
|
||||
lineNumberStyle func(...string) string
|
||||
|
||||
dividerDot lipgloss.Style
|
||||
dividerBar lipgloss.Style
|
||||
logoStyle lipgloss.Style
|
||||
stashSpinnerStyle lipgloss.Style
|
||||
stashInputPromptStyle lipgloss.Style
|
||||
}
|
||||
|
||||
// newStyles builds all styles for the given terminal background.
|
||||
func newStyles(isDark bool) Styles {
|
||||
s := Styles{lightDark: lipgloss.LightDark(isDark)}
|
||||
|
||||
// Colors
|
||||
normalDim := s.adaptive("#A49FA5", "#777777")
|
||||
gray := s.adaptive("#909090", "#626262")
|
||||
midGray := s.adaptive("#B2B2B2", "#4A4A4A")
|
||||
darkGray := s.adaptive("#DDDADA", "#3C3C3C")
|
||||
brightGray := s.adaptive("#847A85", "#979797")
|
||||
dimBrightGray := s.adaptive("#C2B8C2", "#4D4D4D")
|
||||
cream := s.adaptive("#FFFDF5", "#FFFDF5")
|
||||
yellowGreen := s.adaptive("#04B575", "#ECFD65")
|
||||
s.fuchsia = s.adaptive("#EE6FF8", "#EE6FF8")
|
||||
dimFuchsia := s.adaptive("#F1A8FF", "#99519E")
|
||||
dullFuchsia := s.adaptive("#F793FF", "#AD58B4")
|
||||
dimDullFuchsia := s.adaptive("#F6C9FF", "#7B4380")
|
||||
green := lipgloss.Color("#04B575")
|
||||
red := s.adaptive("#FF4672", "#ED567A")
|
||||
semiDimGreen := s.adaptive("#35D79C", "#036B46")
|
||||
dimGreen := s.adaptive("#72D2B0", "#0B5137")
|
||||
|
||||
// Pager colors
|
||||
mintGreen := s.adaptive("#89F0CB", "#89F0CB")
|
||||
darkGreen := s.adaptive("#1C8760", "#1C8760")
|
||||
lineNumberFg := s.adaptive("#656565", "#7D7D7D")
|
||||
statusBarNoteFg := s.adaptive("#656565", "#7D7D7D")
|
||||
statusBarBg := s.adaptive("#E6E6E6", "#242424")
|
||||
|
||||
// Render-func styles
|
||||
s.dimNormalFg = lipgloss.NewStyle().Foreground(normalDim).Render
|
||||
s.brightGrayFg = lipgloss.NewStyle().Foreground(brightGray).Render
|
||||
s.dimBrightGrayFg = lipgloss.NewStyle().Foreground(dimBrightGray).Render
|
||||
s.grayFg = lipgloss.NewStyle().Foreground(gray).Render
|
||||
s.midGrayFg = lipgloss.NewStyle().Foreground(midGray).Render
|
||||
s.darkGrayFg = lipgloss.NewStyle().Foreground(darkGray)
|
||||
s.greenFg = lipgloss.NewStyle().Foreground(green).Render
|
||||
s.semiDimGreenFg = lipgloss.NewStyle().Foreground(semiDimGreen).Render
|
||||
s.dimGreenFg = lipgloss.NewStyle().Foreground(dimGreen).Render
|
||||
s.fuchsiaFg = lipgloss.NewStyle().Foreground(s.fuchsia).Render
|
||||
s.dimFuchsiaFg = lipgloss.NewStyle().Foreground(dimFuchsia).Render
|
||||
s.dullFuchsiaFg = lipgloss.NewStyle().Foreground(dullFuchsia).Render
|
||||
s.dimDullFuchsiaFg = lipgloss.NewStyle().Foreground(dimDullFuchsia).Render
|
||||
s.redFg = lipgloss.NewStyle().Foreground(red).Render
|
||||
|
||||
// Named styles
|
||||
s.tabStyle = lipgloss.NewStyle().Foreground(s.adaptive("#909090", "#626262"))
|
||||
s.selectedTabStyle = lipgloss.NewStyle().Foreground(s.adaptive("#333333", "#979797"))
|
||||
s.errorTitleStyle = lipgloss.NewStyle().Foreground(cream).Background(red).Padding(0, 1)
|
||||
s.subtleStyle = lipgloss.NewStyle().Foreground(s.adaptive("#9B9B9B", "#5C5C5C"))
|
||||
s.paginationStyle = s.subtleStyle
|
||||
|
||||
// Pager styles
|
||||
s.statusBarScrollPosStyle = lipgloss.NewStyle().
|
||||
Foreground(s.adaptive("#949494", "#5A5A5A")).
|
||||
Background(statusBarBg).
|
||||
Render
|
||||
|
||||
s.statusBarNoteStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(statusBarBg).
|
||||
Render
|
||||
|
||||
s.statusBarHelpStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(s.adaptive("#DCDCDC", "#323232")).
|
||||
Render
|
||||
|
||||
s.statusBarMessageStyle = lipgloss.NewStyle().
|
||||
Foreground(mintGreen).
|
||||
Background(darkGreen).
|
||||
Render
|
||||
|
||||
s.statusBarMessageScrollPosStyle = lipgloss.NewStyle().
|
||||
Foreground(mintGreen).
|
||||
Background(darkGreen).
|
||||
Render
|
||||
|
||||
s.statusBarMessageHelpStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#B6FFE4")).
|
||||
Background(green).
|
||||
Render
|
||||
|
||||
s.helpViewStyle = lipgloss.NewStyle().
|
||||
Foreground(statusBarNoteFg).
|
||||
Background(s.adaptive("#f2f2f2", "#1B1B1B")).
|
||||
Render
|
||||
|
||||
s.lineNumberStyle = lipgloss.NewStyle().
|
||||
Foreground(lineNumberFg).
|
||||
Render
|
||||
|
||||
// Stash styles
|
||||
s.dividerDot = s.darkGrayFg.SetString(" • ")
|
||||
s.dividerBar = s.darkGrayFg.SetString(" │ ")
|
||||
|
||||
s.logoStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#ECFD65")).
|
||||
Background(s.fuchsia).
|
||||
Bold(true)
|
||||
|
||||
s.stashSpinnerStyle = lipgloss.NewStyle().
|
||||
Foreground(gray)
|
||||
s.stashInputPromptStyle = lipgloss.NewStyle().
|
||||
Foreground(yellowGreen).
|
||||
MarginRight(1)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// adaptive returns a color appropriate for the current terminal background.
|
||||
func (s Styles) adaptive(light, dark string) color.Color {
|
||||
return s.lightDark(lipgloss.Color(light), lipgloss.Color(dark))
|
||||
}
|
||||
// Ulimately, we'll transition to named styles.
|
||||
var (
|
||||
dimNormalFg = lipgloss.NewStyle().Foreground(normalDim).Render
|
||||
brightGrayFg = lipgloss.NewStyle().Foreground(brightGray).Render
|
||||
dimBrightGrayFg = lipgloss.NewStyle().Foreground(dimBrightGray).Render
|
||||
grayFg = lipgloss.NewStyle().Foreground(gray).Render
|
||||
midGrayFg = lipgloss.NewStyle().Foreground(midGray).Render
|
||||
darkGrayFg = lipgloss.NewStyle().Foreground(darkGray)
|
||||
greenFg = lipgloss.NewStyle().Foreground(green).Render
|
||||
semiDimGreenFg = lipgloss.NewStyle().Foreground(semiDimGreen).Render
|
||||
dimGreenFg = lipgloss.NewStyle().Foreground(dimGreen).Render
|
||||
fuchsiaFg = lipgloss.NewStyle().Foreground(fuchsia).Render
|
||||
dimFuchsiaFg = lipgloss.NewStyle().Foreground(dimFuchsia).Render
|
||||
dullFuchsiaFg = lipgloss.NewStyle().Foreground(dullFuchsia).Render
|
||||
dimDullFuchsiaFg = lipgloss.NewStyle().Foreground(dimDullFuchsia).Render
|
||||
redFg = lipgloss.NewStyle().Foreground(red).Render
|
||||
tabStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#909090", Dark: "#626262"})
|
||||
selectedTabStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#333333", Dark: "#979797"})
|
||||
errorTitleStyle = lipgloss.NewStyle().Foreground(cream).Background(red).Padding(0, 1)
|
||||
subtleStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"})
|
||||
paginationStyle = subtleStyle
|
||||
)
|
||||
|
|
|
|||
114
ui/ui.go
114
ui/ui.go
|
|
@ -8,10 +8,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/glow/v3/utils"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/glamour/styles"
|
||||
"github.com/charmbracelet/glow/v2/utils"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/muesli/gitcha"
|
||||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -19,35 +21,31 @@ const (
|
|||
ellipsis = "…"
|
||||
)
|
||||
|
||||
var markdownExtensions = []string{
|
||||
"*.md", "*.mdown", "*.mkdn", "*.mkd", "*.markdown",
|
||||
}
|
||||
var (
|
||||
config Config
|
||||
|
||||
// NewProgram returns a new Tea program. The returned cleanup function
|
||||
// restores the terminal state and must be called after the program exits.
|
||||
func NewProgram(cfg Config, content string) (*tea.Program, func()) {
|
||||
markdownExtensions = []string{
|
||||
"*.md", "*.mdown", "*.mkdn", "*.mkd", "*.markdown",
|
||||
}
|
||||
)
|
||||
|
||||
// NewProgram returns a new Tea program.
|
||||
func NewProgram(cfg Config, content string) *tea.Program {
|
||||
log.Debug(
|
||||
"Starting glow",
|
||||
"high_perf_pager",
|
||||
cfg.HighPerformancePager,
|
||||
"glamour",
|
||||
cfg.GlamourEnabled,
|
||||
)
|
||||
|
||||
m := newModel(cfg, content)
|
||||
|
||||
if utils.TextSizingEnabled() {
|
||||
if tty, state, err := openRawTerminal(); err == nil {
|
||||
painter := newRawPainter(os.Stdout, tty, state, cfg.EnableMouse)
|
||||
prog := tea.NewProgram(
|
||||
paintModel{inner: m, painter: painter},
|
||||
tea.WithoutRenderer(),
|
||||
tea.WithInput(tty),
|
||||
)
|
||||
painter.watchResize(prog)
|
||||
return prog, painter.stop
|
||||
}
|
||||
config = cfg
|
||||
opts := []tea.ProgramOption{tea.WithAltScreen()}
|
||||
if cfg.EnableMouse {
|
||||
opts = append(opts, tea.WithMouseCellMotion())
|
||||
}
|
||||
|
||||
return tea.NewProgram(m), func() {}
|
||||
m := newModel(cfg, content)
|
||||
return tea.NewProgram(m, opts...)
|
||||
}
|
||||
|
||||
type errMsg struct{ err error }
|
||||
|
|
@ -97,7 +95,6 @@ type commonModel struct {
|
|||
cwd string
|
||||
width int
|
||||
height int
|
||||
styles Styles
|
||||
}
|
||||
|
||||
type model struct {
|
||||
|
|
@ -123,6 +120,10 @@ func (m *model) unloadDocument() []tea.Cmd {
|
|||
m.pager.showHelp = false
|
||||
|
||||
var batch []tea.Cmd
|
||||
if m.pager.viewport.HighPerformanceRendering {
|
||||
batch = append(batch, tea.ClearScrollArea) //nolint:staticcheck
|
||||
}
|
||||
|
||||
if !m.stash.shouldSpin() {
|
||||
batch = append(batch, m.stash.spinner.Tick)
|
||||
}
|
||||
|
|
@ -130,9 +131,18 @@ func (m *model) unloadDocument() []tea.Cmd {
|
|||
}
|
||||
|
||||
func newModel(cfg Config, content string) tea.Model {
|
||||
initSections()
|
||||
|
||||
if cfg.GlamourStyle == styles.AutoStyle {
|
||||
if te.HasDarkBackground() {
|
||||
cfg.GlamourStyle = styles.DarkStyle
|
||||
} else {
|
||||
cfg.GlamourStyle = styles.LightStyle
|
||||
}
|
||||
}
|
||||
|
||||
common := commonModel{
|
||||
cfg: cfg,
|
||||
styles: newStyles(true),
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
m := model{
|
||||
|
|
@ -168,26 +178,25 @@ func newModel(cfg Config, content string) tea.Model {
|
|||
Note: stripAbsolutePath(path, cwd),
|
||||
Modtime: info.ModTime(),
|
||||
}
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Error("unable to read file", "file", path, "error", err)
|
||||
m.fatalErr = err
|
||||
return m
|
||||
}
|
||||
m.pager.currentDocument.Body = string(utils.RemoveFrontmatter(content))
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
cmds := []tea.Cmd{m.stash.spinner.Tick, tea.RequestBackgroundColor}
|
||||
cmds := []tea.Cmd{m.stash.spinner.Tick}
|
||||
|
||||
switch m.state {
|
||||
case stateShowStash:
|
||||
cmds = append(cmds, findLocalFiles(*m.common))
|
||||
case stateShowDocument:
|
||||
cmds = append(cmds, renderWithGlamour(m.pager, m.pager.currentDocument.Body))
|
||||
content, err := os.ReadFile(m.common.cfg.Path)
|
||||
if err != nil {
|
||||
log.Error("unable to read file", "file", m.common.cfg.Path, "error", err)
|
||||
return func() tea.Msg { return errMsg{err} }
|
||||
}
|
||||
body := string(utils.RemoveFrontmatter(content))
|
||||
cmds = append(cmds, renderWithGlamour(m.pager, body))
|
||||
}
|
||||
|
||||
return tea.Batch(cmds...)
|
||||
|
|
@ -196,7 +205,7 @@ func (m model) Init() tea.Cmd {
|
|||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// If there's been an error, any key exits
|
||||
if m.fatalErr != nil {
|
||||
if _, ok := msg.(tea.KeyPressMsg); ok {
|
||||
if _, ok := msg.(tea.KeyMsg); ok {
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
|
@ -204,10 +213,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
var cmds []tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.BackgroundColorMsg:
|
||||
m.common.styles = newStyles(msg.IsDark())
|
||||
m.stash.stylePaginators(m.common.styles)
|
||||
case tea.KeyPressMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
if m.state == stateShowDocument || m.stash.viewState == stashStateLoadingDocument {
|
||||
|
|
@ -318,26 +324,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func (m model) View() tea.View {
|
||||
var content string
|
||||
switch {
|
||||
case m.fatalErr != nil:
|
||||
content = errorView(m.common.styles, m.fatalErr, true)
|
||||
case m.state == stateShowDocument:
|
||||
content = m.pager.View()
|
||||
default:
|
||||
content = m.stash.view()
|
||||
func (m model) View() string {
|
||||
if m.fatalErr != nil {
|
||||
return errorView(m.fatalErr, true)
|
||||
}
|
||||
|
||||
v := tea.NewView(content)
|
||||
v.AltScreen = true
|
||||
if m.common.cfg.EnableMouse {
|
||||
v.MouseMode = tea.MouseModeCellMotion
|
||||
switch m.state { //nolint:exhaustive
|
||||
case stateShowDocument:
|
||||
return m.pager.View()
|
||||
default:
|
||||
return m.stash.view()
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func errorView(styles Styles, err error, fatal bool) string {
|
||||
func errorView(err error, fatal bool) string {
|
||||
exitMsg := "press any key to "
|
||||
if fatal {
|
||||
exitMsg += "exit"
|
||||
|
|
@ -345,9 +345,9 @@ func errorView(styles Styles, err error, fatal bool) string {
|
|||
exitMsg += "return"
|
||||
}
|
||||
s := fmt.Sprintf("%s\n\n%v\n\n%s",
|
||||
styles.errorTitleStyle.Render("ERROR"),
|
||||
errorTitleStyle.Render("ERROR"),
|
||||
err,
|
||||
styles.subtleStyle.Render(exitMsg),
|
||||
subtleStyle.Render(exitMsg),
|
||||
)
|
||||
return "\n" + indent(s, 3)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewModelLoadsDocumentBody(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "test.md")
|
||||
if err := os.WriteFile(path, []byte("# Hello\n\nSome text here.\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
m := newModel(Config{Path: path}, "").(model)
|
||||
if m.state != stateShowDocument {
|
||||
t.Fatalf("expected stateShowDocument, got %s", m.state)
|
||||
}
|
||||
if !strings.Contains(m.pager.currentDocument.Body, "Some text") {
|
||||
t.Errorf("expected document body to be loaded, got %q", m.pager.currentDocument.Body)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,393 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"charm.land/glamour/v2/ansi"
|
||||
"github.com/muesli/cancelreader"
|
||||
"github.com/rivo/uniseg"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const (
|
||||
osc66ST = "\x1b\\"
|
||||
osc66MaxPayload = 4000
|
||||
|
||||
markerPrefix = "\x1b]6666;"
|
||||
markerClose = markerPrefix + "0" + osc66ST
|
||||
)
|
||||
|
||||
var textSizingEnabled = sync.OnceValue(detectTextSizing)
|
||||
|
||||
// TextSizingEnabled reports whether the terminal supports kitty's text
|
||||
// sizing protocol (OSC 66), auto-detecting support on first call and caching
|
||||
// the result. Set GLOW_TEXT_SIZING to on/off to override detection.
|
||||
func TextSizingEnabled() bool {
|
||||
return textSizingEnabled()
|
||||
}
|
||||
|
||||
func detectTextSizing() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("GLOW_TEXT_SIZING"))) {
|
||||
case "0", "false", "off", "no":
|
||||
return false
|
||||
case "1", "true", "on", "yes":
|
||||
return true
|
||||
}
|
||||
|
||||
if !term.IsTerminal(int(os.Stdout.Fd())) {
|
||||
return false
|
||||
}
|
||||
if termEnv := os.Getenv("TERM"); termEnv == "" || termEnv == "dumb" {
|
||||
return false
|
||||
}
|
||||
|
||||
if supported, decisive := probeTextSizing(); decisive {
|
||||
return supported
|
||||
}
|
||||
|
||||
return os.Getenv("KITTY_WINDOW_ID") != "" ||
|
||||
os.Getenv("TERM_PROGRAM") == "kitty" ||
|
||||
strings.Contains(os.Getenv("TERM"), "kitty")
|
||||
}
|
||||
|
||||
var cprPattern = regexp.MustCompile(`\x1b\[(\d+);(\d+)R`)
|
||||
|
||||
func probeTextSizing() (supported, decisive bool) {
|
||||
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
defer func() { _ = tty.Close() }()
|
||||
|
||||
fd := int(tty.Fd())
|
||||
oldState, err := term.MakeRaw(fd)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
defer func() { _ = term.Restore(fd, oldState) }()
|
||||
|
||||
reader, err := cancelreader.NewReader(tty)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
defer func() { _ = reader.Close() }()
|
||||
|
||||
if _, err := io.WriteString(tty, "\r\x1b[6n\x1b]66;w=2; \a\x1b[6n\r"); err != nil {
|
||||
return false, false
|
||||
}
|
||||
|
||||
timer := time.AfterFunc(800*time.Millisecond, func() { reader.Cancel() })
|
||||
defer timer.Stop()
|
||||
|
||||
var buf []byte
|
||||
tmp := make([]byte, 128)
|
||||
nextCol := func() (int, bool) {
|
||||
for {
|
||||
if loc := cprPattern.FindSubmatchIndex(buf); loc != nil {
|
||||
col, _ := strconv.Atoi(string(buf[loc[4]:loc[5]]))
|
||||
buf = buf[loc[1]:]
|
||||
return col, true
|
||||
}
|
||||
n, rerr := reader.Read(tmp)
|
||||
if n > 0 {
|
||||
buf = append(buf, tmp[:n]...)
|
||||
}
|
||||
if rerr != nil {
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
before, ok := nextCol()
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
after, ok := nextCol()
|
||||
if !ok {
|
||||
return false, true
|
||||
}
|
||||
return after-before == 2, true
|
||||
}
|
||||
|
||||
func markerOpen(level int) string {
|
||||
return markerPrefix + strconv.Itoa(level) + osc66ST
|
||||
}
|
||||
|
||||
func markerLevel(s string) int {
|
||||
if !strings.HasPrefix(s, markerPrefix) {
|
||||
return -1
|
||||
}
|
||||
rest := s[len(markerPrefix):]
|
||||
if len(rest) < 1+len(osc66ST) || rest[0] < '0' || rest[0] > '9' || !strings.HasPrefix(rest[1:], osc66ST) {
|
||||
return -1
|
||||
}
|
||||
return int(rest[0] - '0')
|
||||
}
|
||||
|
||||
// AddHeadingSizeMarkers marks the heading styles of levels 1 to 3 in the
|
||||
// given style config so that ApplyTextSizing can find the rendered heading
|
||||
// text and scale it. Headings with a background color are left unmarked:
|
||||
// the background does not cover the scaled glyphs and renders broken.
|
||||
// The style config is modified in place; pass a copy if the original is
|
||||
// shared.
|
||||
func AddHeadingSizeMarkers(cfg *ansi.StyleConfig) {
|
||||
blocks := []struct {
|
||||
level int
|
||||
block *ansi.StyleBlock
|
||||
}{
|
||||
{1, &cfg.H1},
|
||||
{2, &cfg.H2},
|
||||
{3, &cfg.H3},
|
||||
}
|
||||
for _, b := range blocks {
|
||||
if b.block.BackgroundColor != nil {
|
||||
continue
|
||||
}
|
||||
prefix := b.block.Prefix
|
||||
if strings.HasPrefix(prefix, "#") {
|
||||
prefix = strings.TrimPrefix(strings.TrimLeft(prefix, "#"), " ")
|
||||
}
|
||||
b.block.Prefix = markerOpen(b.level) + prefix
|
||||
b.block.Suffix += markerClose
|
||||
}
|
||||
}
|
||||
|
||||
func headingRows(level int) int {
|
||||
if level == 1 {
|
||||
return 3
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
// ApplyTextSizing replaces the heading markers inserted by
|
||||
// AddHeadingSizeMarkers with kitty text sizing (OSC 66) sequences: level 1
|
||||
// headings are scaled 3x, level 2 headings 2x, and level 3 headings 1.5x via
|
||||
// fractional scaling with a tight width so glyphs keep their natural width.
|
||||
// Output without markers is returned unchanged.
|
||||
func ApplyTextSizing(s string) string {
|
||||
if !strings.Contains(s, markerPrefix) {
|
||||
return s
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
b.Grow(len(s))
|
||||
for len(s) > 0 {
|
||||
i := strings.Index(s, markerPrefix)
|
||||
if i < 0 {
|
||||
b.WriteString(s)
|
||||
break
|
||||
}
|
||||
b.WriteString(s[:i])
|
||||
s = s[i:]
|
||||
|
||||
level := markerLevel(s)
|
||||
if level < 0 {
|
||||
b.WriteString(markerPrefix)
|
||||
s = s[len(markerPrefix):]
|
||||
continue
|
||||
}
|
||||
s = s[len(markerOpen(level)):]
|
||||
if level < 1 || level > 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
end := strings.Index(s, markerClose)
|
||||
if end < 0 {
|
||||
b.WriteString(s)
|
||||
break
|
||||
}
|
||||
writeSizedSpan(&b, level, s[:end])
|
||||
s = s[end+len(markerClose):]
|
||||
b.WriteString(strings.Repeat("\n", headingRows(level)-1))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func writeSizedSpan(b *strings.Builder, level int, span string) {
|
||||
lines := strings.Split(span, "\n")
|
||||
for i, ln := range lines {
|
||||
if i > 0 {
|
||||
b.WriteString(strings.Repeat("\n", headingRows(level)))
|
||||
}
|
||||
writeSizedLine(b, level, ln, i > 0)
|
||||
}
|
||||
}
|
||||
|
||||
type segment struct {
|
||||
escape bool
|
||||
value string
|
||||
}
|
||||
|
||||
func writeSizedLine(b *strings.Builder, level int, ln string, continuation bool) {
|
||||
var segs []segment
|
||||
for len(ln) > 0 {
|
||||
i := strings.IndexByte(ln, '\x1b')
|
||||
if i < 0 {
|
||||
segs = append(segs, segment{value: ln})
|
||||
break
|
||||
}
|
||||
if i > 0 {
|
||||
segs = append(segs, segment{value: ln[:i]})
|
||||
ln = ln[i:]
|
||||
continue
|
||||
}
|
||||
seq := scanEscape(ln)
|
||||
segs = append(segs, segment{escape: true, value: seq})
|
||||
ln = ln[len(seq):]
|
||||
}
|
||||
|
||||
firstContent, lastContent := -1, -1
|
||||
for i, sg := range segs {
|
||||
if !sg.escape && strings.Trim(sg.value, " \t") != "" {
|
||||
if firstContent < 0 {
|
||||
firstContent = i
|
||||
}
|
||||
lastContent = i
|
||||
}
|
||||
}
|
||||
|
||||
for i, sg := range segs {
|
||||
if sg.escape || firstContent < 0 {
|
||||
b.WriteString(sg.value)
|
||||
continue
|
||||
}
|
||||
text := sg.value
|
||||
switch {
|
||||
case i < firstContent && continuation:
|
||||
b.WriteString(text)
|
||||
continue
|
||||
case i > lastContent:
|
||||
b.WriteString(text)
|
||||
continue
|
||||
}
|
||||
if i == firstContent && continuation {
|
||||
trimmed := strings.TrimLeft(text, " \t")
|
||||
b.WriteString(text[:len(text)-len(trimmed)])
|
||||
text = trimmed
|
||||
}
|
||||
var trail string
|
||||
if i == lastContent {
|
||||
trimmed := strings.TrimRight(text, " \t")
|
||||
trail = text[len(trimmed):]
|
||||
text = trimmed
|
||||
}
|
||||
if text != "" {
|
||||
b.WriteString(sizedChunk(level, text))
|
||||
}
|
||||
b.WriteString(trail)
|
||||
}
|
||||
}
|
||||
|
||||
func scanEscape(s string) string {
|
||||
if len(s) < 2 {
|
||||
return s
|
||||
}
|
||||
switch s[1] {
|
||||
case '[':
|
||||
for i := 2; i < len(s); i++ {
|
||||
if s[i] >= 0x40 && s[i] <= 0x7e {
|
||||
return s[:i+1]
|
||||
}
|
||||
}
|
||||
return s
|
||||
case ']':
|
||||
for i := 2; i < len(s); i++ {
|
||||
if s[i] == '\a' {
|
||||
return s[:i+1]
|
||||
}
|
||||
if s[i] == '\x1b' && i+1 < len(s) && s[i+1] == '\\' {
|
||||
return s[:i+2]
|
||||
}
|
||||
}
|
||||
return s
|
||||
default:
|
||||
i := 1
|
||||
for i < len(s) && s[i] >= 0x20 && s[i] <= 0x2f {
|
||||
i++
|
||||
}
|
||||
if i < len(s) {
|
||||
i++
|
||||
}
|
||||
return s[:i]
|
||||
}
|
||||
}
|
||||
|
||||
func sizedChunk(level int, text string) string {
|
||||
text = strings.Map(func(r rune) rune {
|
||||
if r < 0x20 || (r >= 0x7f && r <= 0x9f) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, text)
|
||||
if text == "" {
|
||||
return ""
|
||||
}
|
||||
switch level {
|
||||
case 1:
|
||||
return osc66Chunks("s=3", text)
|
||||
case 2:
|
||||
return osc66Chunks("s=2", text)
|
||||
default:
|
||||
return osc66TightChunks(text)
|
||||
}
|
||||
}
|
||||
|
||||
func osc66Chunks(meta, text string) string {
|
||||
var b strings.Builder
|
||||
var chunk strings.Builder
|
||||
g := uniseg.NewGraphemes(text)
|
||||
for g.Next() {
|
||||
cluster := g.Str()
|
||||
if chunk.Len() > 0 && chunk.Len()+len(cluster) > osc66MaxPayload {
|
||||
writeOSC66(&b, meta, chunk.String())
|
||||
chunk.Reset()
|
||||
}
|
||||
chunk.WriteString(cluster)
|
||||
}
|
||||
if chunk.Len() > 0 {
|
||||
writeOSC66(&b, meta, chunk.String())
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func osc66TightChunks(text string) string {
|
||||
var b strings.Builder
|
||||
var chunk strings.Builder
|
||||
width := 0
|
||||
flush := func() {
|
||||
if chunk.Len() == 0 {
|
||||
return
|
||||
}
|
||||
w := (width*3 + 3) / 4
|
||||
writeOSC66(&b, fmt.Sprintf("s=2:n=3:d=4:w=%d", w), chunk.String())
|
||||
chunk.Reset()
|
||||
width = 0
|
||||
}
|
||||
g := uniseg.NewGraphemes(text)
|
||||
for g.Next() {
|
||||
cluster := g.Str()
|
||||
cw := uniseg.StringWidth(cluster)
|
||||
if width > 0 && width+cw > 4 {
|
||||
flush()
|
||||
}
|
||||
chunk.WriteString(cluster)
|
||||
width += cw
|
||||
}
|
||||
flush()
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func writeOSC66(b *strings.Builder, meta, text string) {
|
||||
b.WriteString("\x1b]66;")
|
||||
b.WriteString(meta)
|
||||
b.WriteByte(';')
|
||||
b.WriteString(text)
|
||||
b.WriteString(osc66ST)
|
||||
}
|
||||
|
|
@ -1,222 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"charm.land/glamour/v2"
|
||||
"charm.land/glamour/v2/styles"
|
||||
)
|
||||
|
||||
func renderPlainAndSized(t *testing.T, markdown string, wordWrap int) (string, string) {
|
||||
t.Helper()
|
||||
|
||||
cfg := styles.DarkStyleConfig
|
||||
// Headings with a background are not scaled, so drop the dark style's
|
||||
// H1 background to exercise H1 scaling.
|
||||
cfg.H1.BackgroundColor = nil
|
||||
|
||||
r, err := glamour.NewTermRenderer(
|
||||
glamour.WithStyles(cfg),
|
||||
glamour.WithWordWrap(wordWrap),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plain, err := r.Render(markdown)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
AddHeadingSizeMarkers(&cfg)
|
||||
r, err = glamour.NewTermRenderer(
|
||||
glamour.WithStyles(cfg),
|
||||
glamour.WithWordWrap(wordWrap),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
marked, err := r.Render(markdown)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(marked, markerPrefix) {
|
||||
t.Fatal("rendered output does not contain heading markers")
|
||||
}
|
||||
|
||||
return plain, ApplyTextSizing(marked)
|
||||
}
|
||||
|
||||
func TestAddHeadingSizeMarkersSkipsBackground(t *testing.T) {
|
||||
cfg := styles.DarkStyleConfig
|
||||
AddHeadingSizeMarkers(&cfg)
|
||||
|
||||
if strings.Contains(cfg.H1.Prefix, markerPrefix) || strings.Contains(cfg.H1.Suffix, markerPrefix) {
|
||||
t.Errorf("expected H1 with background color to be left unmarked, got %q/%q", cfg.H1.Prefix, cfg.H1.Suffix)
|
||||
}
|
||||
if !strings.HasPrefix(cfg.H2.Prefix, markerOpen(2)) {
|
||||
t.Errorf("expected H2 to be marked, got %q", cfg.H2.Prefix)
|
||||
}
|
||||
if !strings.HasPrefix(cfg.H3.Prefix, markerOpen(3)) {
|
||||
t.Errorf("expected H3 to be marked, got %q", cfg.H3.Prefix)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingPassthrough(t *testing.T) {
|
||||
in := "hello \x1b[1mworld\x1b[0m"
|
||||
if got := ApplyTextSizing(in); got != in {
|
||||
t.Errorf("expected output unchanged, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingMalformedMarker(t *testing.T) {
|
||||
in := "a" + markerPrefix // truncated marker at end of string
|
||||
if got := ApplyTextSizing(in); got != in {
|
||||
t.Errorf("expected malformed marker preserved verbatim, got %q", got)
|
||||
}
|
||||
in = "a" + markerPrefix + "x" // non-digit level
|
||||
if got := ApplyTextSizing(in); got != in {
|
||||
t.Errorf("expected malformed marker preserved verbatim, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingLevels(t *testing.T) {
|
||||
_, sized := renderPlainAndSized(t, "# Hello\n\n## World\n\n### Third\n", 80)
|
||||
|
||||
if !strings.Contains(sized, "\x1b]66;s=3;Hello\x1b\\") {
|
||||
t.Errorf("expected H1 text at 3x scale, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=3; \x1b\\") {
|
||||
t.Errorf("expected H1 prefix space at 3x scale, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=2;World\x1b\\") {
|
||||
t.Errorf("expected H2 text at 2x scale, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=2:n=3:d=4:w=3;Thir\x1b\\") {
|
||||
t.Errorf("expected H3 chunks at tight 1.5x scale, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=2:n=3:d=4:w=1;d\x1b\\") {
|
||||
t.Errorf("expected H3 remainder chunk at tight 1.5x scale, got %q", sized)
|
||||
}
|
||||
if strings.Contains(sized, markerPrefix) {
|
||||
t.Errorf("expected all markers to be replaced, got %q", sized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingCompensationLines(t *testing.T) {
|
||||
plain, sized := renderPlainAndSized(t, "# Hello\n\n## World\n\n### Third\n\nparagraph\n", 80)
|
||||
|
||||
if diff := strings.Count(sized, "\n") - strings.Count(plain, "\n"); diff != 4 {
|
||||
t.Errorf("expected 4 extra newlines (2 for H1, 1 each for H2/H3), got %d", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingWrappedHeading(t *testing.T) {
|
||||
plain, sized := renderPlainAndSized(t, "# aaa bbb ccc\n\npara\n", 8)
|
||||
|
||||
plainLines := strings.Split(plain, "\n")
|
||||
sizedLines := strings.Split(sized, "\n")
|
||||
|
||||
plainHead := lineIndex(t, plainLines, "aaa")
|
||||
plainPara := lineIndex(t, plainLines, "para")
|
||||
sizedHead := lineIndex(t, sizedLines, "aaa")
|
||||
sizedPara := lineIndex(t, sizedLines, "para")
|
||||
|
||||
headLines := plainPara - plainHead - 1
|
||||
if headLines < 2 {
|
||||
t.Fatalf("expected heading to wrap, got %d line(s)", headLines)
|
||||
}
|
||||
if got, want := sizedPara-sizedHead, headLines*3+1; got != want {
|
||||
t.Errorf("expected wrapped heading to occupy %d rows, got %d", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTextSizingNestedStyles(t *testing.T) {
|
||||
_, sized := renderPlainAndSized(t, "# Hello *World*\n", 80)
|
||||
|
||||
if !strings.Contains(sized, "\x1b]66;s=3;Hello \x1b\\") {
|
||||
t.Errorf("expected first chunk at 3x scale, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=3;World\x1b\\") {
|
||||
t.Errorf("expected emphasized chunk at 3x scale, got %q", sized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectTextSizingEnvOverride(t *testing.T) {
|
||||
t.Setenv("GLOW_TEXT_SIZING", "off")
|
||||
if detectTextSizing() {
|
||||
t.Error("expected detection to be disabled")
|
||||
}
|
||||
t.Setenv("GLOW_TEXT_SIZING", "on")
|
||||
if !detectTextSizing() {
|
||||
t.Error("expected detection to be forced on")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlamourStyleTextSizing(t *testing.T) {
|
||||
render := func(t *testing.T) string {
|
||||
t.Helper()
|
||||
r, err := glamour.NewTermRenderer(
|
||||
GlamourStyle(styles.DarkStyle, false),
|
||||
glamour.WithWordWrap(80),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err := r.Render("# Hello\n\n## World\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
textSizingEnabled = sync.OnceValue(detectTextSizing)
|
||||
t.Setenv("GLOW_TEXT_SIZING", "off")
|
||||
if out := render(t); strings.Contains(out, markerPrefix) {
|
||||
t.Errorf("expected no heading markers when disabled, got %q", out)
|
||||
}
|
||||
|
||||
textSizingEnabled = sync.OnceValue(detectTextSizing)
|
||||
t.Setenv("GLOW_TEXT_SIZING", "on")
|
||||
out := render(t)
|
||||
if strings.Contains(out, markerOpen(1)) {
|
||||
t.Errorf("expected no H1 markers (background color), got %q", out)
|
||||
}
|
||||
if !strings.Contains(out, markerOpen(2)) {
|
||||
t.Errorf("expected H2 markers when enabled, got %q", out)
|
||||
}
|
||||
sized := ApplyTextSizing(out)
|
||||
if strings.Contains(sized, "\x1b]66;s=3;") {
|
||||
t.Errorf("expected no 3x scaling for H1, got %q", sized)
|
||||
}
|
||||
if !strings.Contains(sized, "\x1b]66;s=2;") {
|
||||
t.Errorf("expected OSC 66 sequences after ApplyTextSizing, got %q", sized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanEscape(t *testing.T) {
|
||||
tt := []struct{ in, want string }{
|
||||
{"\x1b[1;31mfoo", "\x1b[1;31m"},
|
||||
{"\x1b[0m", "\x1b[0m"},
|
||||
{"\x1b]66;s=2;hi\a rest", "\x1b]66;s=2;hi\a"},
|
||||
{"\x1b]6666;1\x1b\\x", "\x1b]6666;1\x1b\\"},
|
||||
{"\x1b(B", "\x1b(B"},
|
||||
}
|
||||
for _, tc := range tt {
|
||||
if got := scanEscape(tc.in); got != tc.want {
|
||||
t.Errorf("scanEscape(%q) = %q, want %q", tc.in, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func lineIndex(t *testing.T, lines []string, substr string) int {
|
||||
t.Helper()
|
||||
for i, ln := range lines {
|
||||
if strings.Contains(ln, substr) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
t.Fatalf("no line contains %q", substr)
|
||||
return -1
|
||||
}
|
||||
|
|
@ -2,17 +2,15 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"charm.land/glamour/v2"
|
||||
"charm.land/glamour/v2/ansi"
|
||||
"charm.land/glamour/v2/styles"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/charmbracelet/glamour/ansi"
|
||||
"github.com/charmbracelet/glamour/styles"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
|
|
@ -73,66 +71,43 @@ func IsMarkdownFile(filename string) bool {
|
|||
|
||||
// GlamourStyle returns a glamour.TermRendererOption based on the given style.
|
||||
func GlamourStyle(style string, isCode bool) glamour.TermRendererOption {
|
||||
return func(tr *glamour.TermRenderer) error {
|
||||
styleConfig, err := styleConfigFor(style, isCode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isCode && TextSizingEnabled() {
|
||||
AddHeadingSizeMarkers(&styleConfig)
|
||||
}
|
||||
if err := glamour.WithStyles(styleConfig)(tr); err != nil {
|
||||
return fmt.Errorf("glamour: error applying styles: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func styleConfigFor(style string, isCode bool) (ansi.StyleConfig, error) {
|
||||
if !isCode {
|
||||
if style == "auto" {
|
||||
style = styles.DarkStyle
|
||||
if style == styles.AutoStyle {
|
||||
return glamour.WithAutoStyle()
|
||||
}
|
||||
if cfg, ok := styles.DefaultStyles[style]; ok {
|
||||
return *cfg, nil
|
||||
}
|
||||
return styleConfigFromFile(style)
|
||||
return glamour.WithStylePath(style)
|
||||
}
|
||||
|
||||
// If we are rendering a pure code block, we need to modify the style to
|
||||
// remove the indentation.
|
||||
switch style {
|
||||
case "auto":
|
||||
if lipgloss.HasDarkBackground(os.Stdin, os.Stdout) {
|
||||
style = styles.DarkStyle
|
||||
} else {
|
||||
style = styles.LightStyle
|
||||
}
|
||||
case styles.TokyoNightStyle:
|
||||
style = styles.DraculaStyle
|
||||
case styles.DarkStyle, styles.LightStyle, styles.PinkStyle,
|
||||
styles.NoTTYStyle, styles.DraculaStyle:
|
||||
default:
|
||||
return styleConfigFromFile(style)
|
||||
}
|
||||
|
||||
styleConfig := *styles.DefaultStyles[style]
|
||||
var styleConfig ansi.StyleConfig
|
||||
|
||||
switch style {
|
||||
case styles.AutoStyle:
|
||||
if lipgloss.HasDarkBackground() {
|
||||
styleConfig = styles.DarkStyleConfig
|
||||
} else {
|
||||
styleConfig = styles.LightStyleConfig
|
||||
}
|
||||
case styles.DarkStyle:
|
||||
styleConfig = styles.DarkStyleConfig
|
||||
case styles.LightStyle:
|
||||
styleConfig = styles.LightStyleConfig
|
||||
case styles.PinkStyle:
|
||||
styleConfig = styles.PinkStyleConfig
|
||||
case styles.NoTTYStyle:
|
||||
styleConfig = styles.NoTTYStyleConfig
|
||||
case styles.DraculaStyle:
|
||||
styleConfig = styles.DraculaStyleConfig
|
||||
case styles.TokyoNightStyle:
|
||||
styleConfig = styles.DraculaStyleConfig
|
||||
default:
|
||||
return glamour.WithStylesFromJSONFile(style)
|
||||
}
|
||||
|
||||
var margin uint
|
||||
styleConfig.CodeBlock.Margin = &margin
|
||||
|
||||
return styleConfig, nil
|
||||
}
|
||||
|
||||
func styleConfigFromFile(path string) (ansi.StyleConfig, error) {
|
||||
jsonBytes, err := os.ReadFile(path) //nolint:gosec
|
||||
if err != nil {
|
||||
return ansi.StyleConfig{}, fmt.Errorf("glamour: error reading file: %w", err)
|
||||
}
|
||||
|
||||
var styleConfig ansi.StyleConfig
|
||||
if err := json.Unmarshal(jsonBytes, &styleConfig); err != nil {
|
||||
return ansi.StyleConfig{}, fmt.Errorf("glamour: error parsing style file: %w", err)
|
||||
}
|
||||
return styleConfig, nil
|
||||
return glamour.WithStyles(styleConfig)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue