main.go

  1package main
  2
  3import (
  4	"flag"
  5	"os"
  6	"strings"
  7
  8	"github.com/charmbracelet/lipgloss"
  9	"github.com/muesli/reflow/truncate"
 10	"github.com/muesli/termenv"
 11)
 12
 13func main() {
 14	const (
 15		idText            = "9f3e262"
 16		statusText        = "closed"
 17		titleText         = "Error: the repository you want to access is already locked"
 18		labelIndicator    = "◼"
 19		authorText        = "Arnaud LE CAM (arnaudlecam)"
 20		commentText       = "9"
 21		commentIndicator  = "💬"
 22		ellipsisIndicator = "…"
 23	)
 24
 25	const (
 26		cyan    = termenv.ANSICyan
 27		yellow  = termenv.ANSIYellow
 28		magenta = termenv.ANSIMagenta
 29		gray    = termenv.ANSIWhite
 30	)
 31
 32	const (
 33		idLen      = 7
 34		statusLen  = len("closed")
 35		titleLen   = 50
 36		authorLen  = 15
 37		commentLen = 3
 38	)
 39
 40	idStyle := lipgloss.NewStyle()
 41	statusStyle := lipgloss.NewStyle()
 42	titleStyle := lipgloss.NewStyle()
 43	authorStyle := lipgloss.NewStyle()
 44	commentStyle := lipgloss.NewStyle()
 45	commentMarker := lipgloss.NewStyle()
 46
 47	separator := "\t"
 48
 49	title, author := titleText, authorText
 50	if termenv.DefaultOutput().Profile != termenv.Ascii {
 51		title = truncate.StringWithTail(titleText, titleLen, ellipsisIndicator)
 52		author = truncate.StringWithTail(authorText, authorLen, ellipsisIndicator)
 53
 54		idStyle = idStyle.Width(idLen).MarginRight(1).Foreground(lipgloss.ANSIColor(cyan))
 55		statusStyle = statusStyle.Width(statusLen).MarginRight(2).Foreground(lipgloss.ANSIColor(yellow))
 56		titleStyle = titleStyle.Width(titleLen).MarginRight(6).Foreground(lipgloss.ANSIColor(gray))
 57		authorStyle = authorStyle.Width(authorLen).MarginRight(1).Foreground(lipgloss.ANSIColor(magenta))
 58		commentStyle = commentStyle.Width(commentLen).MarginRight(1).Foreground(lipgloss.ANSIColor(gray)).Align(lipgloss.Right)
 59		commentMarker = commentMarker.Width(2).MarginRight(1).Foreground(lipgloss.ANSIColor(gray))
 60
 61		separator = ""
 62	}
 63
 64	type formatFunc func() string
 65
 66	defaultFormatFunc := func() string {
 67		return strings.Join(
 68			[]string{
 69				idStyle.Render(idText),
 70				statusStyle.Render(statusText),
 71				titleStyle.Render(title),
 72				authorStyle.Render(author),
 73				commentStyle.Render(commentText),
 74				commentMarker.Render(commentIndicator),
 75				"\n",
 76			}, separator)
 77	}
 78
 79	idFormatFunc := func() string {
 80		return idStyle.Render(idText) + "\n"
 81	}
 82
 83	compactFormatFunc := func() string {
 84		return strings.Join(
 85			[]string{
 86				idStyle.Render(idText),
 87				statusStyle.Render(statusText),
 88				titleStyle.Render(title),
 89				authorStyle.Render(author),
 90				"\n",
 91			}, separator)
 92	}
 93
 94	var (
 95		_ formatFunc = defaultFormatFunc
 96		_ formatFunc = idFormatFunc
 97		_ formatFunc = compactFormatFunc
 98	)
 99
100	var format string
101
102	flag.StringVar(&format, "format", "default", "")
103	flag.Parse()
104
105	fn := defaultFormatFunc
106
107	switch format {
108	case "compact":
109		fn = compactFormatFunc
110	case "id":
111		fn = idFormatFunc
112	}
113
114	os.Stderr.Write([]byte(fn()))
115}