Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Scaled text UI to fit the window
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Gherghetta <pgher7285@gmail.com>
  • Loading branch information
pgherghetta committed Jul 1, 2021
1 parent f86d322 commit 7b560fb
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (

ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"github.com/nsf/termbox-go"
)

const menuWidth = 50
const menuHeight = 12
const resultHeight = 20
const resultWidth = 70

Expand Down Expand Up @@ -354,20 +353,25 @@ func PromptMenuEntry(menuTitle string, introwords string, entries []Entry, uiEve
for i, e := range entries {
listData = append(listData, fmt.Sprintf("[%d] %s", i, e.Label()))
}

windowWidth, windowHeight := termbox.Size()
// location will serve as the y1 coordinate in this function.
location := 0
menu := widgets.NewList()
menu.Title = menuTitle
// menus's hight always be 12, which could diplay 10 entrys in one page
menu.SetRect(0, location, menuWidth, location+menuHeight)
location += menuHeight
// windowHeight is divided by 5 to make room for the five boxes that will be on the screen.
height := windowHeight / 5
// menu is the box with the options. It will be at the top of the screen.
menu.SetRect(0, location, windowWidth, height)

location += height
menu.TextStyle.Fg = ui.ColorWhite
intro := newParagraph(introwords, false, location, windowWidth, height)

intro := newParagraph(introwords, false, location, len(introwords)+4, 3)
location += 2
input := newParagraph("", true, location, menuWidth, 3)
location += 3
warning := newParagraph("<Esc> to go back, <Ctrl+d> to exit", false, location, menuWidth, 3)
location += height
input := newParagraph("", true, location, windowWidth, height)

location += height
warning := newParagraph("<Esc> to go back, <Ctrl+d> to exit", false, location, windowWidth, height)

ui.Render(intro)
ui.Render(input)
Expand Down

0 comments on commit 7b560fb

Please sign in to comment.