package main import ( "fmt" "github.com/charmbracelet/lipgloss" ) func (m model) View() string { errView := "" if m.err != nil { errView = fmt.Sprintf("\n%s", errStyle.Render(fmt.Sprintf("ERROR: %v", m.err))) } if m.state == StateLogin { content := "" if m.loginForm != nil { content = m.loginForm.View() } return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, loginBoxStyle.Render(content+errView)) } if m.state == StateSettings { // [수정] 스캔 중이면 로딩 화면 표시 if m.scanning { return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, settingsBoxStyle.Render("Scanning Wi-Fi Networks...\nPlease wait.")) } content := "" if m.settingsForm != nil { content = m.settingsForm.View() } helpMsg := "\n[Enter] Select/Save [Esc] Back/Cancel" box := settingsBoxStyle.Render(content + lipgloss.NewStyle().Foreground(ColorGray).Render(helpMsg)) return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, box+errView) } if m.state == StateTerminal { return "" } // Dashboard wifiTxt := "WiFi: Disconnected" if m.status.Wifi.SSID != "" { wifiTxt = fmt.Sprintf("WiFi: %s (%ddBm)", m.status.Wifi.SSID, m.status.Wifi.RSSI) } header := lipgloss.NewStyle().Width(m.width).Background(ColorPurple).Foreground(ColorText).Padding(0, 1).Bold(true).Render(wifiTxt) panelW := (m.width - 6) / 3 if panelW < 22 { panelW = 22 } currPanelStyle := panelBaseStyle.Copy().Width(panelW) renderMetric := func(label string, val float64, unit string, color lipgloss.Color) string { return fmt.Sprintf("%s%s", lblStyle.Render(label), lipgloss.NewStyle().Foreground(color).Bold(true).Render(fmt.Sprintf("%6.2f %s", val, unit))) } pVin := currPanelStyle.Copy().BorderForeground(ColorBlue).Render(lipgloss.JoinVertical(lipgloss.Center, titleStyle.Foreground(ColorBlue).Render("VIN (Input)"), renderMetric("VOLT:", m.status.Vin.Voltage, "V", ColorBlue), renderMetric("CURR:", m.status.Vin.Current, "A", ColorBlue), renderMetric("POWR:", m.status.Vin.Power, "W", ColorBlue), )) mColor := ColorRed mTitle := "MAIN [OFF]" if m.status.Sw.MainOn { mColor = ColorGreen mTitle = "MAIN [ON]" } pMain := currPanelStyle.Copy().BorderForeground(mColor).Render(lipgloss.JoinVertical(lipgloss.Center, titleStyle.Foreground(mColor).Render(mTitle), renderMetric("VOLT:", m.status.Main.Voltage, "V", mColor), renderMetric("CURR:", m.status.Main.Current, "A", mColor), renderMetric("POWR:", m.status.Main.Power, "W", mColor), )) uColor := ColorRed uTitle := "USB [OFF]" if m.status.Sw.UsbOn { uColor = ColorGreen uTitle = "USB [ON]" } pUsb := currPanelStyle.Copy().BorderForeground(uColor).Render(lipgloss.JoinVertical(lipgloss.Center, titleStyle.Foreground(uColor).Render(uTitle), renderMetric("VOLT:", m.status.Usb.Voltage, "V", uColor), renderMetric("CURR:", m.status.Usb.Current, "A", uColor), renderMetric("POWR:", m.status.Usb.Power, "W", uColor), )) panels := lipgloss.PlaceHorizontal(m.width, lipgloss.Center, lipgloss.JoinHorizontal(lipgloss.Top, pVin, pMain, pUsb)) help := lipgloss.NewStyle().Foreground(ColorGray).Render(" [Enter] Terminal [s] Settings [u] Toggle USB [m] Toggle Main [q] Quit") footer := lipgloss.PlaceHorizontal(m.width, lipgloss.Center, help) return lipgloss.JoinVertical(lipgloss.Left, header, "\n\n", panels, "\n\n", footer+errView) }