Skip to content

Commit

Permalink
Issue #161: Added full screen toggle shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Mar 22, 2024
1 parent 511bd6c commit 91eb665
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/tui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
ActionProcFilter = ActionName("proc_filter")
ActionThemeSelector = ActionName("theme_selector")
ActionSendToBackground = ActionName("send_to_background")
ActionFullScreen = ActionName("full_screen")
)

var defaultShortcuts = map[ActionName]tcell.Key{
Expand All @@ -59,6 +60,7 @@ var defaultShortcuts = map[ActionName]tcell.Key{
ActionProcFilter: tcell.KeyRune,
ActionThemeSelector: tcell.KeyCtrlT,
ActionSendToBackground: tcell.KeyCtrlB,
ActionFullScreen: tcell.KeyCtrlRightSq,
}

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

var logActionsOrder = []ActionName{
Expand Down Expand Up @@ -298,6 +301,9 @@ func getDefaultActions() *ShortCuts {
ActionSendToBackground: {
Description: "Send Process Compose to Background",
},
ActionFullScreen: {
Description: "Toggle Full Screen",
},
},
}
for k, v := range sc.ShortCutKeys {
Expand Down
40 changes: 28 additions & 12 deletions src/tui/main-grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
)

func (pv *pcView) createGrid() {
pv.mainGrid.SetBorders(true)
row := 0
pv.mainGrid.SetBorders(true).
AddItem(pv.statTable, row, 0, 1, 1, 0, 0, false)
row++
if !pv.isFullScreen {
pv.mainGrid.AddItem(pv.statTable, row, 0, 1, 1, 0, 0, false)
row++
}
if pv.commandMode {
textInput := pv.getSearchInput()
pv.mainGrid.AddItem(textInput, row, 0, 1, 1, 0, 0, true)
Expand All @@ -22,23 +24,23 @@ func (pv *pcView) createGrid() {
} else {
log = pv.logsTextArea
}
switch pv.fullScrState {
switch pv.scrSplitState {
case LogFull:
pv.mainGrid.AddItem(log, row, 0, 2, 1, 0, 0, true)
pv.mainGrid.AddItem(log, row, 0, 1, 1, 0, 0, true)
row++
case ProcFull:
pv.mainGrid.AddItem(pv.procTable, row, 0, 2, 1, 0, 0, !pv.commandMode)
pv.mainGrid.AddItem(pv.procTable, row, 0, 1, 1, 0, 0, !pv.commandMode)
row++
case LogProcHalf:
pv.mainGrid.AddItem(pv.procTable, row, 0, 1, 1, 0, 0, !pv.commandMode)
row++
pv.mainGrid.AddItem(log, row, 0, 1, 1, 0, 0, false)
row++
}
pv.mainGrid.AddItem(pv.helpText, row, 0, 1, 1, 0, 0, false)
if !pv.isFullScreen {
pv.mainGrid.AddItem(pv.helpText, row, 0, 1, 1, 0, 0, false)
}
pv.autoAdjustProcTableHeight()

pv.mainGrid.SetTitle("Process Compose")
}

func (pv *pcView) autoAdjustProcTableHeight() {
Expand All @@ -47,11 +49,26 @@ func (pv *pcView) autoAdjustProcTableHeight() {
if procTblHeight > maxProcHeight {
procTblHeight = maxProcHeight
}
rows := []int{pv.statTable.GetRowCount()}
rows := []int{}
if !pv.isFullScreen {
//stat table
rows = append(rows, pv.statTable.GetRowCount())
}
if pv.commandMode {
//search row
rows = append(rows, 1)
}
if pv.scrSplitState == LogProcHalf {
rows = append(rows, procTblHeight, 0)
} else {
// full proc or full log
rows = append(rows, 0)
}

if !pv.isFullScreen {
//help row
rows = append(rows, 1)
}
rows = append(rows, procTblHeight, 0, 1)
//stat table, (command), processes table, logs, help text
//0 means to take all the available height
pv.mainGrid.SetRows(rows...)
Expand All @@ -62,7 +79,6 @@ func (pv *pcView) getSearchInput() tview.Primitive {
textInput.SetFieldBackgroundColor(pv.styles.Dialog().FieldBgColor.Color())
textInput.SetFieldTextColor(pv.styles.Dialog().FieldFgColor.Color())
textInput.SetLabelColor(pv.styles.Dialog().LabelFgColor.Color())
//textInput.SetBackgroundColor(pv.styles.HlColor())
textInput.SetLabelStyle(textInput.GetLabelStyle().Background(pv.styles.BgColor()))

textInput.SetDoneFunc(func(key tcell.Key) {
Expand Down
2 changes: 1 addition & 1 deletion src/tui/proc-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (pv *pcView) onTableSelectionChange(_, _ int) {
}
pv.logsText.resetSearch()
pv.updateHelpTextView()
pv.logsText.SetBorder(true).SetTitle(name)
pv.logsText.SetTitle(name)
pv.unFollowLog()
pv.followLog(name)
if !pv.logFollow {
Expand Down
36 changes: 20 additions & 16 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"github.com/rivo/tview"
)

type FullScrState int
type ScrSplitState int

const (
LogFull FullScrState = 0
ProcFull = 1
LogProcHalf = 2
LogFull ScrSplitState = 0
ProcFull = 1
LogProcHalf = 2
)

const (
Expand All @@ -49,7 +49,7 @@ type pcView struct {
procNames []string
logFollow bool
logSelect bool
fullScrState FullScrState
scrSplitState ScrSplitState
loggedProc string
shortcuts *ShortCuts
procCountCell *tview.TableCell
Expand All @@ -76,6 +76,7 @@ type pcView struct {
themes *config.Themes
helpDialog *helpDialog
settings *config.Settings
isFullScreen bool
}

func newPcView(project app.IProject) *pcView {
Expand All @@ -85,7 +86,7 @@ func newPcView(project app.IProject) *pcView {
logsText: NewLogView(project.GetLogLength()),
statusText: tview.NewTextView().SetDynamicColors(true),
logFollow: true,
fullScrState: LogProcHalf,
scrSplitState: LogProcHalf,
helpText: tview.NewTextView().SetDynamicColors(true),
loggedProc: "",
shortcuts: getDefaultActions(),
Expand Down Expand Up @@ -169,10 +170,10 @@ func (pv *pcView) onMainGridKey(event *tcell.EventKey) *tcell.EventKey {
case pv.shortcuts.ShortCutKeys[ActionQuit].key:
pv.terminateAppView()
case pv.shortcuts.ShortCutKeys[ActionLogScreen].key:
if pv.fullScrState == LogFull {
pv.fullScrState = LogProcHalf
if pv.scrSplitState == LogFull {
pv.scrSplitState = LogProcHalf
} else {
pv.fullScrState = LogFull
pv.scrSplitState = LogFull
}
pv.redrawGrid()
pv.updateHelpTextView()
Expand All @@ -190,10 +191,10 @@ func (pv *pcView) onMainGridKey(event *tcell.EventKey) *tcell.EventKey {
pv.appView.SetFocus(pv.logsTextArea)
pv.updateHelpTextView()
case pv.shortcuts.ShortCutKeys[ActionProcessScreen].key:
if pv.fullScrState == ProcFull {
pv.fullScrState = LogProcHalf
if pv.scrSplitState == ProcFull {
pv.scrSplitState = LogProcHalf
} else {
pv.fullScrState = ProcFull
pv.scrSplitState = ProcFull
}
pv.redrawGrid()
pv.onProcRowSpanChange()
Expand Down Expand Up @@ -230,9 +231,12 @@ func (pv *pcView) onMainGridKey(event *tcell.EventKey) *tcell.EventKey {
pv.showThemeSelector()
case pv.shortcuts.ShortCutKeys[ActionSendToBackground].key:
pv.runShellProcess()
case pv.shortcuts.ShortCutKeys[ActionFullScreen].key:
pv.isFullScreen = !pv.isFullScreen
pv.logsText.SetBorder(!pv.isFullScreen)
pv.redrawGrid()
case tcell.KeyRune:
if event.Rune() == pv.shortcuts.ShortCutKeys[ActionProcFilter].rune {
//pv.showProcFilter()
pv.commandMode = true
pv.redrawGrid()
} else {
Expand Down Expand Up @@ -341,14 +345,14 @@ func (pv *pcView) getSelectedProcName() string {
}

func (pv *pcView) onProcRowSpanChange() {
if pv.fullScrState == ProcFull && pv.logFollow {
if pv.scrSplitState == ProcFull && pv.logFollow {
pv.stopFollowLog()
}
}

func (pv *pcView) updateHelpTextView() {
logScrBool := pv.fullScrState != LogFull
procScrBool := pv.fullScrState != ProcFull
logScrBool := pv.scrSplitState != LogFull
procScrBool := pv.scrSplitState != ProcFull
pv.helpText.Clear()
if pv.logsText.isSearchActive() {
pv.shortcuts.writeButton(ActionLogFind, pv.helpText)
Expand Down

0 comments on commit 91eb665

Please sign in to comment.