From 77014cf5e38ef0e6979a3f41e0772497fe9b9cd2 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 29 Oct 2024 17:08:57 -0400 Subject: [PATCH] Add optional build tag for experimental BEAN Markdown renderer support --- go.mod | 3 +++ go.sum | 6 ++++++ src/cli/1globals.go | 2 +- src/cli/entryReader.go | 8 +++----- src/cli/entryReaderMDBEAN.go | 14 ++++++++++++++ src/cli/entryReaderMDDisabled.go | 5 +++-- .../{entryReaderMD.go => entryReaderMDGlamour.go} | 8 +++++--- wiki/build.md | 3 ++- 8 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/cli/entryReaderMDBEAN.go rename src/cli/{entryReaderMD.go => entryReaderMDGlamour.go} (68%) diff --git a/go.mod b/go.mod index 7ef1469..a6e1551 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/rwinkhart/MUTN go 1.23.2 require ( + github.com/Trojan2021/BEAN v0.0.0-20241029203751-320edbc990e8 github.com/charmbracelet/glamour v0.7.0 github.com/rwinkhart/libmutton v0.2.3 golang.org/x/term v0.25.0 @@ -13,6 +14,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/boombuler/barcode v1.0.2 // indirect + github.com/charmbracelet/x/ansi v0.4.0 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 // indirect github.com/gorilla/css v1.0.1 // indirect @@ -27,6 +29,7 @@ require ( github.com/pkg/sftp v1.13.6 // indirect github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/rwinkhart/convertroman v0.2.0 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/yuin/goldmark v1.7.8 // indirect github.com/yuin/goldmark-emoji v1.0.4 // indirect diff --git a/go.sum b/go.sum index cb453ee..7f8d570 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/Trojan2021/BEAN v0.0.0-20241029203751-320edbc990e8 h1:V4m0AESOYQ3rnklgxozXP7BSE2wqTaqVfWati1fGXAo= +github.com/Trojan2021/BEAN v0.0.0-20241029203751-320edbc990e8/go.mod h1:mgyhaOTeO5Ba8xMhE4f/E+JrHEUbk7IHKDrt2AXqAWY= 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= @@ -13,6 +15,8 @@ github.com/boombuler/barcode v1.0.2 h1:79yrbttoZrLGkL/oOI8hBrUKucwOL0oOjUgEguGMc github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng= github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps= +github.com/charmbracelet/x/ansi v0.4.0 h1:NqwHA4B23VwsDn4H3VcNX1W1tOmgnvY1NDx5tOXdnOU= +github.com/charmbracelet/x/ansi v0.4.0/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= 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= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -52,6 +56,8 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ 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/rwinkhart/convertroman v0.2.0 h1:otUm939eXT77q/Lr31mJtMwVWEw0RjEUB71gO65h9OM= +github.com/rwinkhart/convertroman v0.2.0/go.mod h1:Af6HqvX0EIM4Y3HcnNXbbRey1dLasGB7WU0+3Cowgmw= github.com/rwinkhart/libmutton v0.2.3 h1:1oreB+3VQ4g3zy0ZzfCbYvU83Nkg7UCZMaimeBN5+eE= github.com/rwinkhart/libmutton v0.2.3/go.mod h1:z3BxZ8l6osV2HQ8RZ0PjUbPnUFNEbxX59/RMrSW0iLI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/src/cli/1globals.go b/src/cli/1globals.go index 577b74d..1de251d 100644 --- a/src/cli/1globals.go +++ b/src/cli/1globals.go @@ -11,7 +11,7 @@ var ( ) const ( - MUTNVersion = "0.2.3" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1" + MUTNVersion = "0.2.E" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1" AnsiBold = "\033[1m" ansiBlackOnWhite = "\033[38;5;0;48;5;15m" diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 80acc89..ebcfca1 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -3,7 +3,6 @@ package cli import ( "fmt" "os" - "strings" "github.com/rwinkhart/libmutton/core" "github.com/rwinkhart/libmutton/sync" @@ -50,14 +49,13 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) { fmt.Println(ansiDirectoryHeader + "Notes:" + core.AnsiReset) // combine remaining fields into a single string (to support Markdown rendering) - var notesSlice []string + var noteLines []string for ; field < len(decryptedEntry); field++ { - notesSlice = append(notesSlice, decryptedEntry[field]) + noteLines = append(noteLines, decryptedEntry[field]) } - joinedString := strings.Join(notesSlice, "\n") // print notes to stdout - renderNote(&joinedString) + renderNote(noteLines) // break after notes have been printed break diff --git a/src/cli/entryReaderMDBEAN.go b/src/cli/entryReaderMDBEAN.go new file mode 100644 index 0000000..a85b00d --- /dev/null +++ b/src/cli/entryReaderMDBEAN.go @@ -0,0 +1,14 @@ +//go:build !noMarkdown && BEAN + +package cli + +import ( + "fmt" + + bean "github.com/Trojan2021/BEAN/render" +) + +// renderNote renders the notes section of an entry (in Markdown) to stdout. +func renderNote(noteLines []string) { + fmt.Println(bean.RenderMarkdown(noteLines, width)) +} diff --git a/src/cli/entryReaderMDDisabled.go b/src/cli/entryReaderMDDisabled.go index d5162ce..99b9979 100644 --- a/src/cli/entryReaderMDDisabled.go +++ b/src/cli/entryReaderMDDisabled.go @@ -4,9 +4,10 @@ package cli import ( "fmt" + "strings" ) // renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled). -func renderNote(note *string) { - fmt.Print("\n" + *note + "\n\n") +func renderNote(noteLines []string) { + fmt.Print("\n" + strings.Join(noteLines, "\n") + "\n\n") } diff --git a/src/cli/entryReaderMD.go b/src/cli/entryReaderMDGlamour.go similarity index 68% rename from src/cli/entryReaderMD.go rename to src/cli/entryReaderMDGlamour.go index 7dddb42..b14e54f 100644 --- a/src/cli/entryReaderMD.go +++ b/src/cli/entryReaderMDGlamour.go @@ -1,17 +1,19 @@ -//go:build !noMarkdown +//go:build !noMarkdown && !BEAN package cli import ( "fmt" + "strings" "github.com/charmbracelet/glamour" ) // renderNote renders the notes section of an entry (in Markdown) to stdout. -func renderNote(note *string) { +func renderNote(noteLines []string) { + note := strings.Join(noteLines, "\n") r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) - markdownNotesString, _ := r.Render(*note) + markdownNotesString, _ := r.Render(note) // print markdown-rendered notes fmt.Print(markdownNotesString) diff --git a/wiki/build.md b/wiki/build.md index 7113a34..e80f878 100644 --- a/wiki/build.md +++ b/wiki/build.md @@ -5,6 +5,7 @@ CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./mutn.go ``` Additionally, some custom build tags can be used to create different binaries. The following tags are not used in official builds: -- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time) +- `BEAN`: Creates a binary with the experimental [BEAN](https://github.com/Trojan2021/BEAN) Markdown renderer in place of Glamour +- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time VS Glamour) - `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL) - `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)