func (hds *Heads) PrevWorkspace() *workspace.Workspace { if cur := hds.GlobalIndex(hds.ActiveWorkspace()); cur > -1 { // I f*****g hate Go's modulo operator. WTF. prev := misc.Mod(cur-1, len(hds.Workspaces.Wrks)) return hds.Workspaces.Get(prev) } panic("bug") }
func (cmd HeadCycle) Run() gribble.Value { return syncRun(func() gribble.Value { cur := wm.Heads.VisibleIndex(wm.Workspace()) next := misc.Mod(cur+1, wm.Heads.NumHeads()) wm.Heads.WithVisibleWorkspace(next, func(wrk *workspace.Workspace) { wm.SetWorkspace(wrk, false) }) wm.FocusFallback() return nil }) }
// Prev will highlight the previous choice in the dialog. func (cycle *Cycle) Prev() { if !cycle.showing { return } if cycle.selected == -1 { cycle.selected = len(cycle.items) - 1 } else { cycle.selected-- } cycle.selected = misc.Mod(cycle.selected, len(cycle.items)) cycle.highlight() }
// Next will highlight the next choice in the dialog. func (cycle *Cycle) Next() { if !cycle.showing { return } if cycle.selected == -1 { if len(cycle.items) > 1 { cycle.selected = 1 } else { cycle.selected = 0 } } else { cycle.selected++ } cycle.selected = misc.Mod(cycle.selected, len(cycle.items)) cycle.highlight() }