From f0bbcdea9a505eb99e8d43c5a8085df0e4b1a0a1 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Sun, 26 Nov 2023 08:54:10 -0500 Subject: [PATCH] feat(lipgloss): experiment using lipgloss to format git-bug ls --- cmd/lipgloss/main.go | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 cmd/lipgloss/main.go diff --git a/cmd/lipgloss/main.go b/cmd/lipgloss/main.go new file mode 100644 index 0000000000000000000000000000000000000000..87504837cb54e21c2b0da008ccb0f0739f458317 --- /dev/null +++ b/cmd/lipgloss/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "os" + "strings" + + "github.com/charmbracelet/lipgloss" + "github.com/muesli/reflow/truncate" + "github.com/muesli/termenv" +) + +func main() { + const ( + idText = "9f3e262" + statusText = "closed" + titleText = "Error: the repository you want to access is already locked" + labelIndicator = "◼" + authorText = "Arnaud LE CAM (arnaudlecam)" + commentText = "9" + commentIndicator = "💬" + ellipsisIndicator = "…" + ) + + const ( + cyan = termenv.ANSICyan + yellow = termenv.ANSIYellow + magenta = termenv.ANSIMagenta + gray = termenv.ANSIWhite + ) + + const ( + idLen = 7 + statusLen = len("closed") + titleLen = 50 + authorLen = 15 + commentLen = 3 + ) + + title, author := titleText, authorText + if termenv.DefaultOutput().Profile != termenv.Ascii { + title = truncate.StringWithTail(titleText, titleLen, ellipsisIndicator) + author = truncate.StringWithTail(authorText, authorLen, ellipsisIndicator) + } + + idStyle := lipgloss.NewStyle().Width(idLen).MarginRight(1).Foreground(lipgloss.ANSIColor(cyan)) + statusStyle := lipgloss.NewStyle().Width(statusLen).MarginRight(2).Foreground(lipgloss.ANSIColor(yellow)) + titleStyle := lipgloss.NewStyle().Width(titleLen).MarginRight(6).Foreground(lipgloss.ANSIColor(gray)) + authorStyle := lipgloss.NewStyle().Width(authorLen).MarginRight(1).Foreground(lipgloss.ANSIColor(magenta)) + commentStyle := lipgloss.NewStyle().Width(commentLen).MarginRight(1).Foreground(lipgloss.ANSIColor(gray)).Align(lipgloss.Right) + commentMarker := lipgloss.NewStyle().Width(2).MarginRight(1).Foreground(lipgloss.ANSIColor(gray)) + + str := strings.Join( + []string{ + idStyle.Render(idText), + statusStyle.Render(statusText), + titleStyle.Render(title), + authorStyle.Render(author), + commentStyle.Render(commentText), + commentMarker.Render(commentIndicator), + "\n", + }, "") + + os.Stderr.Write([]byte(str)) +}