mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
preparing to refactor main render functions
This commit is contained in:
parent
7324254414
commit
5ffbeae3e8
6 changed files with 99 additions and 74 deletions
|
|
@ -119,13 +119,16 @@ func sortContainers(a *commands.Container, b *commands.Container, legacySort boo
|
|||
return containerStates[a.Container.State] < containerStates[b.Container.State]
|
||||
}
|
||||
|
||||
func (gui *Gui) renderContainerEnv(container *commands.Container) error {
|
||||
if !container.DetailsLoaded() {
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
_ = gui.RenderStringMain(gui.Tr.WaitingForContainerInfo)
|
||||
})
|
||||
}
|
||||
type MainRenderTask struct {
|
||||
Wrap bool
|
||||
Autoscroll bool
|
||||
|
||||
StrContent string
|
||||
|
||||
// TicketTask
|
||||
}
|
||||
|
||||
func (gui *Gui) renderContainerEnv(container *commands.Container) error {
|
||||
mainView := gui.Views.Main
|
||||
mainView.Autoscroll = false
|
||||
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
||||
|
|
@ -135,7 +138,14 @@ func (gui *Gui) renderContainerEnv(container *commands.Container) error {
|
|||
})
|
||||
}
|
||||
|
||||
// I want a struct that gets returned explaining what needs to happen. So for example,
|
||||
// autoscroll: true, wrap: true, content: string
|
||||
|
||||
func (gui *Gui) containerEnv(container *commands.Container) string {
|
||||
if !container.DetailsLoaded() {
|
||||
return gui.Tr.WaitingForContainerInfo
|
||||
}
|
||||
|
||||
if len(container.Details.Config.Env) == 0 {
|
||||
return gui.Tr.NothingToDisplay
|
||||
}
|
||||
|
|
@ -163,16 +173,20 @@ func (gui *Gui) containerEnv(container *commands.Container) string {
|
|||
}
|
||||
|
||||
func (gui *Gui) renderContainerConfig(container *commands.Container) error {
|
||||
if !container.DetailsLoaded() {
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
_ = gui.RenderStringMain(gui.Tr.WaitingForContainerInfo)
|
||||
})
|
||||
}
|
||||
|
||||
mainView := gui.Views.Main
|
||||
mainView.Autoscroll = false
|
||||
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
||||
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
_ = gui.RenderStringMain(gui.containerConfigStr(container))
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) containerConfigStr(container *commands.Container) string {
|
||||
if !container.DetailsLoaded() {
|
||||
return gui.Tr.WaitingForContainerInfo
|
||||
}
|
||||
|
||||
padding := 10
|
||||
output := ""
|
||||
output += utils.WithPadding("ID: ", padding) + container.ID + "\n"
|
||||
|
|
@ -210,13 +224,12 @@ func (gui *Gui) renderContainerConfig(container *commands.Container) error {
|
|||
|
||||
data, err := json.MarshalIndent(&container.Details, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Sprintf("Error marshalling container details: %v", err)
|
||||
}
|
||||
|
||||
output += fmt.Sprintf("\nFull details:\n\n%s", string(data))
|
||||
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
_ = gui.RenderStringMain(output)
|
||||
})
|
||||
return output
|
||||
}
|
||||
|
||||
func (gui *Gui) renderContainerStats(container *commands.Container) error {
|
||||
|
|
|
|||
|
|
@ -68,29 +68,33 @@ func (gui *Gui) getImagesPanel() *panels.SideListPanel[*commands.Image] {
|
|||
|
||||
func (gui *Gui) renderImageConfig(image *commands.Image) error {
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
padding := 10
|
||||
output := ""
|
||||
output += utils.WithPadding("Name: ", padding) + image.Name + "\n"
|
||||
output += utils.WithPadding("ID: ", padding) + image.Image.ID + "\n"
|
||||
output += utils.WithPadding("Tags: ", padding) + utils.ColoredString(strings.Join(image.Image.RepoTags, ", "), color.FgGreen) + "\n"
|
||||
output += utils.WithPadding("Size: ", padding) + utils.FormatDecimalBytes(int(image.Image.Size)) + "\n"
|
||||
output += utils.WithPadding("Created: ", padding) + fmt.Sprintf("%v", time.Unix(image.Image.Created, 0).Format(time.RFC1123)) + "\n"
|
||||
|
||||
history, err := image.RenderHistory()
|
||||
if err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
output += "\n\n" + history
|
||||
|
||||
mainView := gui.Views.Main
|
||||
mainView.Autoscroll = false
|
||||
mainView.Wrap = false // don't care what your config is this page is ugly without wrapping
|
||||
|
||||
_ = gui.RenderStringMain(output)
|
||||
_ = gui.RenderStringMain(gui.imageConfigStr(image))
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) imageConfigStr(image *commands.Image) string {
|
||||
padding := 10
|
||||
output := ""
|
||||
output += utils.WithPadding("Name: ", padding) + image.Name + "\n"
|
||||
output += utils.WithPadding("ID: ", padding) + image.Image.ID + "\n"
|
||||
output += utils.WithPadding("Tags: ", padding) + utils.ColoredString(strings.Join(image.Image.RepoTags, ", "), color.FgGreen) + "\n"
|
||||
output += utils.WithPadding("Size: ", padding) + utils.FormatDecimalBytes(int(image.Image.Size)) + "\n"
|
||||
output += utils.WithPadding("Created: ", padding) + fmt.Sprintf("%v", time.Unix(image.Image.Created, 0).Format(time.RFC1123)) + "\n"
|
||||
|
||||
history, err := image.RenderHistory()
|
||||
if err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
output += "\n\n" + history
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
func (gui *Gui) reloadImages() error {
|
||||
if err := gui.refreshStateImages(); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -95,25 +95,27 @@ func (gui *Gui) renderCredits(_project *commands.Project) error {
|
|||
mainView.Autoscroll = false
|
||||
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
||||
|
||||
var configBuf bytes.Buffer
|
||||
_ = yaml.NewEncoder(&configBuf, yaml.IncludeOmitted).Encode(gui.Config.UserConfig)
|
||||
|
||||
dashboardString := strings.Join(
|
||||
[]string{
|
||||
lazydockerTitle(),
|
||||
"Copyright (c) 2019 Jesse Duffield",
|
||||
"Keybindings: https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings",
|
||||
"Config Options: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md",
|
||||
"Raise an Issue: https://github.com/jesseduffield/lazydocker/issues",
|
||||
utils.ColoredString("Buy Jesse a coffee: https://github.com/sponsors/jesseduffield", color.FgMagenta), // caffeine ain't free
|
||||
"Here's your lazydocker config when merged in with the defaults (you can open your config by pressing 'o'):",
|
||||
configBuf.String(),
|
||||
}, "\n\n")
|
||||
|
||||
_ = gui.RenderStringMain(dashboardString)
|
||||
_ = gui.RenderStringMain(gui.creditsStr())
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) creditsStr() string {
|
||||
var configBuf bytes.Buffer
|
||||
_ = yaml.NewEncoder(&configBuf, yaml.IncludeOmitted).Encode(gui.Config.UserConfig)
|
||||
|
||||
return strings.Join(
|
||||
[]string{
|
||||
lazydockerTitle(),
|
||||
"Copyright (c) 2019 Jesse Duffield",
|
||||
"Keybindings: https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings",
|
||||
"Config Options: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md",
|
||||
"Raise an Issue: https://github.com/jesseduffield/lazydocker/issues",
|
||||
utils.ColoredString("Buy Jesse a coffee: https://github.com/sponsors/jesseduffield", color.FgMagenta), // caffeine ain't free
|
||||
"Here's your lazydocker config when merged in with the defaults (you can open your config by pressing 'o'):",
|
||||
configBuf.String(),
|
||||
}, "\n\n")
|
||||
}
|
||||
|
||||
func (gui *Gui) renderAllLogs(_project *commands.Project) error {
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
mainView := gui.Views.Main
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func (gui *Gui) renderServiceTop(service *commands.Service) error {
|
|||
func (gui *Gui) renderServiceLogs(service *commands.Service) error {
|
||||
if service.Container == nil {
|
||||
return gui.T.NewTask(func(stop chan struct{}) {
|
||||
gui.clearMainView()
|
||||
gui.reRenderStringMain(gui.Tr.NoContainerForService)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,34 +58,38 @@ func (gui *Gui) renderVolumeConfig(volume *commands.Volume) error {
|
|||
mainView.Autoscroll = false
|
||||
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
||||
|
||||
padding := 15
|
||||
output := ""
|
||||
output += utils.WithPadding("Name: ", padding) + volume.Name + "\n"
|
||||
output += utils.WithPadding("Driver: ", padding) + volume.Volume.Driver + "\n"
|
||||
output += utils.WithPadding("Scope: ", padding) + volume.Volume.Scope + "\n"
|
||||
output += utils.WithPadding("Mountpoint: ", padding) + volume.Volume.Mountpoint + "\n"
|
||||
output += utils.WithPadding("Labels: ", padding) + utils.FormatMap(padding, volume.Volume.Labels) + "\n"
|
||||
output += utils.WithPadding("Options: ", padding) + utils.FormatMap(padding, volume.Volume.Options) + "\n"
|
||||
|
||||
output += utils.WithPadding("Status: ", padding)
|
||||
if volume.Volume.Status != nil {
|
||||
output += "\n"
|
||||
for k, v := range volume.Volume.Status {
|
||||
output += utils.FormatMapItem(padding, k, v)
|
||||
}
|
||||
} else {
|
||||
output += "n/a"
|
||||
}
|
||||
|
||||
if volume.Volume.UsageData != nil {
|
||||
output += utils.WithPadding("RefCount: ", padding) + fmt.Sprintf("%d", volume.Volume.UsageData.RefCount) + "\n"
|
||||
output += utils.WithPadding("Size: ", padding) + utils.FormatBinaryBytes(int(volume.Volume.UsageData.Size)) + "\n"
|
||||
}
|
||||
|
||||
_ = gui.RenderStringMain(output)
|
||||
_ = gui.RenderStringMain(gui.volumeConfigStr(volume))
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) volumeConfigStr(volume *commands.Volume) string {
|
||||
padding := 15
|
||||
output := ""
|
||||
output += utils.WithPadding("Name: ", padding) + volume.Name + "\n"
|
||||
output += utils.WithPadding("Driver: ", padding) + volume.Volume.Driver + "\n"
|
||||
output += utils.WithPadding("Scope: ", padding) + volume.Volume.Scope + "\n"
|
||||
output += utils.WithPadding("Mountpoint: ", padding) + volume.Volume.Mountpoint + "\n"
|
||||
output += utils.WithPadding("Labels: ", padding) + utils.FormatMap(padding, volume.Volume.Labels) + "\n"
|
||||
output += utils.WithPadding("Options: ", padding) + utils.FormatMap(padding, volume.Volume.Options) + "\n"
|
||||
|
||||
output += utils.WithPadding("Status: ", padding)
|
||||
if volume.Volume.Status != nil {
|
||||
output += "\n"
|
||||
for k, v := range volume.Volume.Status {
|
||||
output += utils.FormatMapItem(padding, k, v)
|
||||
}
|
||||
} else {
|
||||
output += "n/a"
|
||||
}
|
||||
|
||||
if volume.Volume.UsageData != nil {
|
||||
output += utils.WithPadding("RefCount: ", padding) + fmt.Sprintf("%d", volume.Volume.UsageData.RefCount) + "\n"
|
||||
output += utils.WithPadding("Size: ", padding) + utils.FormatBinaryBytes(int(volume.Volume.UsageData.Size)) + "\n"
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
func (gui *Gui) reloadVolumes() error {
|
||||
if err := gui.refreshStateVolumes(); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ type TranslationSet struct {
|
|||
ContainerConfigTitle string
|
||||
ContainerEnvTitle string
|
||||
NothingToDisplay string
|
||||
NoContainerForService string
|
||||
CannotDisplayEnvVariables string
|
||||
|
||||
No string
|
||||
|
|
@ -220,6 +221,7 @@ func englishSet() TranslationSet {
|
|||
ContainerConfigTitle: "Container Config",
|
||||
ContainerEnvTitle: "Container Env",
|
||||
NothingToDisplay: "Nothing to display",
|
||||
NoContainerForService: "No logs to show; service is not associated with a container",
|
||||
CannotDisplayEnvVariables: "Something went wrong while displaying environment variables",
|
||||
|
||||
NoContainers: "No containers",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue