Files
pipelines/internal/tui/status.go
T
alan c42a19f7d3 Improve workflow UI, retain stage diffs, and add portable pipeline transfers
Make OpenCode authoring responsive and expand the managed skill references. Add conflict-aware import/export, real-provider reference workflows, and tracked V2 generation for reliable budget accounting.
2026-10-10 20:55:42 +01:00

109 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package tui
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/statusview"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"strings"
)
func (m Model) openStatus() (tea.Model, tea.Cmd) {
m.statusOpen = true
m.statusTop = 0
m.systemStatus = nil
m.statusError = ""
return m.refreshStatus()
}
func (m Model) refreshStatus() (tea.Model, tea.Cmd) {
if m.conn == nil {
m.statusError = "Not connected to the Pipelines server."
return m, nil
}
m.nextID++
m.statusRequest = fmt.Sprintf("status-%d", m.nextID)
m.statusError = ""
return m, m.send(protocol.Message{Type: protocol.GetStatus, ID: m.statusRequest})
}
func (m Model) updateStatus(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "esc", "q":
m.statusOpen = false
return m, nil
case "r":
return m.refreshStatus()
case "j", "down":
m.statusTop++
case "k", "up":
m.statusTop--
case "pgdown":
m.statusTop += max(1, m.height-10)
case "pgup":
m.statusTop -= max(1, m.height-10)
}
m.statusTop = max(0, min(m.statusTop, max(0, len(m.statusContent())-max(1, m.height-4))))
return m, nil
}
func (m Model) statusLines() []string {
lines := []string{}
if m.statusRequest != "" {
lines = append(lines, m.loading("Checking server and ntfy…"))
}
if m.statusError != "" {
lines = append(lines, m.statusError)
if m.systemStatus == nil {
lines = append(lines, "ntfy: unknown (server information unavailable)")
}
}
if m.systemStatus != nil {
lines = append(lines, " ")
lines = append(lines, statusview.Lines(m.systemStatus)...)
}
return lines
}
func (m Model) statusContent() []string {
server, ntfy := statusview.ServerLines(m.systemStatus), statusview.NtfyLines(m.systemStatus)
if m.systemStatus == nil && m.statusError != "" {
s := statusview.Offline(m.url)
server, ntfy = statusview.ServerLines(s), statusview.NtfyLines(s)
}
if m.statusError != "" {
server = append([]string{m.statusError}, server...)
}
if m.statusRequest != "" {
server = append([]string{m.loading("Checking…")}, server...)
}
width := m.width
wrap := func(lines []string, w int) []string {
var rows []string
for _, line := range lines {
rows = append(rows, strings.Split(ansi.Wrap(line, max(1, w), ""), "\n")...)
}
return rows
}
if width >= 100 {
w := (width - 2) / 2
server, ntfy = wrap(server, w-4), wrap(ntfy, width-w-6)
cardHeight := max(len(server), len(ntfy)) + 4
left := panel(w, cardHeight, []string{"Pipelines server"}, server, "", false)
right := panel(width-w-2, cardHeight, []string{"ntfy · phone connection"}, ntfy, "", false)
return strings.Split(lipgloss.JoinHorizontal(lipgloss.Top, left, " ", right), "\n")
}
server, ntfy = wrap(server, width-4), wrap(ntfy, width-4)
left := panel(width, len(server)+4, []string{"Pipelines server"}, server, "", false)
right := panel(width, len(ntfy)+4, []string{"ntfy · phone connection"}, ntfy, "", false)
return strings.Split(left+"\n\n"+right, "\n")
}
func (m Model) statusView(height int) string {
lines := m.statusContent()
top := max(0, min(m.statusTop, max(0, len(lines)-height)))
visible := append([]string{}, lines[top:min(len(lines), top+height)]...)
if top+height < len(lines) && len(visible) > 0 {
visible[len(visible)-1] = bar("↓ More connection details", fmt.Sprintf("%d–%d / %d", top+1, top+height, len(lines)), m.width, false)
}
return fitBlock(visible, m.width, height)
}