update:wip

This commit is contained in:
2026-04-06 01:39:29 +09:00
parent 09c78206a8
commit ed19e0ba4e
10 changed files with 475 additions and 58 deletions

View File

@@ -17,6 +17,17 @@ func footerSep() string {
return styles.FooterSepStyle.Render(" · ")
}
func (m TUIInterface) subtitle() string {
switch m.Page {
case pageConfig:
return "Configuration"
case pageAddServer:
return "Add Server"
default:
return "Secure file transfer"
}
}
func (m TUIInterface) View() tea.View {
if m.Quitting {
return tea.NewView("")
@@ -31,49 +42,41 @@ func (m TUIInterface) View() tea.View {
h = 24
}
// menu rows
var menuRows []string
for i, item := range m.MenuItems {
menuRows = append(menuRows, styles.MenuItemStyle(i == m.Selected).Render(item.Label))
}
menu := lipgloss.JoinVertical(lipgloss.Left, menuRows...)
// status line — error takes priority over no-servers hint
var statusLine string
switch {
case m.InitErr != nil:
statusLine = styles.StatusErrStyle.Render("✗ " + m.InitErr.Error())
case m.NoServers:
statusLine = styles.StatusWarnStyle.Render("⚠ No servers configured. Select Config to add one.")
var body string
switch m.Page {
case pageAddServer:
body = m.viewAddServer()
default:
body = m.viewMenu()
}
// top content
innerRows := []string{
header := lipgloss.JoinVertical(lipgloss.Left,
styles.CardTitleStyle.Render("✦ filepass"),
styles.CardSubtitleStyle.Render("Secure file transfer"),
menu,
}
if statusLine != "" {
innerRows = append(innerRows, statusLine)
}
topContent := styles.CardInnerStyle.Render(
lipgloss.JoinVertical(lipgloss.Left, innerRows...),
styles.CardSubtitleStyle.Render(m.subtitle()),
)
// footer
hints := footerHint("↑↓", "navigate") +
footerSep() +
footerHint("enter", "select") +
footerSep() +
footerHint("esc", "quit")
footer := styles.FooterStyle.Render(hints)
topContent := styles.CardInnerStyle.Render(
lipgloss.JoinVertical(lipgloss.Left, header, body),
)
var footerStr string
if m.Page == pageAddServer {
footerStr = footerHint("tab/↑↓", "navigate") +
footerSep() +
footerHint("enter", "confirm") +
footerSep() +
footerHint("esc", "back")
} else {
footerStr = footerHint("↑↓", "navigate") +
footerSep() +
footerHint("enter", "select") +
footerSep() +
footerHint("esc", "quit")
}
footer := styles.FooterStyle.Render(footerStr)
// card
card := styles.CardStyle.Render(
lipgloss.JoinVertical(lipgloss.Left,
topContent,
footer,
),
lipgloss.JoinVertical(lipgloss.Left, topContent, footer),
)
cardHeight := lipgloss.Height(card)
@@ -89,3 +92,63 @@ func (m TUIInterface) View() tea.View {
v.AltScreen = true
return v
}
func (m TUIInterface) viewMenu() string {
var menuRows []string
for i, item := range m.MenuItems {
disabled := m.isDisabled(i)
menuRows = append(menuRows, styles.MenuItemStyle(i == m.Selected, disabled).Render(item.Label))
}
menu := lipgloss.JoinVertical(lipgloss.Left, menuRows...)
var statusLine string
switch {
case m.InitErr != nil:
statusLine = styles.StatusErrStyle.Render("✗ " + m.InitErr.Error())
case m.NoServers && m.Page == pageHome:
statusLine = styles.StatusWarnStyle.Render("⚠ No servers configured. Select Config to add one.")
case m.FlashMsg != "" && m.Page == pageConfig:
statusLine = styles.StatusOKStyle.Render(m.FlashMsg)
}
if statusLine != "" {
return lipgloss.JoinVertical(lipgloss.Left, menu, statusLine)
}
return menu
}
func (m TUIInterface) viewAddServer() string {
f := m.Form
labels := []string{"Name", "Host", "User", "Private Key Path", "Port"}
required := []bool{true, true, true, true, false}
var rows []string
for i, label := range labels {
lbl := styles.FieldLabelStyle(required[i]).Render(label)
input := f.inputs[i].View()
rows = append(rows, lipgloss.JoinVertical(lipgloss.Left, lbl, input))
}
form := lipgloss.JoinVertical(lipgloss.Left, rows...)
// required legend
legend := styles.FieldLegendStyle.Render("* required")
// form error (duplicate name, etc.)
var errLine string
if m.FormErr != "" {
errLine = styles.StatusErrStyle.Render(m.FormErr)
}
// save / back buttons
saveBtn := styles.ButtonStyle(f.focused == fieldSave, f.canSave()).Render("Save")
backBtn := styles.ButtonStyle(f.focused == fieldBack, true).Render("Back")
buttons := lipgloss.JoinHorizontal(lipgloss.Top, saveBtn, " ", backBtn)
parts := []string{form, legend}
if errLine != "" {
parts = append(parts, errLine)
}
parts = append(parts, buttons)
return lipgloss.JoinVertical(lipgloss.Left, parts...)
}