💄 fix(ui): Properly calc main dimensions
This commit is contained in:
parent
43f5c55456
commit
7212aa31f4
2 changed files with 36 additions and 27 deletions
56
main.go
56
main.go
|
@ -102,10 +102,6 @@ func (m menu) setDimensions() {
|
||||||
m.width, m.height, _ = term.GetSize(int(os.Stdout.Fd()))
|
m.width, m.height, _ = term.GetSize(int(os.Stdout.Fd()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcMainWidth(width int) int {
|
|
||||||
return int(float64(width) * 0.65)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
|
@ -136,7 +132,8 @@ func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.setDimensions()
|
m.setDimensions()
|
||||||
m.viewport.Width = calcMainWidth(m.width)
|
m.viewport.Width = gloss.Width(m.mainView())
|
||||||
|
m.viewport.Height = gloss.Height(m.mainView())
|
||||||
|
|
||||||
case errMsg:
|
case errMsg:
|
||||||
m.appendOutput("Error: " + msg.Error())
|
m.appendOutput("Error: " + msg.Error())
|
||||||
|
@ -148,23 +145,33 @@ func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m menu) View() string {
|
var borderStyle = gloss.NewStyle().
|
||||||
mainWidth := calcMainWidth(m.width)
|
BorderStyle(gloss.RoundedBorder()).
|
||||||
borderStyle := gloss.NewStyle().
|
BorderForeground(gloss.Color("5")).
|
||||||
BorderStyle(gloss.RoundedBorder()).
|
Padding(0, 1)
|
||||||
BorderForeground(gloss.Color("5")).
|
|
||||||
Padding(0, 1)
|
var topPadding = 1
|
||||||
|
|
||||||
|
func (m menu) mainView() string {
|
||||||
|
mainWidth := int(float64(m.width) * 0.65)
|
||||||
|
|
||||||
mainStyle := borderStyle.
|
mainStyle := borderStyle.
|
||||||
Width(mainWidth)
|
Width(mainWidth).
|
||||||
|
Height(m.calcInnerSidebarHeight() - 2)
|
||||||
|
|
||||||
|
mainContent := m.viewport.View()
|
||||||
|
|
||||||
|
return mainStyle.Render(mainContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m menu) calcInnerSidebarHeight() int {
|
||||||
|
return m.height - 3 - gloss.Height(m.helpView()) - topPadding
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m menu) sidebarView() string {
|
||||||
sidebarStyle := borderStyle.
|
sidebarStyle := borderStyle.
|
||||||
Width(int(float64(m.width) * 0.3))
|
Width(int(float64(m.width) * 0.3))
|
||||||
|
|
||||||
topPadding := 1
|
|
||||||
|
|
||||||
helpView := m.help.View(m.keys)
|
|
||||||
|
|
||||||
softwareListEnumerator := func(l list.Items, i int) string {
|
softwareListEnumerator := func(l list.Items, i int) string {
|
||||||
if m.current == i {
|
if m.current == i {
|
||||||
return m.spinner.View()
|
return m.spinner.View()
|
||||||
|
@ -176,7 +183,7 @@ func (m menu) View() string {
|
||||||
|
|
||||||
software := list.New().Enumerator(softwareListEnumerator)
|
software := list.New().Enumerator(softwareListEnumerator)
|
||||||
|
|
||||||
sidebarHeight := m.height - 3 - gloss.Height(helpView) - topPadding
|
sidebarHeight := m.calcInnerSidebarHeight()
|
||||||
|
|
||||||
if len(m.order) > 0 {
|
if len(m.order) > 0 {
|
||||||
start := max(m.current-10, 0)
|
start := max(m.current-10, 0)
|
||||||
|
@ -193,14 +200,15 @@ func (m menu) View() string {
|
||||||
|
|
||||||
sidebarContent := software.String()
|
sidebarContent := software.String()
|
||||||
|
|
||||||
m.viewport.Height = sidebarHeight
|
return sidebarStyle.Render(sidebarContent)
|
||||||
m.viewport.Width = mainWidth
|
}
|
||||||
mainContent := m.viewport.View()
|
|
||||||
|
|
||||||
main := mainStyle.Render(mainContent)
|
func (m menu) helpView() string {
|
||||||
sidebar := sidebarStyle.Render(sidebarContent)
|
return m.help.View(m.keys)
|
||||||
|
}
|
||||||
|
|
||||||
content := gloss.JoinHorizontal(gloss.Top, main, sidebar)
|
func (m menu) View() string {
|
||||||
|
content := gloss.JoinHorizontal(gloss.Top, m.mainView(), m.sidebarView())
|
||||||
|
|
||||||
top := strings.Repeat("\n", topPadding)
|
top := strings.Repeat("\n", topPadding)
|
||||||
last := ""
|
last := ""
|
||||||
|
@ -208,7 +216,7 @@ func (m menu) View() string {
|
||||||
last = "\n"
|
last = "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
page := gloss.JoinVertical(gloss.Left, top, content, helpView, last)
|
page := gloss.JoinVertical(gloss.Left, top, content, m.helpView(), last)
|
||||||
|
|
||||||
return gloss.PlaceHorizontal(m.width, gloss.Center, page)
|
return gloss.PlaceHorizontal(m.width, gloss.Center, page)
|
||||||
}
|
}
|
||||||
|
|
7
test.sh
7
test.sh
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
|
|
||||||
while [ $i -le 100 ]; do
|
while [ $i -le 200 ]; do
|
||||||
printf "line\n"
|
printf '%s line\n' "$i"
|
||||||
sleep 1
|
i=$((i + 1))
|
||||||
|
sleep .1
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue