forked from moncho/dry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add container information to menu widget
- Loading branch information
Showing
5 changed files
with
92 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
package appui | ||
|
||
import ( | ||
termui "github.com/gizak/termui" | ||
"github.com/moncho/dry/docker" | ||
|
||
drytermui "github.com/moncho/dry/ui/termui" | ||
) | ||
|
||
//ContainerDetailsWidget shows service information | ||
type ContainerDetailsWidget struct { | ||
container *docker.Container | ||
drytermui.SizableBufferer | ||
} | ||
|
||
//NewContainerDetailsWidget creates ContainerDetailsWidget with information about the service with the given ID | ||
func NewContainerDetailsWidget(container *docker.Container, y int) *ContainerDetailsWidget { | ||
w := ContainerDetailsWidget{} | ||
info, lines := NewContainerInfo(container) | ||
|
||
cInfo := drytermui.NewParFromMarkupText(DryTheme, info) | ||
cInfo.Y = y | ||
cInfo.Height = lines + 1 | ||
cInfo.BorderLeft = false | ||
cInfo.BorderRight = false | ||
cInfo.BorderTop = false | ||
|
||
cInfo.Bg = termui.Attribute(DryTheme.Bg) | ||
cInfo.BorderBg = termui.Attribute(DryTheme.Bg) | ||
cInfo.BorderFg = termui.Attribute(DryTheme.Footer) | ||
cInfo.TextBgColor = termui.Attribute(DryTheme.Bg) | ||
|
||
return &w | ||
return &ContainerDetailsWidget{cInfo} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package appui | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/network" | ||
"github.com/moncho/dry/docker" | ||
) | ||
|
||
func TestNewContainerDetailsWidget(t *testing.T) { | ||
type args struct { | ||
container *docker.Container | ||
y int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
"a widget with container details can be created", | ||
args{ | ||
&docker.Container{ | ||
Container: types.Container{ | ||
Names: []string{"container1"}, | ||
NetworkSettings: &types.SummaryNetworkSettings{ | ||
Networks: make(map[string]*network.EndpointSettings), | ||
}, | ||
}, | ||
ContainerJSON: types.ContainerJSON{ | ||
NetworkSettings: &types.NetworkSettings{ | ||
Networks: make(map[string]*network.EndpointSettings), | ||
}, | ||
}, | ||
}, | ||
0, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
w := NewContainerDetailsWidget(tt.args.container, tt.args.y) | ||
|
||
if w == nil { | ||
t.Error("ContainerDetailsWidget was not created") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters