Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cmd/mxcli/cmd_tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,33 @@ Commands (via : bar):
:diagram open diagram in browser
:search <kw> full-text search

Flags:
-c, --continue Restore previous session (tab, navigation, preview mode)

Example:
mxcli tui -p app.mpr
mxcli tui -c
`,
Run: func(cmd *cobra.Command, args []string) {
projectPath, _ := cmd.Flags().GetString("project")
continueSession, _ := cmd.Flags().GetBool("continue")
mxcliPath, _ := os.Executable()

// Try to restore session when -c flag is set
var session *tui.TUISession
if continueSession {
loaded, err := tui.LoadSession()
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: could not load session: %v\n", err)
} else if loaded != nil {
session = loaded
// Use project path from session if not explicitly provided
if projectPath == "" && len(session.Tabs) > 0 {
projectPath = session.Tabs[0].ProjectPath
}
}
}

if projectPath == "" {
picker := tui.NewPickerModel()
p := tea.NewProgram(picker, tea.WithAltScreen())
Expand All @@ -55,9 +75,18 @@ Example:
projectPath = m.Chosen()
}

// Verify project file exists
if _, err := os.Stat(projectPath); err != nil {
fmt.Fprintf(os.Stderr, "Error: project file not found: %s\n", projectPath)
os.Exit(1)
}

tui.SaveHistory(projectPath)

m := tui.NewApp(mxcliPath, projectPath)
if session != nil {
m.SetPendingSession(session)
}
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
m.StartWatcher(p)
if _, err := p.Run(); err != nil {
Expand All @@ -66,3 +95,7 @@ Example:
}
},
}

func init() {
tuiCmd.Flags().BoolP("continue", "c", false, "Restore previous TUI session")
}
Loading
Loading