diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index fffc154..bd84fe9 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -5,7 +5,6 @@ import ( "os" "strings" - "github.com/charmbracelet/glamour" "github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/sync" ) @@ -50,18 +49,17 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) { // print the notes header fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset) - // combine remaining fields into a single string (for markdown rendering) - var markdownNotes []string + // combine remaining fields into a single string (to support Markdown rendering) + var notesSlice []string for ; field < len(decryptedEntry); field++ { - markdownNotes = append(markdownNotes, decryptedEntry[field]) + notesSlice = append(notesSlice, decryptedEntry[field]) } - r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) - markdownNotesString, _ := r.Render(strings.Join(markdownNotes, "\n")) + joinedString := strings.Join(notesSlice, "\n") - // print markdown-rendered notes - fmt.Print(markdownNotesString) + // print notes to stdout + renderNote(&joinedString) - // break after all lines have been printed + // break after notes have been printed break } } diff --git a/src/cli/entryReaderMD.go b/src/cli/entryReaderMD.go new file mode 100644 index 0000000..a6e9d98 --- /dev/null +++ b/src/cli/entryReaderMD.go @@ -0,0 +1,18 @@ +//go:build !noMarkdown + +package cli + +import ( + "fmt" + + "github.com/charmbracelet/glamour" +) + +// renderNote renders the notes section of an entry (in Markdown) to stdout +func renderNote(note *string) { + r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) + markdownNotesString, _ := r.Render(*note) + + // print markdown-rendered notes + fmt.Print(markdownNotesString) +} diff --git a/src/cli/entryReaderMDDisabled.go b/src/cli/entryReaderMDDisabled.go new file mode 100644 index 0000000..ddad872 --- /dev/null +++ b/src/cli/entryReaderMDDisabled.go @@ -0,0 +1,12 @@ +//go:build noMarkdown + +package cli + +import ( + "fmt" +) + +// 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") +} diff --git a/wiki/MUTN/build.md b/wiki/MUTN/build.md index 05e8a46..8e7115d 100644 --- a/wiki/MUTN/build.md +++ b/wiki/MUTN/build.md @@ -8,5 +8,6 @@ CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./libmuttonserver.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) - `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) \ No newline at end of file +- `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)