diff --git a/internal/ui_main_events.go b/internal/ui_main_events.go index 22f9262..7de865f 100644 --- a/internal/ui_main_events.go +++ b/internal/ui_main_events.go @@ -6,31 +6,53 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: - // Setup keybindings - switch msg.String() { - case "ctrl+c", "q": - // Exit when user presses Q or CTRL+C - return m, tea.Quit - case "enter": - if m.width != 0 { - // Process the selected item, if the return value is true then exit the application - if m.processSelection() { + // If we are not done + if m.focused != DONE { + // Setup keybindings + switch msg.String() { + case "ctrl+c", "q": + // Exit when user presses Q or CTRL+C + return m, tea.Quit + + case "enter": + if m.width != 0 { + // Process the selected item, if the return value is true then exit the application + if m.processSelection() { + return m, tea.Quit + } + } + case "ctrl+z", "backspace": + // Go backwards in the model + if m.focused > 0 && m.focused != DONE { + m.focused-- + return m, nil + } else if m.focused == DONE { + // Since we have no QuickEmu support, skip the usb controller configuration + m.focused = VIDEO + } else { + // If we are at the beginning, just exit return m, tea.Quit } } - case "ctrl+z", "backspace": - // Go backwards in the model - if m.focused > 0 && m.focused != DONE { - m.focused-- - return m, nil - } else if m.focused == DONE { - // Since we have no QuickEmu support, skip the usb controller configuration - m.focused = VIDEO - } else { - // If we are at the beginning, just exit + } else { + // If we are done then handle keybindings a bit differently + // Setup keybindings for authDialog + switch msg.String() { + case "ctrl+c": + // Exit when user presses CTRL+C return m, tea.Quit + + case "enter": + if m.width != 0 { + // Process the selected item, if the return value is true then exit the application + if m.processSelection() { + return m, tea.Quit + } + } } + m.authDialog, cmd = m.authDialog.Update(msg) + return m, cmd } case tea.WindowSizeMsg: if m.width == 0 { @@ -52,12 +74,14 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Update the styles with the correct width dialogStyle = dialogStyle.Width(m.width) listStyle = listStyle.Width(m.width) - titleStyle = titleStyle.Width(m.width - 2) + titleStyle = titleStyle.Width(m.width - 4) choiceStyle = choiceStyle.Width(m.width) } } } } + + // Run another update loop m.lists[m.focused], cmd = m.lists[m.focused].Update(msg) return m, cmd } diff --git a/internal/ui_main_view.go b/internal/ui_main_view.go index 247262d..7d0651e 100644 --- a/internal/ui_main_view.go +++ b/internal/ui_main_view.go @@ -12,6 +12,7 @@ import ( func (m model) View() string { if m.width != 0 { title := "" + view := "Empty View :(" switch m.focused { case INTRO: title = dialogStyle.Render( @@ -31,11 +32,16 @@ func (m model) View() string { "becomes unbootable, as you will be asked to verify the files generated", ), ) + + view = listStyle.Render(m.lists[m.focused].View()) + case GPUS: title = titleStyle.MarginLeft(2).Render( "Select a GPU to check the IOMMU groups of", ) + view = listStyle.Render(m.lists[m.focused].View()) + case GPU_GROUP: title = titleStyle.Render( fmt.Sprint( @@ -44,11 +50,15 @@ func (m model) View() string { ), ) + view = listStyle.Render(m.lists[m.focused].View()) + case USB: title = titleStyle.Render( "[OPTIONAL]: Select a USB Controller to check the IOMMU groups of", ) + view = listStyle.Render(m.lists[m.focused].View()) + case USB_GROUP: title = titleStyle.Render( fmt.Sprint( @@ -57,6 +67,8 @@ func (m model) View() string { ), ) + view = listStyle.Render(m.lists[m.focused].View()) + case VBIOS: // Get the program directory exe, _ := os.Executable() @@ -89,6 +101,8 @@ func (m model) View() string { title = fmt.Sprintf(text, m.vbios_path, scriptdir) + view = listStyle.Render(m.lists[m.focused].View()) + case VIDEO: title = dialogStyle.Render( fmt.Sprint( @@ -99,13 +113,15 @@ func (m model) View() string { ), ) + view = listStyle.Render(m.lists[m.focused].View()) + case DONE: title = dialogStyle.Render( fmt.Sprint( "The configuration files have been generated and are\n", "located inside the \"config\" folder\n", "\n", - "* The \"cmdline\" file contains kernel arguments that your bootloader needs\n", + "* The \"kernel_args\" file contains kernel arguments that your bootloader needs\n", "* The \"quickemu\" folder contains files that might be\n useable for quickemu in the future\n", "* The files inside the \"etc\" folder must be copied to your system.\n", " NOTE: Verify that these files are correctly formated/edited!\n", @@ -114,9 +130,11 @@ func (m model) View() string { "run it to copy the files to your system and make a backup of your old files.", ), ) + + view = m.authDialog.View() } //return listStyle.SetString(fmt.Sprintf("%s\n\n", title)).Render(m.lists[m.focused].View()) - return lipgloss.JoinVertical(lipgloss.Left, fmt.Sprintf("%s\n%s\n", title, listStyle.Render(m.lists[m.focused].View()))) + return lipgloss.JoinVertical(lipgloss.Left, fmt.Sprintf("%s\n%s\n", title, view)) } else { return "Loading..." } diff --git a/internal/ui_model.go b/internal/ui_model.go index 31bf881..721ec49 100644 --- a/internal/ui_model.go +++ b/internal/ui_model.go @@ -1,7 +1,12 @@ package internal import ( + "fmt" + "os/user" + + "github.com/HikariKnight/ls-iommu/pkg/errorcheck" "github.com/charmbracelet/bubbles/list" + "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" ) @@ -29,6 +34,7 @@ type model struct { offsety []int width int height int + authDialog textinput.Model } // Consts used to navigate the main model @@ -44,8 +50,21 @@ const ( ) func NewModel() *model { + // Get the username + user, err := user.Current() + errorcheck.ErrorCheck(err, "Error getting username") + username := user.Username + + // Create the auth input and focus it + authInput := textinput.New() + authInput.EchoMode = textinput.EchoPassword + authInput.Prompt = fmt.Sprintf("\n[sudo] password for %s: ", username) + authInput.Focus() + // Create a blank model and return it - return &model{} + return &model{ + authDialog: authInput, + } } func (m model) Init() tea.Cmd { @@ -89,7 +108,7 @@ func (m *model) initLists(width, height int) { // Update the styles with the correct width dialogStyle = dialogStyle.Width(m.width) listStyle = listStyle.Width(m.width) - titleStyle = titleStyle.Width(m.width - 2) + titleStyle = titleStyle.Width(m.width - 4) choiceStyle = choiceStyle.Width(m.width) // Make m.fetched and set all values to FALSE