Make the titles better and improve startup error

This commit is contained in:
HikariKnight 2023-04-07 14:31:50 +02:00
parent 654685d1e4
commit 632a2cb0de

View file

@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"log"
"os/exec" "os/exec"
"regexp" "regexp"
"strings" "strings"
@ -27,7 +26,7 @@ var (
helpStyle = lipgloss.NewStyle(). helpStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color(241)) Foreground(lipgloss.Color(241))
listStyle = lipgloss.NewStyle(). listStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.DoubleBorder()) BorderStyle(lipgloss.RoundedBorder())
) )
type status int type status int
@ -110,7 +109,7 @@ func (m *model) processSelection() {
m.lists[GPU_GROUP].SetItems(items) m.lists[GPU_GROUP].SetItems(items)
// Adjust height to correct for a bigger title // Adjust height to correct for a bigger title
m.lists[GPU_GROUP].SetSize(m.width, m.height) m.lists[GPU_GROUP].SetSize(m.width, m.height-1)
// Change focus to next index // Change focus to next index
m.focused++ m.focused++
@ -137,7 +136,7 @@ func (m *model) processSelection() {
m.lists[USB_GROUP].SetItems(items) m.lists[USB_GROUP].SetItems(items)
// Adjust height to correct for a bigger title // Adjust height to correct for a bigger title
m.lists[USB_GROUP].SetSize(m.width, m.height) m.lists[USB_GROUP].SetSize(m.width, m.height-1)
// Change focus to next index // Change focus to next index
m.focused++ m.focused++
@ -188,47 +187,46 @@ func (m model) View() string {
switch m.focused { switch m.focused {
case GPUS: case GPUS:
title = fmt.Sprintf( title = fmt.Sprintf(
"\n %s\n", " Select a GPU to check the IOMMU groups of",
titleStyle.Render("Select a GPU to check the IOMMU groups of"),
) )
case GPU_GROUP: case GPU_GROUP:
title = fmt.Sprintf( title = fmt.Sprint(
"\n %s\n %s", " Press ENTER/RETURN to set up all these devices for passthrough.\n",
titleStyle.Render("Press ENTER/RETURN to set up all these devices for passthrough."), titleStyle.Render("This list should only contain items related to your GPU."), " This list should only contain items related to your GPU.",
) )
case USB: case USB:
title = fmt.Sprintf( title = fmt.Sprint(
"\n %s\n", " [OPTIONAL]: Select a USB Controller to check the IOMMU groups of",
titleStyle.Render("[OPTIONAL]: Select a USB Controller to check the IOMMU groups of"),
) )
case USB_GROUP: case USB_GROUP:
title = fmt.Sprintf( title = fmt.Sprint(
"\n %s\n %s", " Press ENTER/RETURN to set up all these devices for passthrough.\n",
titleStyle.Render("Press ENTER/RETURN to set up all these devices for passthrough."), titleStyle.Render("This list should only contain the USB controller you want to use."), " This list should only contain the USB controller you want to use.",
) )
} }
return lipgloss.JoinVertical(lipgloss.Left, title, listStyle.Render(m.lists[m.focused].View())) return lipgloss.JoinVertical(lipgloss.Left, listStyle.SetString(fmt.Sprintf("%s\n", titleStyle.Render(title))).Render(m.lists[m.focused].View()))
} else { } else {
return "Loading..." return "Loading..."
} }
} }
func NewModel() *model { func NewModel() *model {
// Create a blank model and return it
return &model{} return &model{}
} }
// This is where we build everything // This is where we build everything
func App() { func App() {
// Make a blank model to keep our state in
m := NewModel() m := NewModel()
// Start the program with the model // Start the program with the model
p := tea.NewProgram(m, tea.WithAltScreen()) p := tea.NewProgram(m, tea.WithAltScreen())
if _, err := p.Run(); err != nil { _, err := p.Run()
log.Fatal(err) errorcheck.ErrorCheck(err, "Failed to initialize UI")
}
} }
func GetIOMMU(args ...string) []list.Item { func GetIOMMU(args ...string) []list.Item {