debugger: more UI tweaks and playing with layout
This commit is contained in:
parent
8c729698a8
commit
700a301468
|
@ -1,2 +1,3 @@
|
||||||
.envrc
|
.envrc
|
||||||
out/
|
out/
|
||||||
|
log.txt
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (m HexView) updateViewMode(msg tea.Msg) (HexView, tea.Cmd) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m HexView) View(height int) string {
|
func (m HexView) View() string {
|
||||||
startAddr, endAddr := m.VisibleBytes()
|
startAddr, endAddr := m.VisibleBytes()
|
||||||
bytes := m.mem.Slice(startAddr, endAddr)
|
bytes := m.mem.Slice(startAddr, endAddr)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.sentinel65x.com/dave/gary/debugger/memory"
|
"git.sentinel65x.com/dave/gary/debugger/memory"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
@ -14,7 +13,7 @@ func UI(mem *memory.Memory) error {
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
mem: mem,
|
mem: mem,
|
||||||
bottomMsg: "Loading...",
|
statusMsg: "Loading...",
|
||||||
}
|
}
|
||||||
initial.hex = NewHexView(mem, initial.commitWrites)
|
initial.hex = NewHexView(mem, initial.commitWrites)
|
||||||
initial.hex.AddrStyle = text
|
initial.hex.AddrStyle = text
|
||||||
|
@ -31,11 +30,19 @@ func UI(mem *memory.Memory) error {
|
||||||
var (
|
var (
|
||||||
amber = lip.Color("#ffb00")
|
amber = lip.Color("#ffb00")
|
||||||
slate = lip.Color("235")
|
slate = lip.Color("235")
|
||||||
text = lip.NewStyle().Foreground(amber).Background(slate)
|
text = lip.NewStyle().
|
||||||
faintText = text.Faint(true)
|
Foreground(amber).
|
||||||
box = text.Border(lip.NormalBorder(), true, true, true, true).
|
Background(slate).
|
||||||
BorderForeground(amber).
|
BorderForeground(amber).
|
||||||
BorderBackground(slate)
|
BorderBackground(slate).
|
||||||
|
Border(lip.NormalBorder(), false, false, false, false)
|
||||||
|
faintText = text.Faint(true)
|
||||||
|
|
||||||
|
box = lip.NewStyle().
|
||||||
|
Border(lip.NormalBorder()).
|
||||||
|
BorderForeground(amber).
|
||||||
|
BorderBackground(slate).
|
||||||
|
Padding(1, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
type msgMemoryChanged struct {
|
type msgMemoryChanged struct {
|
||||||
|
@ -56,22 +63,29 @@ type debugger struct {
|
||||||
mem *memory.Memory
|
mem *memory.Memory
|
||||||
hex HexView
|
hex HexView
|
||||||
lastErr error
|
lastErr error
|
||||||
bottomMsg string
|
statusMsg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m debugger) Init() tea.Cmd {
|
func (m debugger) Init() tea.Cmd {
|
||||||
return tea.Sequence(
|
loads := m.readFullMemoryCmds()
|
||||||
m.readFullMemory(),
|
ret := make([]tea.Cmd, 0, (len(loads)*2)+1)
|
||||||
staticMsg(msgUpdateStatus{"Initial load complete."}),
|
for i, c := range loads {
|
||||||
)
|
ret = append(ret, staticMsg(msgUpdateStatus{fmt.Sprintf("Loading block %d/%d", i+1, len(loads))}), c)
|
||||||
|
}
|
||||||
|
ret = append(ret, staticMsg(msgUpdateStatus{"Load complete."}))
|
||||||
|
return tea.Sequence(ret...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m debugger) readFullMemory() tea.Cmd {
|
func (m debugger) readFullMemory() tea.Cmd {
|
||||||
|
return tea.Sequence(m.readFullMemoryCmds()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m debugger) readFullMemoryCmds() []tea.Cmd {
|
||||||
var ret []tea.Cmd
|
var ret []tea.Cmd
|
||||||
for i := 0; i < m.mem.Len(); i += 128 {
|
for i := 0; i < m.mem.Len(); i += 128 {
|
||||||
ret = append(ret, m.readMemory(i, 128))
|
ret = append(ret, m.readMemory(i, 128))
|
||||||
}
|
}
|
||||||
return tea.Sequence(ret...)
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m debugger) readMemory(start, count int) tea.Cmd {
|
func (m debugger) readMemory(start, count int) tea.Cmd {
|
||||||
|
@ -103,13 +117,12 @@ func (m debugger) commitWrites() tea.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m debugger) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m debugger) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
log.Printf("msv: %#v", msg)
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.width = msg.Width
|
m.width = msg.Width
|
||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
m.hex, cmd = m.hex.Update(HexViewSetHeight{m.height - 6}) // TODO: make less shit
|
m.hex, cmd = m.hex.Update(HexViewSetHeight{m.height - box.GetVerticalFrameSize() - 1})
|
||||||
return m, cmd
|
return m, cmd
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
|
@ -120,11 +133,10 @@ func (m debugger) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, m.readMemory(start, end-start)
|
return m, m.readMemory(start, end-start)
|
||||||
}
|
}
|
||||||
case msgErr:
|
case msgErr:
|
||||||
log.Print(msg.err)
|
|
||||||
m.lastErr = msg.err
|
m.lastErr = msg.err
|
||||||
return m, nil
|
return m, nil
|
||||||
case msgUpdateStatus:
|
case msgUpdateStatus:
|
||||||
m.bottomMsg = msg.status
|
m.statusMsg = msg.status
|
||||||
}
|
}
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
m.hex, cmd = m.hex.Update(msg)
|
m.hex, cmd = m.hex.Update(msg)
|
||||||
|
@ -158,20 +170,23 @@ func (m debugger) View() string {
|
||||||
return lip.Place(m.width, m.height, lip.Center, lip.Center, "Please embiggen your terminal")
|
return lip.Place(m.width, m.height, lip.Center, lip.Center, "Please embiggen your terminal")
|
||||||
}
|
}
|
||||||
|
|
||||||
statusBar := text.Width(m.width).Height(1).Align(lip.Center)
|
hex := box.Render(m.hex.View())
|
||||||
topSegment := statusBar.Width(m.width / 3).Reverse(true)
|
|
||||||
|
|
||||||
hexBox := lip.NewStyle().Border(lip.NormalBorder()).BorderForeground(amber).BorderBackground(slate).Padding(1, 2)
|
barText := text.Reverse(true) //.Height(1)
|
||||||
hexHeight := m.height - 2 - hexBox.GetVerticalFrameSize()
|
|
||||||
hex := hexBox.Render(m.hex.View(hexHeight))
|
|
||||||
|
|
||||||
topLeft := text.Reverse(true).Bold(true).Render("Addr: ") + text.Reverse(true).Render(fmt.Sprintf("0x%-5x", m.hex.SelectedAddr()))
|
topLeft := barText.Bold(true).PaddingLeft(1).Render("Addr: ")
|
||||||
topLeft = topSegment.Padding(0, 1).Align(lip.Left).Render(topLeft)
|
topLeft += barText.Render(fmt.Sprintf("0x%x (%d)", m.hex.SelectedAddr(), m.hex.SelectedAddr()))
|
||||||
topMid := topSegment.Bold(true).Render("GARY Debugger")
|
topRight := barText.PaddingRight(1).Render(m.statusMsg)
|
||||||
topRight := topSegment.Render("")
|
title := barText.Padding(0, 1).Bold(true).Render("GARY Debugger")
|
||||||
topStatus := lip.JoinHorizontal(lip.Top, topLeft, topMid, topRight)
|
|
||||||
bottomStatus := statusBar.Render(m.bottomMsg)
|
|
||||||
|
|
||||||
top := lip.JoinVertical(lip.Center, topStatus, hex, bottomStatus)
|
sideWidth := max(lip.Width(topLeft), lip.Width(topRight))
|
||||||
return top
|
titleWidth := m.width - 2*sideWidth
|
||||||
|
topLeft = barText.Width(sideWidth).Align(lip.Left).Render(topLeft)
|
||||||
|
topRight = barText.Width(sideWidth).Align(lip.Right).Render(topRight)
|
||||||
|
title = barText.Width(titleWidth).Align(lip.Center).Render(title)
|
||||||
|
|
||||||
|
status := lip.JoinHorizontal(lip.Top, topLeft, title, topRight)
|
||||||
|
|
||||||
|
all := lip.JoinVertical(lip.Center, status, hex)
|
||||||
|
return all
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue