diff --git a/internal/keybindings/keybindings.go b/internal/keybindings/keybindings.go index 8463ec7..6982938 100644 --- a/internal/keybindings/keybindings.go +++ b/internal/keybindings/keybindings.go @@ -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 @@ -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"), @@ -92,6 +97,7 @@ func (km KeyMap) ShortHelp() []key.Binding { km.PageUp, km.PageDown, km.Tab, + km.ShiftTab, km.Slash, km.Info, km.Stats, diff --git a/internal/model/tabs/jobfromtemplate/jobfromtemplatekeys.go b/internal/model/tabs/jobfromtemplate/jobfromtemplatekeys.go index 620c0e8..939e1c3 100644 --- a/internal/model/tabs/jobfromtemplate/jobfromtemplatekeys.go +++ b/internal/model/tabs/jobfromtemplate/jobfromtemplatekeys.go @@ -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 @@ -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, @@ -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, diff --git a/internal/model/update.go b/internal/model/update.go index 93ef27b..3e88059 100644 --- a/internal/model/update.go +++ b/internal/model/update.go @@ -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" @@ -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 @@ -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 {