Skip to content

Commit

Permalink
Update sidebar when no result is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinatedpixel committed Jul 17, 2024
1 parent 25630bd commit 71ee002
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions viewer/sidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (m *sidebarModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {

case *Item:
case UpdateItem:

m.Data = msg
content := m.getSidebarContents()
Expand Down Expand Up @@ -132,19 +132,23 @@ func (m *sidebarModel) getSidebarContents() string {
modifierLabel := sectionStyle.Render("「 Threat Modifiers 」")
modifiers := m.renderModifiers()

connInfoLabel := sectionStyle.Render("「 Connection Info 」")

dataStyle := lipgloss.NewStyle().Foreground(defaultTextColor)

// get connection count
connCountStyle := lipgloss.NewStyle().Background(overlay2).Foreground(base).Bold(true).Padding(0, 2)
connCountHeader := connCountStyle.Render("Connection Count")
connCount := dataStyle.Render(lipgloss.JoinVertical(lipgloss.Top, connCountHeader, fmt.Sprintf("%d", m.Data.Count)))
var connInfoLabel, connCount, bytes string
// display connection count and bytes for everything except C2 over DNS
if m.Data.C2OverDNSScore == 0 {
connInfoLabel = sectionStyle.Render("「 Connection Info 」")

// get connection count
connCountStyle := lipgloss.NewStyle().Background(overlay2).Foreground(base).Bold(true).Padding(0, 2)
connCountHeader := connCountStyle.Render("Connection Count")
connCount = dataStyle.Render(lipgloss.JoinVertical(lipgloss.Top, connCountHeader, fmt.Sprintf("%d", m.Data.Count)))

// get total bytes
bytesHeaderStyle := lipgloss.NewStyle().Background(overlay2).Foreground(base).Bold(true).Padding(0, 2)
bytesHeader := bytesHeaderStyle.Render("Total Bytes")
bytes := dataStyle.Render(lipgloss.JoinVertical(lipgloss.Top, bytesHeader, m.Data.TotalBytesFormatted))
// get total bytes
bytesHeaderStyle := lipgloss.NewStyle().Background(overlay2).Foreground(base).Bold(true).Padding(0, 2)
bytesHeader := bytesHeaderStyle.Render("Total Bytes")
bytes = dataStyle.Render(lipgloss.JoinVertical(lipgloss.Top, bytesHeader, m.Data.TotalBytesFormatted))
}

// get port:proto:service
portProtoService := m.Data.GetPortProtoService()
Expand All @@ -163,11 +167,6 @@ func (m *sidebarModel) getSidebarContents() string {
// render header
portsHeader := portsHeaderStyle.Render("Port : Proto : Service")
ports = dataStyle.Render(lipgloss.JoinVertical(lipgloss.Top, portsHeader, strings.Join(portProtoService, "\n")))
// strings.Join(portProtoService, "\n")
// calculate the number of lines available for port data
// remainingLines := m.viewport.Height - (lipgloss.Height(heading) + lipgloss.Height(modifiers) + lipgloss.Height(modifierLabel) + lipgloss.Height(connInfoLabel) + lipgloss.Height(bytes) + lipgloss.Height(connCount))
// ports = renderPorts(portProtoService, m.viewport.Width, remainingLines)

}

// join contents
Expand Down
4 changes: 2 additions & 2 deletions viewer/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

// set sidebar data to the selected item
if data, ok := m.List.Rows.Items()[m.List.Rows.Index()].(*Item); ok {
_, cmd := m.SideBar.Update(data)
_, cmd := m.SideBar.Update(UpdateItem(data))
cmds = append(cmds, cmd)
}

} else {
// if there are no items to display, set the sidebar data to nil
_, cmd := m.SideBar.Update(nil)
_, cmd := m.SideBar.Update(UpdateItem(nil))
cmds = append(cmds, cmd)
}

Expand Down

0 comments on commit 71ee002

Please sign in to comment.