MCPcopy
hub / github.com/pranshuparmar/witr / updateContainerTable

Method updateContainerTable

internal/tui/data.go:806–851  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

804}
805
806func (m *MainModel) updateContainerTable() {
807 m.sortContainers()
808 filter := strings.ToLower(strings.TrimSpace(m.containerInput.Value()))
809
810 // Preserve any width changes the WindowSizeMsg handler made (the trailing
811 // Command column flexes) before re-applying header arrows.
812 existing := m.containerTable.Columns()
813 newCols := m.getContainerColumns()
814 for i := range existing {
815 if i < len(newCols) {
816 newCols[i].Width = existing[i].Width
817 }
818 }
819 m.containerTable.SetColumns(newCols)
820
821 cols := m.containerTable.Columns()
822 w := func(i int) int {
823 if i < len(cols) {
824 return cols[i].Width
825 }
826 return 20
827 }
828
829 rows := make([]table.Row, 0, len(m.containers))
830 filtered := make([]*model.ContainerMatch, 0, len(m.containers))
831 for _, c := range m.containers {
832 if filter != "" {
833 haystack := strings.ToLower(c.ID + " " + c.Name + " " + c.Runtime + " " + c.Image + " " + c.Status + " " + c.Ports + " " + c.Command)
834 if !strings.Contains(haystack, filter) {
835 continue
836 }
837 }
838 rows = append(rows, table.Row{
839 output.SanitizeTerminalLine(output.ShortContainerID(c.ID)),
840 truncate(output.SanitizeTerminalLine(c.Name), w(1)),
841 output.SanitizeTerminalLine(c.Runtime),
842 truncateMiddle(output.SanitizeTerminalLine(c.Image), w(3)),
843 truncate(output.SanitizeTerminalLine(c.Status), w(4)),
844 truncate(output.SanitizeTerminalLine(c.Ports), w(5)),
845 truncateMiddle(output.SanitizeTerminalLine(c.Command), w(6)),
846 })
847 filtered = append(filtered, c)
848 }
849 m.containerTable.SetRows(rows)
850 m.filteredContainers = filtered
851}
852
853func truncate(s string, n int) string {
854 if len(s) <= n {

Callers 5

handleContainerListMethod · 0.95
handleListFilterInputMethod · 0.95
handleSortKeyMethod · 0.95
sizedFunction · 0.80

Calls 6

sortContainersMethod · 0.95
getContainerColumnsMethod · 0.95
SanitizeTerminalLineFunction · 0.92
ShortContainerIDFunction · 0.92
truncateFunction · 0.85
truncateMiddleFunction · 0.85

Tested by 1

sizedFunction · 0.64