Skip to content

Commit

Permalink
chore: run go fmt
Browse files Browse the repository at this point in the history
Signed-off-by: moncho <50428+moncho@users.noreply.github.com>
  • Loading branch information
moncho committed Feb 27, 2024
1 parent a7080ef commit f30637a
Show file tree
Hide file tree
Showing 65 changed files with 340 additions and 354 deletions.
2 changes: 1 addition & 1 deletion app/servicetasks_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app
import (
"fmt"

"github.com/moncho/dry/appui/swarm"
"github.com/gdamore/tcell"
"github.com/moncho/dry/appui/swarm"
)

type serviceTasksScreenEventHandler struct {
Expand Down
2 changes: 1 addition & 1 deletion app/stacktasks_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app
import (
"fmt"

"github.com/moncho/dry/appui/swarm"
"github.com/gdamore/tcell"
"github.com/moncho/dry/appui/swarm"
)

type stackTasksScreenEventHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions appui/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

var newLine = []byte{'\n'}

//NewContainerInfo returns detailed container information. Returned int value
//is the number of lines.
// NewContainerInfo returns detailed container information. Returned int value
// is the number of lines.
func NewContainerInfo(container *docker.Container) (string, int) {
var buffer bytes.Buffer
var status string
Expand Down
5 changes: 2 additions & 3 deletions appui/container_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package appui
import (
termui "github.com/gizak/termui"
"github.com/moncho/dry/docker"

drytermui "github.com/moncho/dry/ui/termui"
)

//ContainerDetailsWidget shows service information
// ContainerDetailsWidget shows service information
type ContainerDetailsWidget struct {
drytermui.SizableBufferer
}

//NewContainerDetailsWidget creates ContainerDetailsWidget with information about the service with the given ID
// NewContainerDetailsWidget creates ContainerDetailsWidget with information about the service with the given ID
func NewContainerDetailsWidget(container *docker.Container, y int) *ContainerDetailsWidget {
info, lines := NewContainerInfo(container)

Expand Down
3 changes: 1 addition & 2 deletions appui/container_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package appui
import (
"sync"

drytermui "github.com/moncho/dry/ui/termui"

gizaktermui "github.com/gizak/termui"
"github.com/moncho/dry/docker"
drytermui "github.com/moncho/dry/ui/termui"
)

type ContainerAPI interface {
Expand Down
16 changes: 8 additions & 8 deletions appui/container_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
statusSymbol = string('\u25A3')
)

//ContainerRow is a Grid row showing runtime information about a container
// ContainerRow is a Grid row showing runtime information about a container
type ContainerRow struct {
container *docker.Container
Indicator *drytermui.ParColumn
Expand All @@ -27,7 +27,7 @@ type ContainerRow struct {
drytermui.Row
}

//NewContainerRow creates a new ContainerRow widget
// NewContainerRow creates a new ContainerRow widget
func NewContainerRow(container *docker.Container, table drytermui.Table) *ContainerRow {
cf := formatter.NewContainerFormatter(container, true)

Expand Down Expand Up @@ -63,7 +63,7 @@ func NewContainerRow(container *docker.Container, table drytermui.Table) *Contai

}

//Buffer returns this Row data as a termui.Buffer
// Buffer returns this Row data as a termui.Buffer
func (row *ContainerRow) Buffer() termui.Buffer {
buf := termui.NewBuffer()
//This set the background of the whole row
Expand All @@ -77,19 +77,19 @@ func (row *ContainerRow) Buffer() termui.Buffer {
return buf
}

//ColumnsForFilter returns the columns that are used to filter
// ColumnsForFilter returns the columns that are used to filter
func (row *ContainerRow) ColumnsForFilter() []*drytermui.ParColumn {
return []*drytermui.ParColumn{row.ID, row.Image, row.Names, row.Command}
}

//Highlighted marks this rows as being highlighted
// Highlighted marks this rows as being highlighted
func (row *ContainerRow) Highlighted() {
row.changeTextColor(
termui.Attribute(DryTheme.Fg),
termui.Attribute(DryTheme.CursorLineBg))
}

//NotHighlighted marks this rows as being not highlighted
// NotHighlighted marks this rows as being not highlighted
func (row *ContainerRow) NotHighlighted() {
var fg termui.Attribute
if !docker.IsContainerRunning(row.container) {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (row *ContainerRow) changeTextColor(fg, bg termui.Attribute) {
row.Names.TextBgColor = bg
}

//markAsNotRunning
// markAsNotRunning
func (row *ContainerRow) markAsNotRunning() {
row.Indicator.TextFgColor = NotRunning
row.ID.TextFgColor = inactiveRowColor
Expand All @@ -131,7 +131,7 @@ func (row *ContainerRow) markAsNotRunning() {
row.running = false
}

//markAsRunning
// markAsRunning
func (row *ContainerRow) markAsRunning() {
row.Indicator.TextFgColor = Running
row.running = true
Expand Down
10 changes: 4 additions & 6 deletions appui/docker_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import (
"bytes"
"strconv"

termui "github.com/gizak/termui"
drytermui "github.com/moncho/dry/ui/termui"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-units"

termui "github.com/gizak/termui"
"github.com/moncho/dry/docker"
"github.com/moncho/dry/ui"
drytermui "github.com/moncho/dry/ui/termui"
"github.com/olekukonko/tablewriter"
)

//DockerInfo is a widget to show Docker info
// DockerInfo is a widget to show Docker info
type DockerInfo struct {
drytermui.SizableBufferer
}

//NewDockerInfo creates a DockerInfo widget
// NewDockerInfo creates a DockerInfo widget
func NewDockerInfo(daemon docker.ContainerDaemon) *DockerInfo {
di := drytermui.NewParFromMarkupText(DryTheme, dockerInfo(daemon))
di.BorderTop = false
Expand Down
2 changes: 1 addition & 1 deletion appui/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type eventsRenderer struct {
events []events.Message
}

//NewDockerEventsRenderer creates a renderer for docker events
// NewDockerEventsRenderer creates a renderer for docker events
func NewDockerEventsRenderer(events []events.Message) fmt.Stringer {
return &eventsRenderer{
events: events,
Expand Down
10 changes: 5 additions & 5 deletions appui/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ import (
// SortMode sort mode for widgets
type SortMode int

//SortableColumnHeader is a column header associated to a sort mode
// SortableColumnHeader is a column header associated to a sort mode
type SortableColumnHeader struct {
Title string // Title to display in the tableHeader.
Mode SortMode
}

//WidgetHeader is a widget for the header of a widget
// WidgetHeader is a widget for the header of a widget
type WidgetHeader struct {
elements map[string]string
keys []string
Y int
}

//NewWidgetHeader creates WidgetHeader
// NewWidgetHeader creates WidgetHeader
func NewWidgetHeader() *WidgetHeader {
return &WidgetHeader{
elements: make(map[string]string),
}
}

//HeaderEntry adds a new key-value entry to this header
// HeaderEntry adds a new key-value entry to this header
func (header *WidgetHeader) HeaderEntry(key, value string) {
header.keys = append(header.keys, key)
header.elements[key] = value
}

//GetHeight returns the widget height
// GetHeight returns the widget height
func (header *WidgetHeader) GetHeight() int {
return 1
}
Expand Down
7 changes: 3 additions & 4 deletions appui/image_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/go-units"
drydocker "github.com/moncho/dry/docker"

"github.com/moncho/dry/ui"
"github.com/olekukonko/tablewriter"
)

//DockerImageHistoryRenderer knows how render history image
// DockerImageHistoryRenderer knows how render history image
type DockerImageHistoryRenderer struct {
imageHistory []image.HistoryResponseItem
}

//NewDockerImageHistoryRenderer creates a renderer for the history of an image
// NewDockerImageHistoryRenderer creates a renderer for the history of an image
func NewDockerImageHistoryRenderer(imageHistory []image.HistoryResponseItem) fmt.Stringer {
return &DockerImageHistoryRenderer{imageHistory: imageHistory}
}

//Render docker ps
// Render docker ps
func (r *DockerImageHistoryRenderer) String() string {

buffer := new(bytes.Buffer)
Expand Down
6 changes: 3 additions & 3 deletions appui/image_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
drytermui "github.com/moncho/dry/ui/termui"
)

//ImageRow is a Grid row showing information about a Docker image
// ImageRow is a Grid row showing information about a Docker image
type ImageRow struct {
image types.ImageSummary
Repository *drytermui.ParColumn
Expand All @@ -21,7 +21,7 @@ type ImageRow struct {
Row
}

//NewImageRow creates a new ImageRow widget
// NewImageRow creates a new ImageRow widget
func NewImageRow(image types.ImageSummary, table drytermui.Table) *ImageRow {
iformatter := formatter.NewImageFormatter(image, true)

Expand Down Expand Up @@ -57,7 +57,7 @@ func NewImageRow(image types.ImageSummary, table drytermui.Table) *ImageRow {

}

//ColumnsForFilter returns the columns that are used to filter
// ColumnsForFilter returns the columns that are used to filter
func (row *ImageRow) ColumnsForFilter() []*drytermui.ParColumn {
return []*drytermui.ParColumn{row.Repository, row.Tag, row.ID}
}
35 changes: 17 additions & 18 deletions appui/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"strings"
"sync"

"github.com/docker/docker/api/types"

"github.com/docker/docker/api/types/image"
gizaktermui "github.com/gizak/termui"
"github.com/moncho/dry/docker"
"github.com/moncho/dry/ui/termui"
Expand All @@ -23,9 +22,9 @@ var imageTableHeaders = []SortableColumnHeader{
{`Size`, SortMode(docker.SortImagesBySize)},
}

//DockerImagesWidget knows how render a container list
// DockerImagesWidget knows how render a container list
type DockerImagesWidget struct {
images func() ([]types.ImageSummary, error)
images func() ([]image.Summary, error)
filteredRows []*ImageRow
totalRows []*ImageRow
filterPattern string
Expand All @@ -39,16 +38,16 @@ type DockerImagesWidget struct {
mounted bool
}

//NewDockerImagesWidget creates a widget to show Docker images.
func NewDockerImagesWidget(images func() ([]types.ImageSummary, error), s Screen) *DockerImagesWidget {
// NewDockerImagesWidget creates a widget to show Docker images.
func NewDockerImagesWidget(images func() ([]image.Summary, error), s Screen) *DockerImagesWidget {
return &DockerImagesWidget{
images: images,
header: defaultImageTableHeader,
screen: s,
sortMode: docker.SortImagesByRepo}
}

//Buffer returns the content of this widget as a termui.Buffer
// Buffer returns the content of this widget as a termui.Buffer
func (s *DockerImagesWidget) Buffer() gizaktermui.Buffer {
s.Lock()
defer s.Unlock()
Expand Down Expand Up @@ -87,14 +86,14 @@ func (s *DockerImagesWidget) Buffer() gizaktermui.Buffer {
return buf
}

//Filter filters the image list by the given filter
// Filter filters the image list by the given filter
func (s *DockerImagesWidget) Filter(filter string) {
s.Lock()
defer s.Unlock()
s.filterPattern = filter
}

//Mount tells this widget to be ready for rendering
// Mount tells this widget to be ready for rendering
func (s *DockerImagesWidget) Mount() error {
s.Lock()
defer s.Unlock()
Expand All @@ -117,26 +116,26 @@ func (s *DockerImagesWidget) Mount() error {
return nil
}

//Name returns this widget name
// Name returns this widget name
func (s *DockerImagesWidget) Name() string {
return "DockerImagesWidget"
}

//OnEvent runs the given command
// OnEvent runs the given command
func (s *DockerImagesWidget) OnEvent(event EventCommand) error {
if s.RowCount() > 0 {
return event(s.filteredRows[s.selectedIndex].image.ID)
}
return nil
}

//RowCount returns the number of rows of this widget.
// RowCount returns the number of rows of this widget.
func (s *DockerImagesWidget) RowCount() int {
return len(s.filteredRows)
}

//Sort rotates to the next sort mode.
//SortImagesByRepo -> SortImagesByID -> SortImagesByCreationDate -> SortImagesBySize -> SortImagesByRepo
// Sort rotates to the next sort mode.
// SortImagesByRepo -> SortImagesByID -> SortImagesByCreationDate -> SortImagesBySize -> SortImagesByRepo
func (s *DockerImagesWidget) Sort() {
s.RLock()
defer s.RUnlock()
Expand All @@ -153,15 +152,15 @@ func (s *DockerImagesWidget) Sort() {
s.mounted = false
}

//Unmount tells this widget that it will not be rendering anymore
// Unmount tells this widget that it will not be rendering anymore
func (s *DockerImagesWidget) Unmount() error {
s.RLock()
defer s.RUnlock()
s.mounted = false
return nil
}

//Align aligns rows
// Align aligns rows
func (s *DockerImagesWidget) align() {
x := s.screen.Bounds().Min.X
width := s.screen.Bounds().Dx()
Expand Down Expand Up @@ -228,8 +227,8 @@ func (s *DockerImagesWidget) calculateVisibleRows() {
}
}

//prepareForRendering sets the internal state of this widget so it is ready for
//rendering (i.e. Buffer()).
// prepareForRendering sets the internal state of this widget so it is ready for
// rendering (i.e. Buffer()).
func (s *DockerImagesWidget) prepareForRendering() {
s.sortRows()
s.filterRows()
Expand Down
1 change: 0 additions & 1 deletion appui/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/docker/docker/api/types"

"github.com/moncho/dry/mocks"
"github.com/moncho/dry/ui"
)
Expand Down
2 changes: 1 addition & 1 deletion appui/input.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package appui

//Input reads input
// Input reads input
func Input(done chan<- struct{}) {
done <- struct{}{}
}
Loading

0 comments on commit f30637a

Please sign in to comment.