Files
wehub-resource-sync 36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:06 +08:00

150 lines
2.6 KiB
Go

package tui
import "github.com/charmbracelet/bubbles/table"
// returns the column index at x pixels, or -1 if not found.
func (m *MainModel) getColumnAtX(x int, cols []table.Column) int {
currentX := 0
for i, col := range cols {
colWidth := col.Width + 2
if x >= currentX && x < currentX+colWidth {
return i
}
currentX += colWidth
}
return -1
}
func (m *MainModel) handleProcessHeaderClick(x int) {
cols := m.table.Columns()
colIdx := m.getColumnAtX(x, cols)
if colIdx >= 0 {
newCol := ""
switch colIdx {
case 0:
newCol = "pid"
case 1:
newCol = "user"
case 2:
newCol = "name"
case 3:
newCol = "cpu"
case 4:
newCol = "mem"
case 5:
newCol = "time"
}
if newCol != "" {
if m.sortCol == newCol {
m.sortDesc = !m.sortDesc
} else {
m.sortCol = newCol
m.sortDesc = true
}
m.sortProcesses()
m.filterProcesses()
newCols := m.getColumns()
for i := range cols {
if i < len(newCols) {
newCols[i].Width = cols[i].Width
}
}
m.table.SetColumns(newCols)
}
}
}
func (m *MainModel) handlePortHeaderClick(x int) {
cols := m.portTable.Columns()
colIdx := m.getColumnAtX(x, cols)
if colIdx >= 0 {
newCol := ""
switch colIdx {
case 0:
newCol = "port"
case 1:
newCol = "proto"
case 2:
newCol = "addr"
case 3:
newCol = "state"
}
if newCol != "" {
if m.sortPortCol == newCol {
m.sortPortDesc = !m.sortPortDesc
} else {
m.sortPortCol = newCol
m.sortPortDesc = false
}
m.updatePortTable()
}
}
}
func (m *MainModel) handleContainerHeaderClick(x int) {
cols := m.containerTable.Columns()
colIdx := m.getColumnAtX(x, cols)
if colIdx >= 0 {
newCol := ""
switch colIdx {
case 0:
newCol = "id"
case 1:
newCol = "name"
case 2:
newCol = "runtime"
case 3:
newCol = "image"
case 4:
newCol = "status"
}
if newCol != "" {
if m.sortContainerCol == newCol {
m.sortContainerDesc = !m.sortContainerDesc
} else {
m.sortContainerCol = newCol
m.sortContainerDesc = false
}
m.updateContainerTable()
}
}
}
func (m *MainModel) handleLockHeaderClick(x int) {
cols := m.lockTable.Columns()
colIdx := m.getColumnAtX(x, cols)
if colIdx >= 0 {
newCol := ""
switch colIdx {
case 0:
newCol = "pid"
case 1:
newCol = "process"
case 2:
newCol = "type"
case 3:
newCol = "mode"
case 4:
newCol = "path"
}
if newCol != "" {
if m.sortLockCol == newCol {
m.sortLockDesc = !m.sortLockDesc
} else {
m.sortLockCol = newCol
m.sortLockDesc = false
}
m.updateLockTable()
}
}
}