Skip to content

Commit

Permalink
Issue #163: Send process compose to background
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Mar 22, 2024
1 parent 23093e3 commit 265aa4e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
86 changes: 46 additions & 40 deletions src/tui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,51 @@ import (
type ActionName string

const (
ActionHelp = ActionName("help")
ActionLogScreen = ActionName("log_screen")
ActionFollowLog = ActionName("log_follow")
ActionWrapLog = ActionName("log_wrap")
ActionLogSelection = ActionName("log_select")
ActionProcessStart = ActionName("process_start")
ActionProcessScale = ActionName("process_scale")
ActionProcessInfo = ActionName("process_info")
ActionProcessStop = ActionName("process_stop")
ActionProcessRestart = ActionName("process_restart")
ActionProcessScreen = ActionName("process_screen")
ActionQuit = ActionName("quit")
ActionLogFind = ActionName("find")
ActionLogFindNext = ActionName("find_next")
ActionLogFindPrev = ActionName("find_prev")
ActionLogFindExit = ActionName("find_exit")
ActionNsFilter = ActionName("ns_filter")
ActionHideDisabled = ActionName("hide_disabled")
ActionProcFilter = ActionName("proc_filter")
ActionThemeSelector = ActionName("theme_selector")
ActionHelp = ActionName("help")
ActionLogScreen = ActionName("log_screen")
ActionFollowLog = ActionName("log_follow")
ActionWrapLog = ActionName("log_wrap")
ActionLogSelection = ActionName("log_select")
ActionProcessStart = ActionName("process_start")
ActionProcessScale = ActionName("process_scale")
ActionProcessInfo = ActionName("process_info")
ActionProcessStop = ActionName("process_stop")
ActionProcessRestart = ActionName("process_restart")
ActionProcessScreen = ActionName("process_screen")
ActionQuit = ActionName("quit")
ActionLogFind = ActionName("find")
ActionLogFindNext = ActionName("find_next")
ActionLogFindPrev = ActionName("find_prev")
ActionLogFindExit = ActionName("find_exit")
ActionNsFilter = ActionName("ns_filter")
ActionHideDisabled = ActionName("hide_disabled")
ActionProcFilter = ActionName("proc_filter")
ActionThemeSelector = ActionName("theme_selector")
ActionSendToBackground = ActionName("send_to_background")
)

var defaultShortcuts = map[ActionName]tcell.Key{
ActionHelp: tcell.KeyF1,
ActionLogScreen: tcell.KeyF4,
ActionFollowLog: tcell.KeyF5,
ActionWrapLog: tcell.KeyF6,
ActionLogSelection: tcell.KeyCtrlS,
ActionProcessScale: tcell.KeyF2,
ActionProcessInfo: tcell.KeyF3,
ActionProcessStart: tcell.KeyF7,
ActionProcessStop: tcell.KeyF9,
ActionProcessRestart: tcell.KeyCtrlR,
ActionProcessScreen: tcell.KeyF8,
ActionQuit: tcell.KeyF10,
ActionLogFind: tcell.KeyCtrlF,
ActionLogFindNext: tcell.KeyCtrlN,
ActionLogFindPrev: tcell.KeyCtrlP,
ActionLogFindExit: tcell.KeyEsc,
ActionNsFilter: tcell.KeyCtrlG,
ActionHideDisabled: tcell.KeyCtrlD,
ActionProcFilter: tcell.KeyRune,
ActionThemeSelector: tcell.KeyCtrlT,
ActionHelp: tcell.KeyF1,
ActionLogScreen: tcell.KeyF4,
ActionFollowLog: tcell.KeyF5,
ActionWrapLog: tcell.KeyF6,
ActionLogSelection: tcell.KeyCtrlS,
ActionProcessScale: tcell.KeyF2,
ActionProcessInfo: tcell.KeyF3,
ActionProcessStart: tcell.KeyF7,
ActionProcessStop: tcell.KeyF9,
ActionProcessRestart: tcell.KeyCtrlR,
ActionProcessScreen: tcell.KeyF8,
ActionQuit: tcell.KeyF10,
ActionLogFind: tcell.KeyCtrlF,
ActionLogFindNext: tcell.KeyCtrlN,
ActionLogFindPrev: tcell.KeyCtrlP,
ActionLogFindExit: tcell.KeyEsc,
ActionNsFilter: tcell.KeyCtrlG,
ActionHideDisabled: tcell.KeyCtrlD,
ActionProcFilter: tcell.KeyRune,
ActionThemeSelector: tcell.KeyCtrlT,
ActionSendToBackground: tcell.KeyCtrlB,
}

var defaultShortcutsRunes = map[ActionName]rune{
Expand All @@ -66,6 +68,7 @@ var defaultShortcutsRunes = map[ActionName]rune{
var generalActionsOrder = []ActionName{
ActionHelp,
ActionThemeSelector,
ActionSendToBackground,
}

var logActionsOrder = []ActionName{
Expand Down Expand Up @@ -292,6 +295,9 @@ func getDefaultActions() *ShortCuts {
ActionThemeSelector: {
Description: "Select Theme",
},
ActionSendToBackground: {
Description: "Send Process Compose to Background",
},
},
}
for k, v := range sc.ShortCutKeys {
Expand Down
14 changes: 13 additions & 1 deletion src/tui/proc-starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tui
import (
"context"
"fmt"
"github.com/f1bonacc1/process-compose/src/command"
"github.com/f1bonacc1/process-compose/src/types"
"github.com/rs/zerolog/log"
"os"
Expand All @@ -28,6 +29,17 @@ func (pv *pcView) startProcess() {
}
}

func (pv *pcView) runShellProcess() {
shell := command.DefaultShellConfig()
shellCmd := &types.ProcessConfig{
Executable: shell.ShellCommand,
RestartPolicy: types.RestartPolicyConfig{
Restart: types.RestartPolicyNo,
},
}
pv.runForeground(shellCmd)
}

func (pv *pcView) runForeground(info *types.ProcessConfig) bool {
pv.halt()
defer pv.resume()
Expand All @@ -43,7 +55,7 @@ func (pv *pcView) execute(info *types.ProcessConfig) error {
ctx, cancel := context.WithCancel(context.Background())
defer func() {
cancel()
clearScreen()
//clearScreen()
}()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
Expand Down
2 changes: 2 additions & 0 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func (pv *pcView) onMainGridKey(event *tcell.EventKey) *tcell.EventKey {
pv.showDialog(pv.helpDialog, 50, 30)
case pv.shortcuts.ShortCutKeys[ActionThemeSelector].key:
pv.showThemeSelector()
case pv.shortcuts.ShortCutKeys[ActionSendToBackground].key:
pv.runShellProcess()
case tcell.KeyRune:
if event.Rune() == pv.shortcuts.ShortCutKeys[ActionProcFilter].rune {
//pv.showProcFilter()
Expand Down

0 comments on commit 265aa4e

Please sign in to comment.