feat(tui): use universal archive rows
This commit is contained in:
parent
f7db36c7fd
commit
5e5c401531
2
go.mod
2
go.mod
@ -41,7 +41,7 @@ require (
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/vincentkoc/crawlkit v0.3.0
|
||||
github.com/vincentkoc/crawlkit v0.3.1
|
||||
golang.org/x/crypto v0.50.0 // indirect
|
||||
golang.org/x/tools v0.44.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@ -73,8 +73,8 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/vincentkoc/crawlkit v0.3.0 h1:37QsucIaUmaRygk2fn7NQniD6YSAAi0DR1vzL8UimoI=
|
||||
github.com/vincentkoc/crawlkit v0.3.0/go.mod h1:Zp6k0f6owZ81wccG26jPbLSDGmfjoxPdzgPXZcUpmW4=
|
||||
github.com/vincentkoc/crawlkit v0.3.1 h1:z5q7s+oAkdlgGjdT1N/CsWkc4GZ2uNqCmVDtTd2tQSM=
|
||||
github.com/vincentkoc/crawlkit v0.3.1/go.mod h1:Zp6k0f6owZ81wccG26jPbLSDGmfjoxPdzgPXZcUpmW4=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs=
|
||||
|
||||
@ -146,6 +146,10 @@ func TestStatusSearchSQLAndListings(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(out.Bytes(), &rows))
|
||||
require.NotEmpty(t, rows)
|
||||
require.Equal(t, "panic locked database", rows[0]["title"])
|
||||
require.Equal(t, "discord", rows[0]["source"])
|
||||
require.Equal(t, "message", rows[0]["kind"])
|
||||
require.Equal(t, "g1", rows[0]["scope"])
|
||||
require.Equal(t, "general", rows[0]["container"])
|
||||
after, err := os.ReadFile(dbPath)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, before, after, "tui --json should not mutate the database")
|
||||
|
||||
@ -3,7 +3,6 @@ package cli
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@ -45,44 +44,43 @@ func (r *runtime) runTUI(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
items := discordTUIItems(rows)
|
||||
if r.json {
|
||||
return r.print(items)
|
||||
}
|
||||
if err := tui.Run(r.ctx, tui.Options{
|
||||
return tui.Browse(r.ctx, tui.BrowseOptions{
|
||||
AppName: "discrawl",
|
||||
Title: "discrawl archive",
|
||||
EmptyMessage: "discrawl has no local messages yet",
|
||||
Items: items,
|
||||
}); err != nil {
|
||||
if errors.Is(err, tui.ErrNotTerminal) {
|
||||
return fmt.Errorf("%w; run discrawl tui from a TTY or pass --json", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
Rows: discordTUIRows(rows),
|
||||
JSON: r.json,
|
||||
Stdout: r.stdout,
|
||||
})
|
||||
}
|
||||
|
||||
func discordTUIItems(rows []store.MessageRow) []tui.Item {
|
||||
items := make([]tui.Item, 0, len(rows))
|
||||
func discordTUIRows(rows []store.MessageRow) []tui.Row {
|
||||
items := make([]tui.Row, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
title := strings.TrimSpace(row.Content)
|
||||
if title == "" {
|
||||
title = row.MessageID
|
||||
}
|
||||
tags := []string{"message", row.GuildID, row.ChannelID}
|
||||
tags := []string{row.GuildID, row.ChannelID}
|
||||
if row.GuildID == "@me" {
|
||||
tags = append(tags, "dm")
|
||||
}
|
||||
items = append(items, tui.Item{
|
||||
Title: title,
|
||||
Subtitle: strings.TrimSpace(strings.Join([]string{row.GuildID, row.ChannelName, row.AuthorName, formatTime(row.CreatedAt)}, " ")),
|
||||
Detail: strings.TrimSpace(strings.Join([]string{
|
||||
"id=" + row.MessageID,
|
||||
"channel=" + row.ChannelID,
|
||||
"author=" + row.AuthorID,
|
||||
"reply_to=" + row.ReplyToMessage,
|
||||
}, "\n")),
|
||||
Tags: tags,
|
||||
items = append(items, tui.Row{
|
||||
Source: "discord",
|
||||
Kind: "message",
|
||||
ID: row.MessageID,
|
||||
ParentID: row.ReplyToMessage,
|
||||
Scope: row.GuildID,
|
||||
Container: firstNonEmpty(row.ChannelName, row.ChannelID),
|
||||
Author: firstNonEmpty(row.AuthorName, row.AuthorID),
|
||||
Title: title,
|
||||
Text: row.Content,
|
||||
CreatedAt: formatTime(row.CreatedAt),
|
||||
Tags: tags,
|
||||
Fields: map[string]string{
|
||||
"channel_id": row.ChannelID,
|
||||
"author_id": row.AuthorID,
|
||||
},
|
||||
})
|
||||
}
|
||||
return items
|
||||
|
||||
Loading…
Reference in New Issue
Block a user