diff --git a/internal/tui/panes.go b/internal/tui/panes.go new file mode 100644 index 0000000..f8ccaf9 --- /dev/null +++ b/internal/tui/panes.go @@ -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 +} diff --git a/internal/tui/split.go b/internal/tui/split.go index 39c62f8..aa63f4a 100644 --- a/internal/tui/split.go +++ b/internal/tui/split.go @@ -3,36 +3,39 @@ package tui import "strings" func (m Model) renderAppPane() string { + // Constant height offset + constHeightOffset := 1 + var ( - searchW int = m.width + searchW int = max(0, m.width) searchH int = 1 - reqW int = int(float64(m.width) * 0.6) - reqH int = m.height + reqW int = max(0, int(float64(m.width)*0.55)) + reqH int = max(0, m.height-constHeightOffset) - detW int = int(float64(m.width) * 0.4) - detH int = m.height + detW int = max(0, int(float64(m.width)*0.45)) + detH int = max(0, m.height-constHeightOffset) - eventW int = m.width - eventH int = int(float64(m.height) * 0.15) + eventW int = max(0, m.width) + eventH int = max(0, int(float64(m.height)*0.15)) - stdW int = m.width - stdH int = int(float64(m.height) * 0.2) + stdW int = max(0, m.width) + stdH int = max(0, int(float64(m.height)*0.2)) ) if m.showSearch { - reqH -= searchH - detH -= searchH + reqH = max(0, reqH-searchH) + detH = max(0, detH-searchH) } if m.showEvents { - reqH -= eventH - detH -= eventH + reqH = max(0, reqH-eventH) + detH = max(0, detH-eventH) } if m.showStd { - reqH -= stdH - detH -= stdH + reqH = max(0, reqH-stdH) + detH = max(0, detH-stdH) } reqPane := m.renderRequestPane(reqW, reqH) @@ -43,6 +46,9 @@ func (m Model) renderAppPane() string { } var screen []string + statusBar := m.renderStatusBar(m.width) + screen = append(screen, statusBar) + if m.showSearch { searchPane := m.renderSearchPane(searchW, searchH) screen = append(screen, searchPane...) @@ -68,43 +74,3 @@ func (m Model) renderAppPane() string { 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 -}