mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
131 lines
4.7 KiB
Go
131 lines
4.7 KiB
Go
// Copyright 2014 The gocui Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gocui
|
|
|
|
import (
|
|
"github.com/gdamore/tcell/v3"
|
|
)
|
|
|
|
// KeyName represents special keys or keys combinations.
|
|
type KeyName tcell.Key
|
|
|
|
// Modifier allows to define special keys combinations. They can be used
|
|
// in combination with Keys or Runes when a new keybinding is defined.
|
|
type Modifier tcell.ModMask
|
|
|
|
// Keybindings are used to link a given key-press event with a handler.
|
|
type keybinding struct {
|
|
viewName string
|
|
key Key
|
|
mod Modifier
|
|
handler func(*Gui, *View) error
|
|
}
|
|
|
|
// newKeybinding returns a new Keybinding object.
|
|
func newKeybinding(viewname string, key Key, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) {
|
|
kb = &keybinding{
|
|
viewName: viewname,
|
|
key: key,
|
|
mod: mod,
|
|
handler: handler,
|
|
}
|
|
return kb
|
|
}
|
|
|
|
// matchKeypress returns if the keybinding matches the keypress.
|
|
func (kb *keybinding) matchKeypress(key Key, mod Modifier) bool {
|
|
return kb.key.Equals(key) && kb.mod == mod
|
|
}
|
|
|
|
// Special keys.
|
|
const (
|
|
KeyF1 KeyName = KeyName(tcell.KeyF1)
|
|
KeyF2 = KeyName(tcell.KeyF2)
|
|
KeyF3 = KeyName(tcell.KeyF3)
|
|
KeyF4 = KeyName(tcell.KeyF4)
|
|
KeyF5 = KeyName(tcell.KeyF5)
|
|
KeyF6 = KeyName(tcell.KeyF6)
|
|
KeyF7 = KeyName(tcell.KeyF7)
|
|
KeyF8 = KeyName(tcell.KeyF8)
|
|
KeyF9 = KeyName(tcell.KeyF9)
|
|
KeyF10 = KeyName(tcell.KeyF10)
|
|
KeyF11 = KeyName(tcell.KeyF11)
|
|
KeyF12 = KeyName(tcell.KeyF12)
|
|
KeyInsert = KeyName(tcell.KeyInsert)
|
|
KeyDelete = KeyName(tcell.KeyDelete)
|
|
KeyHome = KeyName(tcell.KeyHome)
|
|
KeyEnd = KeyName(tcell.KeyEnd)
|
|
KeyPgdn = KeyName(tcell.KeyPgDn)
|
|
KeyPgup = KeyName(tcell.KeyPgUp)
|
|
KeyArrowUp = KeyName(tcell.KeyUp)
|
|
KeyShiftArrowUp = KeyName(tcell.KeyF62)
|
|
KeyArrowDown = KeyName(tcell.KeyDown)
|
|
KeyShiftArrowDown = KeyName(tcell.KeyF63)
|
|
KeyArrowLeft = KeyName(tcell.KeyLeft)
|
|
KeyArrowRight = KeyName(tcell.KeyRight)
|
|
)
|
|
|
|
// Keys combinations.
|
|
const (
|
|
KeyCtrlTilde = KeyName(tcell.KeyF64) // arbitrary assignment
|
|
KeyCtrlA = KeyName(tcell.KeyCtrlA)
|
|
KeyCtrlB = KeyName(tcell.KeyCtrlB)
|
|
KeyCtrlC = KeyName(tcell.KeyCtrlC)
|
|
KeyCtrlD = KeyName(tcell.KeyCtrlD)
|
|
KeyCtrlE = KeyName(tcell.KeyCtrlE)
|
|
KeyCtrlF = KeyName(tcell.KeyCtrlF)
|
|
KeyCtrlG = KeyName(tcell.KeyCtrlG)
|
|
KeyBackspace = KeyName(tcell.KeyBackspace)
|
|
KeyCtrlH = KeyName(tcell.KeyCtrlH)
|
|
KeyTab = KeyName(tcell.KeyTab)
|
|
KeyBacktab = KeyName(tcell.KeyBacktab)
|
|
KeyCtrlI = KeyName(tcell.KeyCtrlI)
|
|
KeyCtrlJ = KeyName(tcell.KeyCtrlJ)
|
|
KeyCtrlK = KeyName(tcell.KeyCtrlK)
|
|
KeyCtrlL = KeyName(tcell.KeyCtrlL)
|
|
KeyEnter = KeyName(tcell.KeyEnter)
|
|
KeyCtrlM = KeyName(tcell.KeyCtrlM)
|
|
KeyCtrlN = KeyName(tcell.KeyCtrlN)
|
|
KeyCtrlO = KeyName(tcell.KeyCtrlO)
|
|
KeyCtrlP = KeyName(tcell.KeyCtrlP)
|
|
KeyCtrlQ = KeyName(tcell.KeyCtrlQ)
|
|
KeyCtrlR = KeyName(tcell.KeyCtrlR)
|
|
KeyCtrlS = KeyName(tcell.KeyCtrlS)
|
|
KeyCtrlT = KeyName(tcell.KeyCtrlT)
|
|
KeyCtrlU = KeyName(tcell.KeyCtrlU)
|
|
KeyCtrlV = KeyName(tcell.KeyCtrlV)
|
|
KeyCtrlW = KeyName(tcell.KeyCtrlW)
|
|
KeyCtrlX = KeyName(tcell.KeyCtrlX)
|
|
KeyCtrlY = KeyName(tcell.KeyCtrlY)
|
|
KeyCtrlZ = KeyName(tcell.KeyCtrlZ)
|
|
KeyEsc = KeyName(tcell.KeyEscape)
|
|
KeySpace = KeyName(32)
|
|
KeyBackspace2 = KeyName(tcell.KeyBackspace2)
|
|
KeyCtrl8 = KeyName(tcell.KeyBackspace2) // same key as in termbox-go
|
|
|
|
// The following assignments were used in termbox implementation.
|
|
// In tcell, these are not keys per se. But in gocui we have them
|
|
// mapped to the keys so we have to use placeholder keys.
|
|
|
|
KeyAltEnter = KeyName(tcell.KeyF64) // arbitrary assignments
|
|
MouseLeft = KeyName(tcell.KeyF63)
|
|
MouseRight = KeyName(tcell.KeyF62)
|
|
MouseMiddle = KeyName(tcell.KeyF61)
|
|
MouseRelease = KeyName(tcell.KeyF60)
|
|
MouseWheelUp = KeyName(tcell.KeyF59)
|
|
MouseWheelDown = KeyName(tcell.KeyF58)
|
|
MouseWheelLeft = KeyName(tcell.KeyF57)
|
|
MouseWheelRight = KeyName(tcell.KeyF56)
|
|
)
|
|
|
|
// Modifiers.
|
|
const (
|
|
ModNone Modifier = Modifier(0)
|
|
ModAlt = Modifier(tcell.ModAlt)
|
|
ModMotion = Modifier(2) // just picking an arbitrary number here that doesn't clash with tcell.ModAlt
|
|
// ModCtrl doesn't work with keyboard keys. Use CtrlKey in Key and ModNone. This is was for mouse clicks only (tcell.v1)
|
|
// ModCtrl = Modifier(tcell.ModCtrl)
|
|
)
|