Skip to content

Commit

Permalink
View sub dialog size adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Navid Yaghoobi <[email protected]>
  • Loading branch information
navidys committed Mar 7, 2025
1 parent cfd827a commit 34a7797
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 82 deletions.
6 changes: 3 additions & 3 deletions ui/containers/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (cnt *Containers) diff() {

cnt.messageDialog.SetTitle("podman container diff")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, strings.Join(data, "\n"))
cnt.messageDialog.Display()
cnt.messageDialog.DisplayFullSize()
}

func (cnt *Containers) inspect() {
Expand All @@ -601,7 +601,7 @@ func (cnt *Containers) inspect() {

cnt.messageDialog.SetTitle("podman container inspect")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, data)
cnt.messageDialog.Display()
cnt.messageDialog.DisplayFullSize()
}

func (cnt *Containers) kill() {
Expand Down Expand Up @@ -663,7 +663,7 @@ func (cnt *Containers) logs() {
cnt.messageDialog.SetTitle("podman container logs")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, cntLogs)
cnt.messageDialog.TextScrollToEnd()
cnt.messageDialog.Display()
cnt.messageDialog.DisplayFullSize()
}

go getLogs()
Expand Down
7 changes: 6 additions & 1 deletion ui/containers/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ func (cnt *Containers) Draw(screen tcell.Screen) { //nolint:cyclop

// message dialog
if cnt.messageDialog.IsDisplay() {
cnt.messageDialog.SetRect(x, y, width, height+1)
if cnt.messageDialog.IsDisplayFullSize() {
cnt.messageDialog.SetRect(cntViewX, cntViewY, cntViewW, cntViewH)
} else {
cnt.messageDialog.SetRect(x, y, width, height+1)
}

cnt.messageDialog.Draw(screen)

return
Expand Down
49 changes: 36 additions & 13 deletions ui/dialogs/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (
// MessageDialog is a simaple message dialog primitive.
type MessageDialog struct {
*tview.Box
layout *tview.Flex
infoType *tview.InputField
textview *tview.TextView
form *tview.Form
display bool
message string
cancelHandler func()
layout *tview.Flex
infoType *tview.InputField
textview *tview.TextView
form *tview.Form
display bool
displayFullSize bool
message string
cancelHandler func()
}

type messageInfo int
Expand All @@ -38,10 +39,11 @@ const (
// NewMessageDialog returns new message dialog primitive.
func NewMessageDialog(text string) *MessageDialog {
dialog := &MessageDialog{
Box: tview.NewBox(),
infoType: tview.NewInputField(),
display: false,
message: text,
Box: tview.NewBox(),
infoType: tview.NewInputField(),
display: false,
displayFullSize: false,
message: text,
}

dialog.infoType.SetBackgroundColor(style.DialogBgColor)
Expand All @@ -65,7 +67,6 @@ func NewMessageDialog(text string) *MessageDialog {
tlayout.AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 1, 0, false)
tlayout.AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(dialog.infoType, 1, 0, false).
AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 1, 0, false).
AddItem(dialog.textview, 0, 1, true),
0, 1, true)
tlayout.AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 1, 0, false)
Expand All @@ -78,7 +79,6 @@ func NewMessageDialog(text string) *MessageDialog {
dialog.form.SetButtonBackgroundColor(style.ButtonBgColor)

dialog.layout = tview.NewFlex().SetDirection(tview.FlexRow)
dialog.layout.AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 1, 0, true)
dialog.layout.AddItem(tlayout, 0, 1, true)
dialog.layout.AddItem(dialog.form, DialogFormHeight, 0, true)
dialog.layout.SetBorder(true)
Expand All @@ -91,13 +91,25 @@ func NewMessageDialog(text string) *MessageDialog {
// Display displays this primitive.
func (d *MessageDialog) Display() {
d.display = true
d.displayFullSize = false
}

// DisplayFullSize displays this primitive in full size.
func (d *MessageDialog) DisplayFullSize() {
d.display = true
d.displayFullSize = true
}

// IsDisplay returns true if primitive is shown.
func (d *MessageDialog) IsDisplay() bool {
return d.display
}

// IsDisplayFullSize returns true if primitive is shown in full size.
func (d *MessageDialog) IsDisplayFullSize() bool {
return d.displayFullSize
}

// Hide stops displaying this primitive.
func (d *MessageDialog) Hide() {
d.message = ""
Expand Down Expand Up @@ -169,6 +181,17 @@ func (d *MessageDialog) HasFocus() bool {

// SetRect set rects for this primitive.
func (d *MessageDialog) SetRect(x, y, width, height int) {
if d.displayFullSize {
dX := x + 1
dY := y + 1
dWidth := width - 2 //nolint:mnd
dHeight := height - 2 //nolint:mnd

d.Box.SetRect(dX, dY, dWidth, dHeight)

return
}

messageHeight := 0
if d.message != "" {
messageHeight = len(strings.Split(d.message, "\n")) + 3 //nolint:mnd
Expand Down
4 changes: 2 additions & 2 deletions ui/images/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (img *Images) diff() {

img.messageDialog.SetTitle("podman image diff")
img.messageDialog.SetText(dialogs.MessageImageInfo, headerLabel, strings.Join(data, "\n"))
img.messageDialog.Display()
img.messageDialog.DisplayFullSize()
}

go diff()
Expand Down Expand Up @@ -192,7 +192,7 @@ func (img *Images) inspect() {

img.messageDialog.SetTitle("podman image inspect")
img.messageDialog.SetText(dialogs.MessageImageInfo, headerLabel, data)
img.messageDialog.Display()
img.messageDialog.DisplayFullSize()
}

func (img *Images) cprune() {
Expand Down
17 changes: 11 additions & 6 deletions ui/images/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ func (img *Images) Draw(screen tcell.Screen) { //nolint:cyclop
img.Box.DrawForSubclass(screen, img)
img.Box.SetBorder(false)

x, y, width, height := img.GetInnerRect()
imagewViewX, imagewViewY, imagewViewW, imagewViewH := img.GetInnerRect()

img.table.SetRect(x, y, width, height)
img.table.SetRect(imagewViewX, imagewViewY, imagewViewW, imagewViewH)
img.table.SetBorder(true)

img.table.Draw(screen)
x, y, width, height = img.table.GetInnerRect()
x, y, width, height := img.table.GetInnerRect()

// error dialog
if img.errorDialog.IsDisplay() {
Expand Down Expand Up @@ -44,7 +44,12 @@ func (img *Images) Draw(screen tcell.Screen) { //nolint:cyclop

// message dialog
if img.messageDialog.IsDisplay() {
img.messageDialog.SetRect(x, y, width, height+1)
if img.messageDialog.IsDisplayFullSize() {
img.messageDialog.SetRect(imagewViewX, imagewViewY, imagewViewW, imagewViewH)
} else {
img.messageDialog.SetRect(x, y, width, height+1)
}

img.messageDialog.Draw(screen)

return
Expand All @@ -60,7 +65,7 @@ func (img *Images) Draw(screen tcell.Screen) { //nolint:cyclop

// search dialog
if img.searchDialog.IsDisplay() {
img.searchDialog.SetRect(x, y, width, height)
img.searchDialog.SetRect(imagewViewX, imagewViewY, imagewViewW, imagewViewH)
img.searchDialog.Draw(screen)
}

Expand All @@ -72,7 +77,7 @@ func (img *Images) Draw(screen tcell.Screen) { //nolint:cyclop

// history dialog
if img.historyDialog.IsDisplay() {
img.historyDialog.SetRect(x, y, width, height)
img.historyDialog.SetRect(imagewViewX, imagewViewY, imagewViewW, imagewViewH)
img.historyDialog.Draw(screen)

return
Expand Down
18 changes: 5 additions & 13 deletions ui/images/imgdialogs/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,15 @@ func (d *ImageHistoryDialog) InputHandler() func(event *tcell.EventKey, setFocus

// SetRect set rects for this primitive.
func (d *ImageHistoryDialog) SetRect(x, y, width, height int) {
dX := x + dialogs.DialogPadding
dWidth := width - (2 * dialogs.DialogPadding) //nolint:mnd
dHeight := len(d.results) + dialogs.DialogFormHeight + 5 //nolint:mnd

if dHeight > height {
dHeight = height
}

tableHeight := dHeight - dialogs.DialogFormHeight - 2 //nolint:mnd

hs := ((height - dHeight) / 2) //nolint:mnd
dY := y + hs
dX := x + 1
dY := y + 1
dWidth := width - 2 //nolint:mnd
dHeight := height - 2 //nolint:mnd

d.Box.SetRect(dX, dY, dWidth, dHeight)

// set table height size
d.layout.ResizeItem(d.table, tableHeight, 0)
d.layout.ResizeItem(d.table, dHeight, 0)
cWidth := d.getCreatedByWidth()

for i := range d.table.GetRowCount() {
Expand Down
2 changes: 1 addition & 1 deletion ui/networks/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (nets *Networks) inspect() {

nets.messageDialog.SetTitle("podman network inspect")
nets.messageDialog.SetText(dialogs.MessageNetworkInfo, headerLabel, data)
nets.messageDialog.Display()
nets.messageDialog.DisplayFullSize()
}

func (nets *Networks) cprune() {
Expand Down
13 changes: 9 additions & 4 deletions ui/networks/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ func (nets *Networks) Draw(screen tcell.Screen) {
nets.Box.DrawForSubclass(screen, nets)
nets.Box.SetBorder(false)

x, y, width, height := nets.GetInnerRect()
netViewX, netViewY, netViewW, netViewH := nets.GetInnerRect()

nets.table.SetRect(x, y, width, height)
nets.table.SetRect(netViewX, netViewY, netViewW, netViewH)
nets.table.SetBorder(true)

nets.table.Draw(screen)

x, y, width, height = nets.table.GetInnerRect()
x, y, width, height := nets.table.GetInnerRect()

// error dialog
if nets.errorDialog.IsDisplay() {
Expand Down Expand Up @@ -60,7 +60,12 @@ func (nets *Networks) Draw(screen tcell.Screen) {

// message dialog
if nets.messageDialog.IsDisplay() {
nets.messageDialog.SetRect(x, y, width, height+1)
if nets.messageDialog.IsDisplayFullSize() {
nets.messageDialog.SetRect(netViewX, netViewY, netViewW, netViewH)
} else {
nets.messageDialog.SetRect(x, y, width, height+1)
}

nets.messageDialog.Draw(screen)

return
Expand Down
2 changes: 1 addition & 1 deletion ui/pods/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *Pods) inspect() {

p.messageDialog.SetTitle("podman pod inspect")
p.messageDialog.SetText(dialogs.MessagePodInfo, headerLabel, data)
p.messageDialog.Display()
p.messageDialog.DisplayFullSize()
}

func (p *Pods) kill() {
Expand Down
15 changes: 10 additions & 5 deletions ui/pods/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ func (pods *Pods) Draw(screen tcell.Screen) {
pods.Box.DrawForSubclass(screen, pods)
pods.Box.SetBorder(false)

x, y, width, height := pods.GetInnerRect()
podViewX, podViewY, podViewW, podViewH := pods.GetInnerRect()

pods.table.SetRect(x, y, width, height)
pods.table.SetRect(podViewX, podViewY, podViewW, podViewH)
pods.table.SetBorder(true)

pods.table.Draw(screen)

x, y, width, height = pods.table.GetInnerRect()
x, y, width, height := pods.table.GetInnerRect()

// error dialog
if pods.errorDialog.IsDisplay() {
Expand Down Expand Up @@ -53,7 +53,12 @@ func (pods *Pods) Draw(screen tcell.Screen) {

// message dialog
if pods.messageDialog.IsDisplay() {
pods.messageDialog.SetRect(x, y, width, height+1)
if pods.messageDialog.IsDisplayFullSize() {
pods.messageDialog.SetRect(podViewX, podViewY, podViewW, podViewH)
} else {
pods.messageDialog.SetRect(x, y, width, height+1)
}

pods.messageDialog.Draw(screen)

return
Expand All @@ -75,7 +80,7 @@ func (pods *Pods) Draw(screen tcell.Screen) {

// stats dialogs
if pods.statsDialog.IsDisplay() {
pods.statsDialog.SetRect(x, y, width, height)
pods.statsDialog.SetRect(podViewX, podViewY, podViewW, podViewH)
pods.statsDialog.Draw(screen)

return
Expand Down
8 changes: 4 additions & 4 deletions ui/pods/poddialogs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ func (d *PodStatsDialog) Draw(screen tcell.Screen) {

// SetRect set rects for this primitive.
func (d *PodStatsDialog) SetRect(x, y, width, height int) {
dX := x + dialogs.DialogPadding
dY := y + dialogs.DialogPadding - 1
dWidth := width - (2 * dialogs.DialogPadding) //nolint:mnd
dHeight := height - (2 * (dialogs.DialogPadding - 1)) //nolint:mnd
dX := x + 1
dY := y + 1
dWidth := width - 2 //nolint:mnd
dHeight := height - 2 //nolint:mnd

d.Box.SetRect(dX, dY, dWidth, dHeight)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/secrets/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *Secrets) inspect() {

s.messageDialog.SetTitle("podman secret inspect")
s.messageDialog.SetText(dialogs.MessageSecretInfo, headerLabel, data)
s.messageDialog.Display()
s.messageDialog.DisplayFullSize()
}

func (s *Secrets) rm() {
Expand Down
13 changes: 9 additions & 4 deletions ui/secrets/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ func (s *Secrets) Draw(screen tcell.Screen) {
s.Box.DrawForSubclass(screen, s)
s.Box.SetBorder(false)

x, y, width, height := s.GetInnerRect()
secretViewX, secretViewY, secretViewW, secretViewH := s.GetInnerRect()

s.table.SetRect(x, y, width, height)
s.table.SetRect(secretViewX, secretViewY, secretViewW, secretViewH)
s.table.SetBorder(true)
s.table.Draw(screen)

x, y, width, height = s.table.GetInnerRect()
x, y, width, height := s.table.GetInnerRect()

// error dialog
if s.errorDialog.IsDisplay() {
Expand All @@ -31,7 +31,12 @@ func (s *Secrets) Draw(screen tcell.Screen) {

// message dialog
if s.messageDialog.IsDisplay() {
s.messageDialog.SetRect(x, y, width, height+1)
if s.messageDialog.IsDisplayFullSize() {
s.messageDialog.SetRect(secretViewX, secretViewY, secretViewW, secretViewH)
} else {
s.messageDialog.SetRect(x, y, width, height+1)
}

s.messageDialog.Draw(screen)

return
Expand Down
2 changes: 1 addition & 1 deletion ui/system/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (sys *System) info() {

sys.messageDialog.SetTitle("SYSTEM INFORMATION")
sys.messageDialog.SetText(dialogs.MessageSystemInfo, connName, data)
sys.messageDialog.Display()
sys.messageDialog.DisplayFullSize()
}

func (sys *System) cprune() {
Expand Down
Loading

0 comments on commit 34a7797

Please sign in to comment.