Skip to content

Commit

Permalink
fix: 🐛 UI border tweak for termux and small screen
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimanyu003 committed Apr 8, 2023
1 parent 4ce9699 commit 4913cf8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package ui

import (
"fmt"
"golang.org/x/term"
"log"
"os"

"github.com/abhimanyu003/sttr/processors"

Expand Down Expand Up @@ -33,11 +35,16 @@ func New(input string) UI {
}

func (u *UI) Render() {
termWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil || termWidth > maxWidth {
termWidth = maxWidth
}
if u.input == "" {
divider := lipgloss.NewStyle().Padding(0, 1).Foreground(borderStyle).Render("•")
info := lipgloss.NewStyle().Foreground(specialStyle).Render("[ Enter 2 empty lines to process ]")

title := lipgloss.NewStyle().Width(maxWidth).
title := lipgloss.NewStyle().
MaxWidth(termWidth).
BorderStyle(lipgloss.DoubleBorder()).
BorderTop(true).
BorderBottom(true).
Expand All @@ -61,7 +68,8 @@ func (u *UI) Render() {
data = fmt.Sprintf("error: %s", err.Error())
}

border := lipgloss.NewStyle().Width(maxWidth).
border := lipgloss.NewStyle().
Width(termWidth).
BorderTop(true).
BorderStyle(lipgloss.DoubleBorder()).
BorderForeground(borderStyle).String()
Expand Down Expand Up @@ -99,8 +107,8 @@ func (u *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return u, tea.Quit
}
case tea.WindowSizeMsg:
top, right, bottom, left := appStyle.GetMargin()
u.list.SetSize(msg.Width-left-right, msg.Height-top-bottom)
h, w := appStyle.GetFrameSize()
u.list.SetSize(msg.Width-h, msg.Height-w)
}

var cmd tea.Cmd
Expand Down

0 comments on commit 4913cf8

Please sign in to comment.