Skip to content

Commit

Permalink
feat: show value for first fetch; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Apr 19, 2024
1 parent b3d2865 commit 8fd4ae3
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 81 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ to your local filesystem.
<img src="./assets/cueitup.gif?raw=true" alt="Usage" />
</p>

Demo video:

[![Demo Video](https://img.youtube.com/vi/95HsXNUL4J4/0.jpg)](https://www.youtube.com/watch?v=95HsXNUL4J4)

Install
---

Expand Down Expand Up @@ -95,6 +99,52 @@ cueitup \

```

Reference Manual
---

```
cueitup has 3 views:
- Message List View
- Message Value View
- Help View (this one)
Keyboard Shortcuts
General
<tab> Switch focus to next section
<s-tab> Switch focus to previous section
? Show help view
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
```

TODO
---

Expand Down
23 changes: 2 additions & 21 deletions ui/model/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ import (
"github.com/charmbracelet/lipgloss"
)

func newAppDelegateKeyMap() *delegateKeyMap {
return &delegateKeyMap{
choose: key.NewBinding(
key.WithKeys("ctrl+f"),
key.WithHelp("enter", "check status"),
),
}
}

func newAppItemDelegate(keys *delegateKeyMap) list.DefaultDelegate {
func newAppItemDelegate() list.DefaultDelegate {
d := list.NewDefaultDelegate()

d.Styles.SelectedTitle = d.Styles.
Expand All @@ -32,15 +23,14 @@ func newAppItemDelegate(keys *delegateKeyMap) list.DefaultDelegate {
case tea.KeyMsg:
switch {
case key.Matches(msgType,
keys.choose,
list.DefaultKeyMap().CursorUp,
list.DefaultKeyMap().CursorDown,
list.DefaultKeyMap().GoToStart,
list.DefaultKeyMap().GoToEnd,
list.DefaultKeyMap().NextPage,
list.DefaultKeyMap().PrevPage,
):
if item, ok := m.SelectedItem().(KMsgItem); ok {
if item, ok := m.SelectedItem().(msgItem); ok {
return showItemDetails(*item.message.MessageId)
} else {
return nil
Expand All @@ -51,14 +41,5 @@ func newAppItemDelegate(keys *delegateKeyMap) list.DefaultDelegate {
return nil
}

help := []key.Binding{keys.choose}

d.ShortHelpFunc = func() []key.Binding {
return help
}

d.FullHelpFunc = func() [][]key.Binding {
return [][]key.Binding{help}
}
return d
}
26 changes: 13 additions & 13 deletions ui/model/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ var (
helpHeaderStyle.Render("Keyboard Shortcuts"),
helpHeaderStyle.Render("General"),
helpSectionStyle.Render(`
<tab> Switch focus to next section
<s-tab> Switch focus to previous section
? Show help view
<tab> Switch focus to next section
<s-tab> Switch focus to previous section
? Show help view
`),
helpHeaderStyle.Render("List View"),
helpSectionStyle.Render(`
Expand All @@ -39,25 +39,25 @@ var (
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
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
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
but not populate its internal list, effectively
skipping over them
`),
helpHeaderStyle.Render("Message Value View "),
helpSectionStyle.Render(`
f Toggle focussed section between full screen and
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
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
`),
)
)
4 changes: 2 additions & 2 deletions ui/model/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (

func InitialModel(sqsClient *sqs.Client, queueUrl string, msgConsumptionConf MsgConsumptionConf) model {

var appDelegateKeys = newAppDelegateKeyMap()
appDelegate := newAppItemDelegate(appDelegateKeys)
appDelegate := newAppItemDelegate()
jobItems := make([]list.Item, 0)

queueParts := strings.Split(queueUrl, "/")
Expand Down Expand Up @@ -46,6 +45,7 @@ func InitialModel(sqsClient *sqs.Client, queueUrl string, msgConsumptionConf Msg
contextSearchInput: ti,
showHelpIndicator: true,
debugMode: dbg,
firstFetch: true,
}
m.msgsList.Title = "Messages"
m.msgsList.SetStatusBarItemName("message", "messages")
Expand Down
3 changes: 2 additions & 1 deletion ui/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ type model struct {
msg string
errorMsg string
debugMode bool
firstFetch bool
}

func (m model) Init() tea.Cmd {
return tea.Batch(
GetQueueMsgCount(m.sqsClient, m.queueUrl),
tickEvery(msgCountTickInterval),
hideHelp(time.Second*30),
hideHelp(time.Minute*1),
)
}
5 changes: 0 additions & 5 deletions ui/model/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ var (
inActivePaneHeaderStyle = activePaneHeaderStyle.Copy().
Background(lipgloss.Color(inactivePaneColor))

msgDetailsTitleStyle = baseStyle.Copy().
Bold(true).
Background(lipgloss.Color("#b8bb26")).
Align(lipgloss.Left)

msgValueTitleStyle = baseStyle.Copy().
Bold(true).
Background(lipgloss.Color(inactivePaneColor)).
Expand Down
13 changes: 4 additions & 9 deletions ui/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import (
"fmt"

"github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/charmbracelet/bubbles/key"
)

type delegateKeyMap struct {
choose key.Binding
}

type KMsgItem struct {
type msgItem struct {
message types.Message
messageValue string
msgMetadata string
Expand All @@ -20,17 +15,17 @@ type KMsgItem struct {
contextKeyValue string
}

func (item KMsgItem) Title() string {
func (item msgItem) Title() string {
return RightPadTrim(fmt.Sprintf("%s: %s", RightPadTrim("msgId", 10), *item.message.MessageId), listWidth)
}

func (item KMsgItem) Description() string {
func (item msgItem) Description() string {
if item.contextKeyValue != "" {
return RightPadTrim(fmt.Sprintf("%s: %s", RightPadTrim(item.contextKeyName, 10), item.contextKeyValue), listWidth)
}
return ""
}

func (item KMsgItem) FilterValue() string {
func (item msgItem) FilterValue() string {
return string(*item.message.MessageId)
}
56 changes: 26 additions & 30 deletions ui/model/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,38 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case "n", " ":
m.msg = " ..."
return m,
m.FetchMessages(1, 0)
cmds = append(cmds, m.FetchMessages(1, 0))
case "N":
m.msg = " ..."
for i := 0; i < 10; i++ {
cmds = append(cmds,
m.FetchMessages(1, 0),
)
}
return m, tea.Batch(cmds...)
case "}":
m.msg = " ..."
for i := 0; i < 20; i++ {
cmds = append(cmds,
m.FetchMessages(5, 0),
)
}
return m, tea.Batch(cmds...)
case "?":
m.lastView = m.activeView
m.activeView = helpView
return m, nil
case "d":
if m.activeView == msgsListView {
m.deleteMsgs = !m.deleteMsgs
}
return m, nil
case "p":
if m.persistRecords == false {
m.skipRecords = false
}
m.persistRecords = !m.persistRecords
return m, nil
case "s":
if m.skipRecords == false {
m.persistRecords = false
}
m.skipRecords = !m.skipRecords
return m, nil
case "[", "h":
if m.activeView == msgValueView {
m.msgsList.CursorUp()
Expand All @@ -112,25 +105,25 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl+p":
m.pollForQueueMsgCount = !m.pollForQueueMsgCount
if m.pollForQueueMsgCount {
return m,
tea.Batch(GetQueueMsgCount(m.sqsClient,
m.queueUrl),
cmds = append(cmds,
tea.Batch(GetQueueMsgCount(m.sqsClient, m.queueUrl),
tickEvery(msgCountTickInterval),
)
),
)
}
case "ctrl+s":
if m.activeView != contextualSearchView {
m.lastView = m.activeView
m.activeView = contextualSearchView
}
return m, tea.Batch(cmds...)
case "ctrl+f":
if len(m.contextSearchValues) > 0 {
m.filterMessages = !m.filterMessages
}
case "ctrl+r":
m.msgsList.SetItems(make([]list.Item, 0))
m.msgValueVP.SetContent("")
m.firstFetch = true
case "1":
m.msgValueVP.Width = m.terminalWidth - 1
m.msgValueVP.Height = m.terminalHeight - 7
Expand All @@ -151,22 +144,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
case "tab":
if m.vpFullScreen {
return m, nil
}
if m.activeView == msgsListView {
m.activeView = msgValueView
} else if m.activeView == msgValueView {
m.activeView = msgsListView
if !m.vpFullScreen {
if m.activeView == msgsListView {
m.activeView = msgValueView
} else if m.activeView == msgValueView {
m.activeView = msgsListView
}
}
case "shift+tab":
if m.vpFullScreen {
return m, nil
}
if m.activeView == msgsListView {
m.activeView = msgsListView
} else if m.activeView == msgValueView {
m.activeView = msgsListView
if !m.vpFullScreen {
if m.activeView == msgsListView {
m.activeView = msgsListView
} else if m.activeView == msgValueView {
m.activeView = msgsListView
}
}
}

Expand Down Expand Up @@ -200,7 +191,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} else {
m.recordValueStore[msg.storeKey] = msg.msgValue
}
return m, tea.Batch(cmds...)

case ContextSearchValuesSetMsg:
m.contextSearchValues = msg.values
Expand Down Expand Up @@ -230,7 +220,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

m.msgsList.InsertItem(len(m.msgsList.Items()),
KMsgItem{message: message,
msgItem{message: message,
messageValue: msg.messageValues[i],
contextKeyName: m.msgConsumptionConf.ContextKey,
contextKeyValue: msg.keyValues[i],
Expand All @@ -256,6 +246,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
msg.messages),
)
}
if m.firstFetch {
if len(m.msgsList.Items()) > 0 {
result := string(pretty.Color([]byte(m.recordValueStore[m.msgsList.SelectedItem().FilterValue()]), nil))
m.msgValueVP.SetContent(result)
m.firstFetch = false
}
}
}
}
case KMsgChosenMsg:
Expand All @@ -271,7 +268,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.pollForQueueMsgCount {
cmds = append(cmds, tickEvery(msgCountTickInterval))
}
return m, tea.Batch(cmds...)
case QueueMsgCountFetchedMsg:
if msg.err != nil {
m.errorMsg = msg.err.Error()
Expand Down

0 comments on commit 8fd4ae3

Please sign in to comment.