mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-13 12:05:02 +03:00
feat(lipgloss): adds id and compact formats
This commit is contained in:
parent
4f9d9f308c
commit
11d01a1586
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -36,31 +37,79 @@ func main() {
|
|||||||
commentLen = 3
|
commentLen = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
idStyle := lipgloss.NewStyle().Width(idLen).MarginRight(1).Foreground(lipgloss.ANSIColor(cyan))
|
idStyle := lipgloss.NewStyle()
|
||||||
statusStyle := lipgloss.NewStyle().Width(statusLen).MarginRight(2).Foreground(lipgloss.ANSIColor(yellow))
|
statusStyle := lipgloss.NewStyle()
|
||||||
titleStyle := lipgloss.NewStyle().MarginRight(6).Foreground(lipgloss.ANSIColor(gray))
|
titleStyle := lipgloss.NewStyle()
|
||||||
authorStyle := lipgloss.NewStyle().MarginRight(1).Foreground(lipgloss.ANSIColor(magenta))
|
authorStyle := lipgloss.NewStyle()
|
||||||
commentStyle := lipgloss.NewStyle().Width(commentLen).MarginRight(1).Foreground(lipgloss.ANSIColor(gray)).Align(lipgloss.Right)
|
commentStyle := lipgloss.NewStyle()
|
||||||
commentMarker := lipgloss.NewStyle().Width(2).MarginRight(1).Foreground(lipgloss.ANSIColor(gray))
|
commentMarker := lipgloss.NewStyle()
|
||||||
|
|
||||||
|
separator := "\t"
|
||||||
|
|
||||||
title, author := titleText, authorText
|
title, author := titleText, authorText
|
||||||
if termenv.DefaultOutput().Profile != termenv.Ascii {
|
if termenv.DefaultOutput().Profile != termenv.Ascii {
|
||||||
title = truncate.StringWithTail(titleText, titleLen, ellipsisIndicator)
|
title = truncate.StringWithTail(titleText, titleLen, ellipsisIndicator)
|
||||||
titleStyle = titleStyle.Width(titleLen)
|
|
||||||
author = truncate.StringWithTail(authorText, authorLen, ellipsisIndicator)
|
author = truncate.StringWithTail(authorText, authorLen, ellipsisIndicator)
|
||||||
authorStyle = authorStyle.Width(authorLen)
|
|
||||||
|
idStyle = idStyle.Width(idLen).MarginRight(1).Foreground(lipgloss.ANSIColor(cyan))
|
||||||
|
statusStyle = statusStyle.Width(statusLen).MarginRight(2).Foreground(lipgloss.ANSIColor(yellow))
|
||||||
|
titleStyle = titleStyle.Width(titleLen).MarginRight(6).Foreground(lipgloss.ANSIColor(gray))
|
||||||
|
authorStyle = authorStyle.Width(authorLen).MarginRight(1).Foreground(lipgloss.ANSIColor(magenta))
|
||||||
|
commentStyle = commentStyle.Width(commentLen).MarginRight(1).Foreground(lipgloss.ANSIColor(gray)).Align(lipgloss.Right)
|
||||||
|
commentMarker = commentMarker.Width(2).MarginRight(1).Foreground(lipgloss.ANSIColor(gray))
|
||||||
|
|
||||||
|
separator = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
str := strings.Join(
|
type formatFunc func() string
|
||||||
[]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))
|
defaultFormatFunc := func() string {
|
||||||
|
return strings.Join(
|
||||||
|
[]string{
|
||||||
|
idStyle.Render(idText),
|
||||||
|
statusStyle.Render(statusText),
|
||||||
|
titleStyle.Render(title),
|
||||||
|
authorStyle.Render(author),
|
||||||
|
commentStyle.Render(commentText),
|
||||||
|
commentMarker.Render(commentIndicator),
|
||||||
|
"\n",
|
||||||
|
}, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
idFormatFunc := func() string {
|
||||||
|
return idStyle.Render(idText) + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
compactFormatFunc := func() string {
|
||||||
|
return strings.Join(
|
||||||
|
[]string{
|
||||||
|
idStyle.Render(idText),
|
||||||
|
statusStyle.Render(statusText),
|
||||||
|
titleStyle.Render(title),
|
||||||
|
authorStyle.Render(author),
|
||||||
|
"\n",
|
||||||
|
}, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ formatFunc = defaultFormatFunc
|
||||||
|
_ formatFunc = idFormatFunc
|
||||||
|
_ formatFunc = compactFormatFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
var format string
|
||||||
|
|
||||||
|
flag.StringVar(&format, "format", "default", "")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
fn := defaultFormatFunc
|
||||||
|
|
||||||
|
switch format {
|
||||||
|
case "compact":
|
||||||
|
fn = compactFormatFunc
|
||||||
|
case "id":
|
||||||
|
fn = idFormatFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Stderr.Write([]byte(fn()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user