@@ -33,13 +33,33 @@ Commands (via : bar):
3333 :diagram open diagram in browser
3434 :search <kw> full-text search
3535
36+ Flags:
37+ -c, --continue Restore previous session (tab, navigation, preview mode)
38+
3639Example:
3740 mxcli tui -p app.mpr
41+ mxcli tui -c
3842` ,
3943 Run : func (cmd * cobra.Command , args []string ) {
4044 projectPath , _ := cmd .Flags ().GetString ("project" )
45+ continueSession , _ := cmd .Flags ().GetBool ("continue" )
4146 mxcliPath , _ := os .Executable ()
4247
48+ // Try to restore session when -c flag is set
49+ var session * tui.TUISession
50+ if continueSession {
51+ loaded , err := tui .LoadSession ()
52+ if err != nil {
53+ fmt .Fprintf (os .Stderr , "Warning: could not load session: %v\n " , err )
54+ } else if loaded != nil {
55+ session = loaded
56+ // Use project path from session if not explicitly provided
57+ if projectPath == "" && len (session .Tabs ) > 0 {
58+ projectPath = session .Tabs [0 ].ProjectPath
59+ }
60+ }
61+ }
62+
4363 if projectPath == "" {
4464 picker := tui .NewPickerModel ()
4565 p := tea .NewProgram (picker , tea .WithAltScreen ())
@@ -55,9 +75,18 @@ Example:
5575 projectPath = m .Chosen ()
5676 }
5777
78+ // Verify project file exists
79+ if _ , err := os .Stat (projectPath ); err != nil {
80+ fmt .Fprintf (os .Stderr , "Error: project file not found: %s\n " , projectPath )
81+ os .Exit (1 )
82+ }
83+
5884 tui .SaveHistory (projectPath )
5985
6086 m := tui .NewApp (mxcliPath , projectPath )
87+ if session != nil {
88+ m .SetPendingSession (session )
89+ }
6190 p := tea .NewProgram (m , tea .WithAltScreen (), tea .WithMouseCellMotion ())
6291 m .StartWatcher (p )
6392 if _ , err := p .Run (); err != nil {
@@ -66,3 +95,7 @@ Example:
6695 }
6796 },
6897}
98+
99+ func init () {
100+ tuiCmd .Flags ().BoolP ("continue" , "c" , false , "Restore previous TUI session" )
101+ }
0 commit comments