add:partial functionality
This commit is contained in:
@@ -12,23 +12,34 @@ const (
|
||||
pageConfig
|
||||
pageAddServer
|
||||
pageSelectServer
|
||||
pageServerActions
|
||||
pageFileAction
|
||||
)
|
||||
|
||||
type TUIInterface struct {
|
||||
Services *services.ServicesStore
|
||||
Page page
|
||||
MenuItems []pages.MenuItem
|
||||
Selected int
|
||||
Servers map[string]services.Server
|
||||
ServerNames []string // sorted, stable order for list rendering
|
||||
NoServers bool
|
||||
InitErr error
|
||||
FlashMsg string
|
||||
Form addServerForm
|
||||
FormErr string // inline field error (e.g. duplicate name)
|
||||
Quitting bool
|
||||
WindowWidth int
|
||||
WindowHeight int
|
||||
Services *services.ServicesStore
|
||||
Page page
|
||||
MenuItems []pages.MenuItem
|
||||
Selected int
|
||||
Servers map[string]services.Server
|
||||
ServerNames []string // sorted, stable order for list rendering
|
||||
NoServers bool
|
||||
InitErr error
|
||||
FlashMsg string
|
||||
Form addServerForm
|
||||
FormErr string // inline field error (e.g. duplicate name)
|
||||
Quitting bool
|
||||
WindowWidth int
|
||||
WindowHeight int
|
||||
// server actions page
|
||||
ActiveServer string
|
||||
StorageFiles []string
|
||||
StorageLoading bool
|
||||
StorageErr error
|
||||
FileSelected int // cursor within StorageFiles
|
||||
FileFocused bool // true = ↑↓ drives file list, false = action menu
|
||||
// file action page
|
||||
ActiveFile string
|
||||
}
|
||||
|
||||
func NewTUIInterface(store *services.ServicesStore) TUIInterface {
|
||||
|
||||
@@ -23,6 +23,22 @@ type serverAddedMsg struct {
|
||||
|
||||
type clearFlashMsg struct{}
|
||||
|
||||
type storageFilesMsg struct {
|
||||
files []string
|
||||
err error
|
||||
}
|
||||
|
||||
func checkStorageCmd(store *services.ServicesStore, serverName string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
storage, err := store.NewStorageService(serverName)
|
||||
if err != nil {
|
||||
return storageFilesMsg{err: err}
|
||||
}
|
||||
files, err := storage.Check()
|
||||
return storageFilesMsg{files: files, err: err}
|
||||
}
|
||||
}
|
||||
|
||||
func clearFlashAfter(d time.Duration) tea.Cmd {
|
||||
return tea.Tick(d, func(time.Time) tea.Msg {
|
||||
return clearFlashMsg{}
|
||||
@@ -82,6 +98,32 @@ func (m TUIInterface) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.Selected = 0
|
||||
return m, nil
|
||||
|
||||
case pages.ServerActionsPageMsg:
|
||||
m.Page = pageServerActions
|
||||
m.ActiveServer = msg.ServerName
|
||||
m.MenuItems = pages.ServerActionItems()
|
||||
m.Selected = 0
|
||||
m.FileSelected = 0
|
||||
m.FileFocused = false
|
||||
m.StorageFiles = nil
|
||||
m.StorageErr = nil
|
||||
m.StorageLoading = true
|
||||
return m, checkStorageCmd(m.Services, msg.ServerName)
|
||||
|
||||
case pages.FileActionPageMsg:
|
||||
m.Page = pageFileAction
|
||||
m.ActiveFile = msg.Filename
|
||||
m.MenuItems = pages.FileActionItems()
|
||||
m.Selected = 0
|
||||
return m, nil
|
||||
|
||||
case storageFilesMsg:
|
||||
m.StorageLoading = false
|
||||
m.StorageFiles = msg.files
|
||||
m.StorageErr = msg.err
|
||||
m.FileSelected = 0
|
||||
return m, nil
|
||||
|
||||
case configLoadedMsg:
|
||||
if msg.err != nil {
|
||||
m.InitErr = msg.err
|
||||
@@ -112,14 +154,18 @@ func (m TUIInterface) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
// add server form has its own key handling
|
||||
if m.Page == pageAddServer {
|
||||
return m.updateAddServer(msg)
|
||||
}
|
||||
// server list has its own key handling
|
||||
if m.Page == pageSelectServer {
|
||||
return m.updateSelectServer(msg)
|
||||
}
|
||||
if m.Page == pageServerActions {
|
||||
return m.updateServerActions(msg)
|
||||
}
|
||||
if m.Page == pageFileAction {
|
||||
return m.updateFileAction(msg)
|
||||
}
|
||||
|
||||
switch msg.String() {
|
||||
case "up", "k":
|
||||
@@ -169,6 +215,122 @@ func (m TUIInterface) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TUIInterface) updateServerActions(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "tab":
|
||||
// toggle focus between action menu and file list
|
||||
if len(m.StorageFiles) > 0 {
|
||||
m.FileFocused = !m.FileFocused
|
||||
}
|
||||
|
||||
case "up", "k":
|
||||
if m.FileFocused {
|
||||
if m.FileSelected > 0 {
|
||||
m.FileSelected--
|
||||
}
|
||||
} else {
|
||||
if m.Selected > 0 {
|
||||
m.Selected--
|
||||
}
|
||||
}
|
||||
|
||||
case "down", "j":
|
||||
if m.FileFocused {
|
||||
if m.FileSelected < len(m.StorageFiles)-1 {
|
||||
m.FileSelected++
|
||||
}
|
||||
} else {
|
||||
if m.Selected < len(m.MenuItems)-1 {
|
||||
m.Selected++
|
||||
}
|
||||
}
|
||||
|
||||
case "enter":
|
||||
if m.FileFocused && len(m.StorageFiles) > 0 {
|
||||
file := m.StorageFiles[m.FileSelected]
|
||||
server := m.ActiveServer
|
||||
return m, func() tea.Msg {
|
||||
return pages.FileActionPageMsg{ServerName: server, Filename: file}
|
||||
}
|
||||
}
|
||||
switch m.MenuItems[m.Selected].Key {
|
||||
case "send":
|
||||
// TODO: navigate to send page
|
||||
case "get":
|
||||
// TODO: navigate to get page (bulk)
|
||||
case "clean":
|
||||
// TODO: navigate to clean page (bulk)
|
||||
}
|
||||
|
||||
case "ctrl+c":
|
||||
m.Quitting = true
|
||||
return m, tea.Quit
|
||||
|
||||
case "esc":
|
||||
return m, func() tea.Msg { return pages.SelectServerPageMsg{} }
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TUIInterface) updateFileAction(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "up", "k":
|
||||
if m.Selected > 0 {
|
||||
m.Selected--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.Selected < len(m.MenuItems)-1 {
|
||||
m.Selected++
|
||||
}
|
||||
case "enter":
|
||||
server := m.ActiveServer
|
||||
file := m.ActiveFile
|
||||
switch m.MenuItems[m.Selected].Key {
|
||||
case "get":
|
||||
_ = server
|
||||
_ = file
|
||||
// TODO: implement get
|
||||
case "delete":
|
||||
_ = server
|
||||
_ = file
|
||||
// TODO: implement delete
|
||||
}
|
||||
case "ctrl+c":
|
||||
m.Quitting = true
|
||||
return m, tea.Quit
|
||||
case "esc":
|
||||
server := m.ActiveServer
|
||||
return m, func() tea.Msg { return pages.ServerActionsPageMsg{ServerName: server} }
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TUIInterface) updateSelectServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
last := len(m.ServerNames) - 1
|
||||
switch msg.String() {
|
||||
case "up", "k":
|
||||
if m.Selected > 0 {
|
||||
m.Selected--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.Selected < last {
|
||||
m.Selected++
|
||||
}
|
||||
case "enter":
|
||||
if m.Selected >= 0 && m.Selected < len(m.ServerNames) {
|
||||
name := m.ServerNames[m.Selected]
|
||||
return m, func() tea.Msg { return pages.ServerActionsPageMsg{ServerName: name} }
|
||||
}
|
||||
case "ctrl+c":
|
||||
m.Quitting = true
|
||||
return m, tea.Quit
|
||||
case "esc":
|
||||
return m, func() tea.Msg { return pages.HomePageMsg{} }
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TUIInterface) updateAddServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
f := m.Form
|
||||
|
||||
@@ -182,16 +344,13 @@ func (m TUIInterface) updateAddServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd)
|
||||
return m, nil
|
||||
|
||||
case "enter":
|
||||
// on an input field, advance to next
|
||||
if f.focused < fieldSave {
|
||||
m.Form = f.focusNext()
|
||||
return m, nil
|
||||
}
|
||||
// on save button
|
||||
if f.focused == fieldSave {
|
||||
return m.submitAddServer()
|
||||
}
|
||||
// on back button
|
||||
if f.focused == fieldBack {
|
||||
return m, func() tea.Msg { return pages.ConfigPageMsg{} }
|
||||
}
|
||||
@@ -201,7 +360,6 @@ func (m TUIInterface) updateAddServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd)
|
||||
return m, tea.Quit
|
||||
|
||||
case "ctrl+v":
|
||||
// OSC52 clipboard read; result arrives as tea.ClipboardMsg
|
||||
if f.focused < len(f.inputs) {
|
||||
return m, tea.ReadClipboard
|
||||
}
|
||||
@@ -211,11 +369,9 @@ func (m TUIInterface) updateAddServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd)
|
||||
return m, func() tea.Msg { return pages.ConfigPageMsg{} }
|
||||
}
|
||||
|
||||
// route keystrokes to the focused input
|
||||
if f.focused < len(f.inputs) {
|
||||
var cmd tea.Cmd
|
||||
f.inputs[f.focused], cmd = f.inputs[f.focused].Update(msg)
|
||||
// clear duplicate-name error when user edits the name field
|
||||
if f.focused == fieldName {
|
||||
m.FormErr = ""
|
||||
}
|
||||
@@ -240,28 +396,6 @@ func (m TUIInterface) updateAddServerPaste(text string) (tea.Model, tea.Cmd) {
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m TUIInterface) updateSelectServer(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
last := len(m.ServerNames) - 1
|
||||
switch msg.String() {
|
||||
case "up", "k":
|
||||
if m.Selected > 0 {
|
||||
m.Selected--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.Selected < last {
|
||||
m.Selected++
|
||||
}
|
||||
case "enter":
|
||||
// TODO: connect to selected server
|
||||
case "ctrl+c":
|
||||
m.Quitting = true
|
||||
return m, tea.Quit
|
||||
case "esc":
|
||||
return m, func() tea.Msg { return pages.HomePageMsg{} }
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TUIInterface) submitAddServer() (tea.Model, tea.Cmd) {
|
||||
f := m.Form
|
||||
name := strings.TrimSpace(f.inputs[fieldName].Value())
|
||||
|
||||
@@ -25,6 +25,13 @@ func (m TUIInterface) subtitle() string {
|
||||
return "Add Server"
|
||||
case pageSelectServer:
|
||||
return "Select Server"
|
||||
case pageServerActions:
|
||||
if m.ActiveServer != "" {
|
||||
return m.ActiveServer
|
||||
}
|
||||
return "Server"
|
||||
case pageFileAction:
|
||||
return m.ActiveFile
|
||||
default:
|
||||
return "Secure file transfer"
|
||||
}
|
||||
@@ -50,6 +57,10 @@ func (m TUIInterface) View() tea.View {
|
||||
body = m.viewAddServer()
|
||||
case pageSelectServer:
|
||||
body = m.viewSelectServer()
|
||||
case pageServerActions:
|
||||
body = m.viewServerActions()
|
||||
case pageFileAction:
|
||||
body = m.viewFileAction()
|
||||
default:
|
||||
body = m.viewMenu()
|
||||
}
|
||||
@@ -79,6 +90,20 @@ func (m TUIInterface) View() tea.View {
|
||||
footerHint("enter", "connect") +
|
||||
footerSep() +
|
||||
footerHint("esc", "back")
|
||||
case pageServerActions:
|
||||
footerStr = footerHint("tab", "switch pane") +
|
||||
footerSep() +
|
||||
footerHint("↑↓", "navigate") +
|
||||
footerSep() +
|
||||
footerHint("enter", "select") +
|
||||
footerSep() +
|
||||
footerHint("esc", "back")
|
||||
case pageFileAction:
|
||||
footerStr = footerHint("↑↓", "navigate") +
|
||||
footerSep() +
|
||||
footerHint("enter", "confirm") +
|
||||
footerSep() +
|
||||
footerHint("esc", "back")
|
||||
default:
|
||||
footerStr = footerHint("↑↓", "navigate") +
|
||||
footerSep() +
|
||||
@@ -130,6 +155,49 @@ func (m TUIInterface) viewMenu() string {
|
||||
return menu
|
||||
}
|
||||
|
||||
func (m TUIInterface) viewServerActions() string {
|
||||
// action menu — single column, unfocused when file pane is active
|
||||
var actionRows []string
|
||||
for i, item := range m.MenuItems {
|
||||
active := !m.FileFocused && i == m.Selected
|
||||
actionRows = append(actionRows, styles.MenuItemStyle(active, false).Render(item.Label))
|
||||
}
|
||||
actions := lipgloss.JoinVertical(lipgloss.Left, actionRows...)
|
||||
|
||||
// file list section below, separated by a top border
|
||||
var fileRows []string
|
||||
switch {
|
||||
case m.StorageLoading:
|
||||
fileRows = append(fileRows, styles.StatusWarnStyle.Render(" loading…"))
|
||||
case m.StorageErr != nil:
|
||||
fileRows = append(fileRows, styles.StatusErrStyle.Render("✗ "+m.StorageErr.Error()))
|
||||
case len(m.StorageFiles) == 0:
|
||||
fileRows = append(fileRows, styles.StorageEmptyStyle.Render(" no files in storage"))
|
||||
default:
|
||||
for i, f := range m.StorageFiles {
|
||||
active := m.FileFocused && i == m.FileSelected
|
||||
fileRows = append(fileRows, styles.FileItemStyle(active).Render(f))
|
||||
}
|
||||
}
|
||||
fileList := lipgloss.JoinVertical(lipgloss.Left, fileRows...)
|
||||
fileSection := styles.StorageFileSectionStyle.Render(fileList)
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, actions, fileSection)
|
||||
}
|
||||
|
||||
func (m TUIInterface) viewFileAction() string {
|
||||
// filename shown as a dim label above the menu
|
||||
filenameLabel := styles.FilenameLabelStyle.Render(m.ActiveFile)
|
||||
|
||||
var menuRows []string
|
||||
for i, item := range m.MenuItems {
|
||||
menuRows = append(menuRows, styles.MenuItemStyle(i == m.Selected, false).Render(item.Label))
|
||||
}
|
||||
menu := lipgloss.JoinVertical(lipgloss.Left, menuRows...)
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, filenameLabel, menu)
|
||||
}
|
||||
|
||||
func (m TUIInterface) viewSelectServer() string {
|
||||
if len(m.ServerNames) == 0 {
|
||||
return styles.StatusWarnStyle.Render("⚠ No servers configured.")
|
||||
@@ -155,16 +223,13 @@ func (m TUIInterface) viewAddServer() string {
|
||||
}
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user