2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-03 05:12:01 +08:00

(cli): Fix withModal helper

This commit is contained in:
Ken Hibino
2022-05-27 15:26:18 -07:00
parent f105a2c3c3
commit 19411c538a

View File

@@ -614,7 +614,6 @@ type rowContent struct {
} }
func withModal(d *ScreenDrawer, contents []*rowContent) { func withModal(d *ScreenDrawer, contents []*rowContent) {
modalStyle := baseStyle //.Background(tcell.ColorDarkMagenta)
w, h := d.Screen().Size() w, h := d.Screen().Size()
var ( var (
modalWidth = int(math.Floor(float64(w) * 0.6)) modalWidth = int(math.Floor(float64(w) * 0.6))
@@ -626,26 +625,27 @@ func withModal(d *ScreenDrawer, contents []*rowContent) {
return // no content can be shown return // no content can be shown
} }
d.Goto(colOffset, rowOffset) d.Goto(colOffset, rowOffset)
d.Print(string(tcell.RuneULCorner), modalStyle) d.Print(string(tcell.RuneULCorner), baseStyle)
d.Print(strings.Repeat(string(tcell.RuneHLine), modalWidth-2), modalStyle) d.Print(strings.Repeat(string(tcell.RuneHLine), modalWidth-2), baseStyle)
d.Print(string(tcell.RuneURCorner), modalStyle) d.Print(string(tcell.RuneURCorner), baseStyle)
d.NL() d.NL()
contentWidth := modalWidth - 4 /* borders + paddings */
for i := 1; i < modalHeight-1; i++ { for i := 1; i < modalHeight-1; i++ {
d.Goto(colOffset, rowOffset+i) d.Goto(colOffset, rowOffset+i)
d.Print(string(tcell.RuneVLine), modalStyle) d.Print(fmt.Sprintf("%c ", tcell.RuneVLine), baseStyle)
cnt := &rowContent{strings.Repeat(" ", modalWidth-2), baseStyle} cnt := &rowContent{strings.Repeat(" ", contentWidth), baseStyle}
if i <= len(contents) { if i <= len(contents) {
cnt = contents[i-1] cnt = contents[i-1]
cnt.s = adjustWidth(cnt.s, modalWidth-2) cnt.s = adjustWidth(cnt.s, contentWidth)
} }
d.Print(truncate(cnt.s, modalWidth-2), cnt.style) d.Print(truncate(cnt.s, contentWidth), cnt.style)
d.Print(string(tcell.RuneVLine), modalStyle) d.Print(fmt.Sprintf(" %c", tcell.RuneVLine), baseStyle)
d.NL() d.NL()
} }
d.Goto(colOffset, rowOffset+modalHeight-1) d.Goto(colOffset, rowOffset+modalHeight-1)
d.Print(string(tcell.RuneLLCorner), modalStyle) d.Print(string(tcell.RuneLLCorner), baseStyle)
d.Print(strings.Repeat(string(tcell.RuneHLine), modalWidth-2), modalStyle) d.Print(strings.Repeat(string(tcell.RuneHLine), modalWidth-2), baseStyle)
d.Print(string(tcell.RuneLRCorner), modalStyle) d.Print(string(tcell.RuneLRCorner), baseStyle)
d.NL() d.NL()
} }