Skip to content

Commit

Permalink
feat: persist subset only, if requested
Browse files Browse the repository at this point in the history
Print reference manual on -help.
  • Loading branch information
dhth committed Mar 10, 2024
1 parent c2ab3b4 commit ef651d1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 43 deletions.
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ var (
)

func Execute() {

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Inspect messages in an AWS SQS queue in a simple and deliberate manner.\n\nFlags:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n------\n%s", model.HelpText)
}
flag.Parse()

if *queueUrl == "" {
Expand Down
66 changes: 34 additions & 32 deletions ui/model/help.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
package model

var (
helpText = `
cueitup has two sections:
- Message List View
- Message Value View
HelpText = `
TUI Reference Manual
Keyboard Shortcuts:
cueitup has two sections:
- Message List View
- Message Value View
General
<tab> Switch focus to next section
<s-tab> Switch focus to previous section
Keyboard Shortcuts:
List View
h/<Up> Move cursor up
k/<Down> Move cursor down
n Fetch the next message from the queue
N Fetch up to 10 more messages from the queue
} Fetch up to 100 more messages from the queue
d Toggle deletion mode; cueitup will delete messages
after reading them
<ctrl+s> Toggle contextual search prompt
<ctrl+f> Toggle contextual filtering ON/OFF
<ctrl+p> Toggle queue message count polling ON/OFF; ON by default
p Toggle persist mode (cueitup will start persisting
messages, at the location
messages/<topic-name>/<timestamp>/<message-id>.md
s Toggle skipping mode; cueitup will consume messages,
but not populate its internal list, effectively
skipping over them
General
<tab> Switch focus to next section
<s-tab> Switch focus to previous section
Message Value View
f Toggle focussed section between full screen and
regular mode
1 Maximize message value view
q Minimize section, and return focus to list view
[ Show details for the previous entry in the list
] Show details for the next entry in the list
List View
h/<Up> Move cursor up
k/<Down> Move cursor down
n Fetch the next message from the queue
N Fetch up to 10 more messages from the queue
} Fetch up to 100 more messages from the queue
d Toggle deletion mode; cueitup will delete messages
after reading them
<ctrl+s> Toggle contextual search prompt
<ctrl+f> Toggle contextual filtering ON/OFF
<ctrl+p> Toggle queue message count polling ON/OFF; ON by default
p Toggle persist mode (cueitup will start persisting
messages, at the location
messages/<topic-name>/<timestamp-when-cueitup-started>/<unix-epoch>-<message-id>.md
s Toggle skipping mode; cueitup will consume messages,
but not populate its internal list, effectively
skipping over them
Message Value View
f Toggle focussed section between full screen and
regular mode
1 Maximize message value view
q Minimize section, and return focus to list view
[ Show details for the previous entry in the list
] Show details for the next entry in the list
`
)
19 changes: 14 additions & 5 deletions ui/model/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package model

import (
"fmt"
"time"

"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/tidwall/pretty"
)

const useHighPerformanceRenderer = false
Expand Down Expand Up @@ -203,7 +205,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.helpVPReady {
m.helpVP = viewport.New(120, m.terminalHeight-7)
m.helpVP.HighPerformanceRendering = useHighPerformanceRenderer
m.helpVP.SetContent(helpText)
m.helpVP.SetContent(HelpText)
m.helpVPReady = true
}
case KMsgValueReadyMsg:
Expand Down Expand Up @@ -248,17 +250,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
contextKeyValue: msg.keyValues[i],
},
)
m.recordValueStore[*message.MessageId] = msg.messageValues[i]
if m.persistRecords {
filePath := fmt.Sprintf("%s/%s.md", m.persistDir, *message.MessageId)
prefix := time.Now().Unix()
filePath := fmt.Sprintf("%s/%d-%s.md", m.persistDir, prefix, *message.MessageId)
cmds = append(cmds,
saveRecordValueToDisk(
filePath,
*message.Body,
msg.messageValues[i],
m.msgConsumptionConf.Format,
),
)
}
m.recordValueStore[*message.MessageId] = msg.messageValues[i]
}
if m.deleteMsgs {
cmds = append(cmds,
Expand All @@ -270,7 +273,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
case KMsgChosenMsg:
m.msgValueVP.SetContent(m.recordValueStore[msg.key])
switch m.deserializationFmt {
case JsonFmt:
result := string(pretty.Color([]byte(m.recordValueStore[msg.key]), nil))
m.msgValueVP.SetContent(result)
default:
m.msgValueVP.SetContent(m.recordValueStore[msg.key])
}
case MsgCountTickMsg:
cmds = append(cmds, GetQueueMsgCount(m.sqsClient, m.queueUrl))
if m.pollForQueueMsgCount {
Expand Down
9 changes: 3 additions & 6 deletions ui/model/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ func getRecordValueJSONFull(message *types.Message) (string, error) {
return "", nil
}

var result string
prettyJSON := pretty.Pretty([]byte(*message.Body))
result = string(pretty.Color(prettyJSON, nil))

return result, nil
return string(prettyJSON), nil
}

func getRecordValueJSONNested(message *types.Message, extractKey string, contextKey string) (string, string, error) {
Expand Down Expand Up @@ -76,14 +74,13 @@ func getRecordValueJSONNested(message *types.Message, extractKey string, context
return "", "", err
}
nestedPretty := pretty.Pretty(nestedBytes)
nestedColored := string(pretty.Color(nestedPretty, nil))

contextualValue, ok := nestedData[contextKey]
if !ok {
return string(nestedColored), "", nil
return string(nestedPretty), "", nil
}

return string(nestedColored), contextualValue.(string), nil
return string(nestedPretty), contextualValue.(string), nil
}

func getMessageData(message *types.Message, msgConsumptionConf MsgConsumptionConf) (string, string, error) {
Expand Down

0 comments on commit ef651d1

Please sign in to comment.