Skip to content

Commit

Permalink
Merge pull request #6 from CLIP-HPC/4-rfe-add-shift+tab-keyboard-shor…
Browse files Browse the repository at this point in the history
…tcut-to-get-to-the-previous-tab

add: shift+tab key
  • Loading branch information
pja237 authored Dec 20, 2022
2 parents 160e515 + 6ebf4b3 commit f8ef101
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/keybindings/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type KeyMap struct {
PageUp key.Binding
PageDown key.Binding
Tab key.Binding
ShiftTab key.Binding
Slash key.Binding
Info key.Binding
Enter key.Binding
Expand Down Expand Up @@ -56,6 +57,10 @@ var DefaultKeyMap = KeyMap{
key.WithKeys("tab"),
key.WithHelp("tab", "Cycle tabs"),
),
ShiftTab: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp("shift+tab", "Cycle tabs backwards"),
),
Quit: key.NewBinding(
key.WithKeys("q", "ctrl+c"),
key.WithHelp("q", "Quit scom"),
Expand Down Expand Up @@ -92,6 +97,7 @@ func (km KeyMap) ShortHelp() []key.Binding {
km.PageUp,
km.PageDown,
km.Tab,
km.ShiftTab,
km.Slash,
km.Info,
km.Stats,
Expand Down
4 changes: 3 additions & 1 deletion internal/model/tabs/jobfromtemplate/jobfromtemplatekeys.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jobfromtemplate

import (
"github.com/charmbracelet/bubbles/key"
"github.com/CLIP-HPC/SlurmCommander/internal/keybindings"
"github.com/charmbracelet/bubbles/key"
)

type Keys map[*key.Binding]bool
Expand All @@ -14,6 +14,7 @@ var KeyMap = Keys{
&keybindings.DefaultKeyMap.PageUp: false,
&keybindings.DefaultKeyMap.PageDown: false,
&keybindings.DefaultKeyMap.Tab: true,
&keybindings.DefaultKeyMap.ShiftTab: true,
&keybindings.DefaultKeyMap.Slash: false,
&keybindings.DefaultKeyMap.Info: false,
&keybindings.DefaultKeyMap.Enter: true,
Expand All @@ -31,6 +32,7 @@ var EditorKeyMap = Keys{
&keybindings.DefaultKeyMap.PageUp: false,
&keybindings.DefaultKeyMap.PageDown: false,
&keybindings.DefaultKeyMap.Tab: false,
&keybindings.DefaultKeyMap.ShiftTab: false,
&keybindings.DefaultKeyMap.Slash: false,
&keybindings.DefaultKeyMap.Info: false,
&keybindings.DefaultKeyMap.Enter: false,
Expand Down
33 changes: 29 additions & 4 deletions internal/model/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"strings"
"time"

"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/CLIP-HPC/SlurmCommander/internal/command"
"github.com/CLIP-HPC/SlurmCommander/internal/keybindings"
"github.com/CLIP-HPC/SlurmCommander/internal/model/tabs/clustertab"
Expand All @@ -20,6 +16,10 @@ import (
"github.com/CLIP-HPC/SlurmCommander/internal/slurm"
"github.com/CLIP-HPC/SlurmCommander/internal/styles"
"github.com/CLIP-HPC/SlurmCommander/internal/table"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)

type errMsg error
Expand Down Expand Up @@ -537,6 +537,31 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}

// Shift+TAB
case key.Matches(msg, keybindings.DefaultKeyMap.ShiftTab):
// switch tab
if m.ActiveTab == 0 {
m.ActiveTab = uint(len(tabs) - 1)
} else {
m.ActiveTab -= 1
}
// setup keys
tabKeys[m.ActiveTab].SetupKeys()
m.lastKey = "tab"

// clear error states
m.Globals.ErrorHelp = ""
m.Globals.ErrorMsg = nil

switch m.ActiveTab {
case tabJobs:
return m, jobtab.TimedGetSqueue(m.Log)
case tabCluster:
return m, clustertab.TimedGetSinfo(m.Log)
default:
return m, nil
}

// SLASH
case key.Matches(msg, keybindings.DefaultKeyMap.Slash):
switch {
Expand Down

0 comments on commit f8ef101

Please sign in to comment.