feat: render status bar
This commit is contained in:
parent
4c4a3f6bb0
commit
ea201b4c91
92
internal/tui/panes.go
Normal file
92
internal/tui/panes.go
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m Model) renderStatusBar(w int) string {
|
||||||
|
// TODO: Optimize somehow
|
||||||
|
var errCount int
|
||||||
|
for _, req := range m.requests {
|
||||||
|
if req.Failed || (req.Status >= 400 && req.Status < 600) {
|
||||||
|
errCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
left := fmt.Sprintf(" tap %3d reqs | %d err | avg 500ms", len(m.requests), errCount)
|
||||||
|
right := "j/k nav / search tab panel e events o output r replay q quit "
|
||||||
|
|
||||||
|
spaceSize := max(w-(len(left)+len(right)), 0)
|
||||||
|
space := strings.Repeat(" ", spaceSize)
|
||||||
|
|
||||||
|
return left + space + right
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderSearchPane(w, h int) []string {
|
||||||
|
lines := make([]string, h)
|
||||||
|
for y := range lines {
|
||||||
|
lines[y] = strings.Repeat(" ", w)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderRequestPane(w, h int) []string {
|
||||||
|
if w < 0 {
|
||||||
|
w = 0
|
||||||
|
}
|
||||||
|
if h < 0 {
|
||||||
|
h = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := make([]string, h)
|
||||||
|
for y := range lines {
|
||||||
|
lines[y] = strings.Repeat(".", w)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderDetailsPane(w, h int) []string {
|
||||||
|
if w < 0 {
|
||||||
|
w = 0
|
||||||
|
}
|
||||||
|
if h < 0 {
|
||||||
|
h = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := make([]string, h)
|
||||||
|
for y := range lines {
|
||||||
|
lines[y] = strings.Repeat("^", w)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderEventsPane(w, h int) []string {
|
||||||
|
if w < 0 {
|
||||||
|
w = 0
|
||||||
|
}
|
||||||
|
if h < 0 {
|
||||||
|
h = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := make([]string, h)
|
||||||
|
for y := range lines {
|
||||||
|
lines[y] = strings.Repeat("~", w)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderStdPane(w, h int) []string {
|
||||||
|
if w < 0 {
|
||||||
|
w = 0
|
||||||
|
}
|
||||||
|
if h < 0 {
|
||||||
|
h = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := make([]string, h)
|
||||||
|
for y := range lines {
|
||||||
|
lines[y] = strings.Repeat(" ", w)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
@ -3,36 +3,39 @@ package tui
|
|||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
func (m Model) renderAppPane() string {
|
func (m Model) renderAppPane() string {
|
||||||
|
// Constant height offset
|
||||||
|
constHeightOffset := 1
|
||||||
|
|
||||||
var (
|
var (
|
||||||
searchW int = m.width
|
searchW int = max(0, m.width)
|
||||||
searchH int = 1
|
searchH int = 1
|
||||||
|
|
||||||
reqW int = int(float64(m.width) * 0.6)
|
reqW int = max(0, int(float64(m.width)*0.55))
|
||||||
reqH int = m.height
|
reqH int = max(0, m.height-constHeightOffset)
|
||||||
|
|
||||||
detW int = int(float64(m.width) * 0.4)
|
detW int = max(0, int(float64(m.width)*0.45))
|
||||||
detH int = m.height
|
detH int = max(0, m.height-constHeightOffset)
|
||||||
|
|
||||||
eventW int = m.width
|
eventW int = max(0, m.width)
|
||||||
eventH int = int(float64(m.height) * 0.15)
|
eventH int = max(0, int(float64(m.height)*0.15))
|
||||||
|
|
||||||
stdW int = m.width
|
stdW int = max(0, m.width)
|
||||||
stdH int = int(float64(m.height) * 0.2)
|
stdH int = max(0, int(float64(m.height)*0.2))
|
||||||
)
|
)
|
||||||
|
|
||||||
if m.showSearch {
|
if m.showSearch {
|
||||||
reqH -= searchH
|
reqH = max(0, reqH-searchH)
|
||||||
detH -= searchH
|
detH = max(0, detH-searchH)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.showEvents {
|
if m.showEvents {
|
||||||
reqH -= eventH
|
reqH = max(0, reqH-eventH)
|
||||||
detH -= eventH
|
detH = max(0, detH-eventH)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.showStd {
|
if m.showStd {
|
||||||
reqH -= stdH
|
reqH = max(0, reqH-stdH)
|
||||||
detH -= stdH
|
detH = max(0, detH-stdH)
|
||||||
}
|
}
|
||||||
|
|
||||||
reqPane := m.renderRequestPane(reqW, reqH)
|
reqPane := m.renderRequestPane(reqW, reqH)
|
||||||
@ -43,6 +46,9 @@ func (m Model) renderAppPane() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var screen []string
|
var screen []string
|
||||||
|
statusBar := m.renderStatusBar(m.width)
|
||||||
|
screen = append(screen, statusBar)
|
||||||
|
|
||||||
if m.showSearch {
|
if m.showSearch {
|
||||||
searchPane := m.renderSearchPane(searchW, searchH)
|
searchPane := m.renderSearchPane(searchW, searchH)
|
||||||
screen = append(screen, searchPane...)
|
screen = append(screen, searchPane...)
|
||||||
@ -68,43 +74,3 @@ func (m Model) renderAppPane() string {
|
|||||||
|
|
||||||
return strings.Join(screen, ("\n"))
|
return strings.Join(screen, ("\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderSearchPane(w, h int) []string {
|
|
||||||
lines := make([]string, h)
|
|
||||||
for y := range lines {
|
|
||||||
lines[y] = strings.Repeat(" ", w)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Model) renderRequestPane(w, h int) []string {
|
|
||||||
lines := make([]string, h)
|
|
||||||
for y := range lines {
|
|
||||||
lines[y] = strings.Repeat(".", w)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Model) renderDetailsPane(w, h int) []string {
|
|
||||||
lines := make([]string, h)
|
|
||||||
for y := range lines {
|
|
||||||
lines[y] = strings.Repeat("^", w)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Model) renderEventsPane(w, h int) []string {
|
|
||||||
lines := make([]string, h)
|
|
||||||
for y := range lines {
|
|
||||||
lines[y] = strings.Repeat("~", w)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Model) renderStdPane(w, h int) []string {
|
|
||||||
lines := make([]string, h)
|
|
||||||
for y := range lines {
|
|
||||||
lines[y] = strings.Repeat(" ", w)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user