@@ -3,6 +3,8 @@ package tui
33import (
44 "fmt"
55 "strings"
6+
7+ "github.com/shubh-io/dockmate/internal/docker"
68)
79
810func (m model ) renderInfoPanel (width int ) string {
@@ -11,18 +13,49 @@ func (m model) renderInfoPanel(width int) string {
1113 b .WriteString (dividerStyle .Render (strings .Repeat ("─" , width )))
1214 b .WriteString ("\n " )
1315
16+ id := m .infoContainerID
17+ if id == "" && m .infoContainer != nil {
18+ id = m .infoContainer .ID
19+ }
20+
21+ var container * docker.Container
22+
23+ if id != "" {
24+
25+ for _ , p := range m .projects {
26+ for i := range p .Containers {
27+ if p .Containers [i ].ID == id {
28+ container = & p .Containers [i ]
29+ break
30+ }
31+ }
32+ if container != nil {
33+ break
34+ }
35+ }
36+ if container == nil {
37+ for i := range m .containers {
38+ if m .containers [i ].ID == id {
39+ container = & m .containers [i ]
40+ break
41+ }
42+ }
43+ }
44+ }
45+
1446 containerName := ""
15- if m . infoContainer != nil && len (m . infoContainer .Names ) > 0 {
16- containerName = m . infoContainer .Names [0 ]
47+ if container != nil && len (container .Names ) > 0 {
48+ containerName = container .Names [0 ]
1749 }
50+
1851 infoTitle := fmt .Sprintf ("Container Info: %s " , containerName )
1952 if visibleLen (infoTitle ) < width {
2053 infoTitle += strings .Repeat (" " , width - visibleLen (infoTitle ))
2154 }
2255 b .WriteString (titleStyle .Render (infoTitle ))
2356 b .WriteString ("\n " )
2457
25- if m . infoContainer == nil {
58+ if container == nil {
2659 noContainerMsg := " No container selected"
2760 if visibleLen (noContainerMsg ) < width {
2861 noContainerMsg += strings .Repeat (" " , width - visibleLen (noContainerMsg ))
@@ -32,56 +65,61 @@ func (m model) renderInfoPanel(width int) string {
3265 return b .String ()
3366 }
3467
35- c := m .infoContainer
36-
3768 // Display container information fields
3869 infoFields := []struct {
3970 label string
4071 value string
4172 }{
42- {"Container ID" , c .ID },
73+ {"Container ID" , container .ID },
4374 {"Name" , containerName },
44- {"Image" , c .Image },
45- {"Status" , c .Status },
46- {"State" , c .State },
47- {"CPU Usage" , c .CPU },
48- {"Memory Usage" , c .Memory },
49- {"Network I/O" , c .NetIO },
50- {"Block I/O" , c .BlockIO },
51- {"Ports" , c .Ports },
75+ {"Image" , container .Image },
76+ {"Status" , container .Status },
77+ {"State" , container .State },
78+ {"CPU Usage" , container .CPU },
79+ {"Memory Usage" , container .Memory },
80+ {"Network I/O" , container .NetIO },
81+ {"Block I/O" , container .BlockIO },
82+ {"Ports" , container .Ports },
83+ // {"Compose Project", container.ComposeProject},
84+ // {"Compose File Directory", container.ComposeFileDirectory},
85+ // {"Compose Directory", container.ComposeDirectory},
86+ // {"Compose Service", container.ComposeService},
5287 }
5388
5489 // Add compose-specific fields if available
55- if c .ComposeProject != "" {
90+ if container .ComposeProject != "" {
5691 infoFields = append (infoFields , struct {
5792 label string
5893 value string
59- }{"Compose Project" , c .ComposeProject })
94+ }{"Compose Project" , container .ComposeProject })
6095 }
61- if c .ComposeDirectory != "" {
96+ if container .ComposeDirectory != "" {
6297 infoFields = append (infoFields , struct {
6398 label string
6499 value string
65- }{"Compose Directory" , c .ComposeDirectory })
100+ }{"Compose Directory" , container .ComposeDirectory })
66101 }
67- if c .ComposeFileDirectory != "" {
102+ if container .ComposeFileDirectory != "" {
68103 infoFields = append (infoFields , struct {
69104 label string
70105 value string
71- }{"Compose File Directory" , c .ComposeFileDirectory })
106+ }{"Compose File Directory" , container .ComposeFileDirectory })
72107 }
73- if c .ComposeService != "" {
108+ if container .ComposeService != "" {
74109 infoFields = append (infoFields , struct {
75110 label string
76111 value string
77- }{"Compose Service" , c .ComposeService })
112+ }{"Compose Service" , container .ComposeService })
113+ }
114+ panelHeight := m .infoPanelHeight
115+ if container != nil && container .ComposeFileDirectory == "" {
116+ panelHeight -= 4
78117 }
79118
80- maxInfoLines := m . infoPanelHeight - 2 // account for divider and title
119+ maxInfoLines := panelHeight - 2 // account for divider and title
81120 if maxInfoLines < 1 {
82121 maxInfoLines = 1
83122 }
84-
85123 // Render info fields with wrapping
86124 renderedLines := 0
87125 for _ , field := range infoFields {
0 commit comments