Skip to content

Commit

Permalink
feat #275: Allow detaching from TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Dec 1, 2024
1 parent 1505127 commit 6b9ce00
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/cmd/project_runner_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func runInDetachedMode() {
fmt.Println("Starting Process Compose in detached mode. Use 'process-compose attach' to connect to it or 'process-compose down' to stop it")
//remove detached flag
for i, arg := range os.Args {
if arg == "-D" || arg == "--detached" {
if arg == "-D" || arg == "--detached" || arg == "--detached-with-tui" {
os.Args = append(os.Args[:i], os.Args[i+1:]...)
break
}
Expand All @@ -36,7 +36,9 @@ func runInDetachedMode() {
if err := cmd.Start(); err != nil {
panic(err)
}

if *pcFlags.IsDetachedWithTui {
startTui(getClient(), false)
}
// Exit the parent process
os.Exit(0)
}
3 changes: 2 additions & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func runProjectCmd(args []string) {
_ = logFile.Close()
}()
runner := getProjectRunner(args, *pcFlags.NoDependencies, "", []string{})
if *pcFlags.IsDetached {
if *pcFlags.IsDetached || *pcFlags.IsDetachedWithTui {
//placing it here ensures that if the compose.yaml is invalid, the program will exit immediately
runInDetachedMode()
}
Expand Down Expand Up @@ -99,6 +99,7 @@ func init() {

if runtime.GOOS != "windows" {
rootCmd.Flags().BoolVarP(pcFlags.IsDetached, "detached", "D", *pcFlags.IsDetached, "run process-compose in detached mode")
rootCmd.Flags().BoolVar(pcFlags.IsDetachedWithTui, "detached-with-tui", *pcFlags.IsDetachedWithTui, "run process-compose in detached mode with TUI")
rootCmd.PersistentFlags().StringVarP(pcFlags.UnixSocketPath, "unix-socket", "u", config.GetUnixSocketPath(), "path to unix socket (env: "+config.EnvVarUnixSocketPath+")")
rootCmd.PersistentFlags().BoolVarP(pcFlags.IsUnixSocket, "use-uds", "U", *pcFlags.IsUnixSocket, "use unix domain sockets instead of tcp")
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Flags struct {
DisableDotEnv *bool
IsTuiFullScreen *bool
IsDetached *bool
IsDetachedWithTui *bool
}

// NewFlags returns new configuration flags.
Expand Down Expand Up @@ -101,6 +102,7 @@ func NewFlags() *Flags {
DisableDotEnv: toPtr(getDisableDotEnvDefault()),
IsTuiFullScreen: toPtr(getTuiFullScreenDefault()),
IsDetached: toPtr(false),
IsDetachedWithTui: toPtr(false),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
"project",
"list",
"ls",
"--detached-with-tui",
}
)

Expand Down
10 changes: 5 additions & 5 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,19 @@ func (pv *pcView) exitSearch() {

func (pv *pcView) terminateAppView() {

result := "This will terminate all the running processes."
result := "Are you sure you want to quit?\nThis will terminate all the running processes."
if pv.project.IsRemote() {
result = ""
result = "Detach from the remote project?"
}
if pv.isExitConfirmDisabled {
go pv.handleShutDown()
return
}
m := tview.NewModal().
SetText("Are you sure you want to quit?\n" + result).
AddButtons([]string{"Quit", "Cancel"}).
SetText(result).
AddButtons([]string{"Yes", "No"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Quit" {
if buttonLabel == "Yes" {
go pv.handleShutDown()
}
pv.pages.SwitchToPage(PageMain)
Expand Down

0 comments on commit 6b9ce00

Please sign in to comment.