feat: working on the split engine, lots of progress.
Need colors and a real display.
This commit is contained in:
parent
d51d1fea56
commit
4c4a3f6bb0
@ -21,15 +21,22 @@ type Model struct {
|
|||||||
|
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
|
||||||
|
showEvents bool
|
||||||
|
showStd bool
|
||||||
|
showSearch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModel(ch <-chan model.Event) Model {
|
func NewModel(ch <-chan model.Event) Model {
|
||||||
return Model{
|
return Model{
|
||||||
channel: ch,
|
channel: ch,
|
||||||
events: make([]model.Event, 0, maxEvents),
|
events: make([]model.Event, 0, maxEvents),
|
||||||
requests: make([]model.Request, 0, maxRequests),
|
requests: make([]model.Request, 0, maxRequests),
|
||||||
width: 100,
|
width: 0,
|
||||||
height: 28,
|
height: 0,
|
||||||
|
showEvents: false,
|
||||||
|
showStd: false,
|
||||||
|
showSearch: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
110
internal/tui/split.go
Normal file
110
internal/tui/split.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package tui
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func (m Model) renderAppPane() string {
|
||||||
|
var (
|
||||||
|
searchW int = m.width
|
||||||
|
searchH int = 1
|
||||||
|
|
||||||
|
reqW int = int(float64(m.width) * 0.6)
|
||||||
|
reqH int = m.height
|
||||||
|
|
||||||
|
detW int = int(float64(m.width) * 0.4)
|
||||||
|
detH int = m.height
|
||||||
|
|
||||||
|
eventW int = m.width
|
||||||
|
eventH int = int(float64(m.height) * 0.15)
|
||||||
|
|
||||||
|
stdW int = m.width
|
||||||
|
stdH int = int(float64(m.height) * 0.2)
|
||||||
|
)
|
||||||
|
|
||||||
|
if m.showSearch {
|
||||||
|
reqH -= searchH
|
||||||
|
detH -= searchH
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.showEvents {
|
||||||
|
reqH -= eventH
|
||||||
|
detH -= eventH
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.showStd {
|
||||||
|
reqH -= stdH
|
||||||
|
detH -= stdH
|
||||||
|
}
|
||||||
|
|
||||||
|
reqPane := m.renderRequestPane(reqW, reqH)
|
||||||
|
detPane := m.renderDetailsPane(detW, detH)
|
||||||
|
|
||||||
|
if len(reqPane) != len(detPane) {
|
||||||
|
return "height of request and details did not match"
|
||||||
|
}
|
||||||
|
|
||||||
|
var screen []string
|
||||||
|
if m.showSearch {
|
||||||
|
searchPane := m.renderSearchPane(searchW, searchH)
|
||||||
|
screen = append(screen, searchPane...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range reqPane {
|
||||||
|
screen = append(screen, reqPane[i]+detPane[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.showEvents {
|
||||||
|
eventPane := m.renderEventsPane(eventW, eventH)
|
||||||
|
screen = append(screen, eventPane...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.showStd {
|
||||||
|
stdPane := m.renderStdPane(stdW, stdH)
|
||||||
|
screen = append(screen, stdPane...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(screen) != m.height {
|
||||||
|
return "height of screen does not match terminal height"
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@ -14,10 +14,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
// TODO: Abstract the keymaps
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "ctrl+c", "q", "esc":
|
case "ctrl+c", "q":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
case "e":
|
||||||
|
m.showEvents = !m.showEvents
|
||||||
|
case "o":
|
||||||
|
m.showStd = !m.showStd
|
||||||
|
case "/":
|
||||||
|
m.showSearch = true
|
||||||
|
case "esc":
|
||||||
|
m.showSearch = false
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
|||||||
@ -9,20 +9,23 @@ import (
|
|||||||
|
|
||||||
// TODO: This is all temporary
|
// TODO: This is all temporary
|
||||||
func (m Model) View() string {
|
func (m Model) View() string {
|
||||||
eventLines := m.renderEvents(8)
|
return m.renderAppPane()
|
||||||
requestLines := m.renderRequests(12)
|
|
||||||
|
|
||||||
return strings.Join([]string{
|
// eventLines := m.renderEvents(8)
|
||||||
"termtap - live session",
|
// requestLines := m.renderRequests(12)
|
||||||
fmt.Sprintf("events=%d requests=%d", len(m.events), len(m.requests)),
|
//
|
||||||
"keys: q/esc/ctrl+c quit",
|
// return strings.Join([]string{
|
||||||
"",
|
// "termtap - live session",
|
||||||
"Recent events:",
|
// fmt.Sprintf("events=%d requests=%d", len(m.events), len(m.requests)),
|
||||||
eventLines,
|
// fmt.Sprintf("%dx%d", m.height, m.width),
|
||||||
"",
|
// "keys: q/esc/ctrl+c quit",
|
||||||
"Recent requests:",
|
// "",
|
||||||
requestLines,
|
// "Recent events:",
|
||||||
}, "\n")
|
// eventLines,
|
||||||
|
// "",
|
||||||
|
// "Recent requests:",
|
||||||
|
// requestLines,
|
||||||
|
// }, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderEvents(limit int) string {
|
func (m Model) renderEvents(limit int) string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user