mirror of
https://github.com/charmbracelet/mods
synced 2024-10-18 15:22:17 +00:00
chore: wordwrap conversation listing output
This commit is contained in:
parent
af884c527e
commit
97e126d90b
4
go.mod
4
go.mod
|
@ -19,6 +19,7 @@ require (
|
|||
github.com/spf13/cobra v1.7.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/term v0.12.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.25.0
|
||||
)
|
||||
|
@ -50,8 +51,7 @@ require (
|
|||
golang.org/x/mod v0.11.0 // indirect
|
||||
golang.org/x/net v0.12.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
golang.org/x/term v0.10.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
lukechampine.com/uint128 v1.2.0 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -952,14 +952,14 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
23
main.go
23
main.go
|
@ -13,7 +13,9 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/charmbracelet/glow/editor"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// Build vars.
|
||||
|
@ -344,15 +346,24 @@ func listConversations() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var width = 80
|
||||
if isOutputTTY() {
|
||||
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
|
||||
width = w
|
||||
}
|
||||
}
|
||||
|
||||
for _, conversation := range conversations {
|
||||
if isOutputTTY() {
|
||||
fmt.Fprintf(
|
||||
timea := stdoutStyles().Timeago.Render(timeago.Of(conversation.UpdatedAt))
|
||||
left := stdoutStyles().Bullet.String() + stdoutStyles().SHA1.Render(conversation.ID[:sha1short])
|
||||
right := stdoutStyles().ConversationList.
|
||||
Width(width-lipgloss.Width(left)).
|
||||
Render(conversation.Title, timea)
|
||||
fmt.Fprint(
|
||||
os.Stdout,
|
||||
"%s %s %s %s\n",
|
||||
stdoutStyles().Bullet,
|
||||
stdoutStyles().SHA1.Render(conversation.ID[:sha1short]),
|
||||
conversation.Title,
|
||||
stdoutStyles().Timeago.Render(timeago.Of(conversation.UpdatedAt)),
|
||||
lipgloss.JoinHorizontal(lipgloss.Top, left, right),
|
||||
"\n",
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ type styles struct {
|
|||
Link,
|
||||
Pipe,
|
||||
Quote,
|
||||
ConversationList,
|
||||
SHA1,
|
||||
Bullet,
|
||||
Timeago lipgloss.Style
|
||||
|
@ -38,8 +39,9 @@ func makeStyles(r *lipgloss.Renderer) (s styles) {
|
|||
s.Link = r.NewStyle().Foreground(lipgloss.Color("#00AF87")).Underline(true)
|
||||
s.Quote = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#FF71D0", Dark: "#FF78D2"})
|
||||
s.Pipe = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#8470FF", Dark: "#745CFF"})
|
||||
s.ConversationList = r.NewStyle().Padding(0, 1)
|
||||
s.SHA1 = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#00B594", Dark: "#11d4b1"}).Bold(true)
|
||||
s.Bullet = r.NewStyle().SetString("•").Foreground(lipgloss.AdaptiveColor{Light: "#757575", Dark: "#777"})
|
||||
s.Bullet = r.NewStyle().SetString("• ").Foreground(lipgloss.AdaptiveColor{Light: "#757575", Dark: "#777"})
|
||||
s.Timeago = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#999", Dark: "#555"})
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue