vim

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 6 Imported by: 5

Documentation

Overview

Package vim provides utilities for parsing and generating vim-like keystrokes. This is heavily tailored towards compatibility with key events constructed by tcell, for use in terminals.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultEmacsDownKeys = []KeyPress{KeyCtrl('n')}
	DefaultEmacsUpKeys   = []KeyPress{KeyCtrl('p')}
	DefaultVimDownKeys   = []KeyPress{Key('j')}
	DefaultVimUpKeys     = []KeyPress{Key('k')}
	DefaultDownKeys      = []KeyPress{KeyPressDown}
	DefaultUpKeys        = []KeyPress{KeyPressUp}
	AllDownKeys          = append(DefaultDownKeys, append(DefaultEmacsDownKeys, DefaultVimDownKeys...)...)
	AllUpKeys            = append(DefaultUpKeys, append(DefaultEmacsUpKeys, DefaultVimUpKeys...)...)

	DefaultEmacsLeftKeys  = []KeyPress{KeyCtrl('b')}
	DefaultEmacsRightKeys = []KeyPress{KeyCtrl('f')}
	DefaultVimLeftKeys    = []KeyPress{Key('h')}
	DefaultVimRightKeys   = []KeyPress{Key('l')}
	DefaultLeftKeys       = []KeyPress{KeyPressLeft}
	DefaultRightKeys      = []KeyPress{KeyPressRight}
	AllLeftKeys           = append(DefaultLeftKeys, append(DefaultEmacsLeftKeys, DefaultVimLeftKeys...)...)
	AllRightKeys          = append(DefaultRightKeys, append(DefaultEmacsRightKeys, DefaultVimRightKeys...)...)

	ModMapReverse = map[string]tcell.ModMask{
		"C": tcell.ModCtrl,
		"c": tcell.ModCtrl,
		"A": tcell.ModAlt,
		"a": tcell.ModAlt,
		"S": tcell.ModShift,
		"s": tcell.ModShift,
	}

	ModMap = map[tcell.ModMask]string{
		tcell.ModCtrl:  "C",
		tcell.ModAlt:   "A",
		tcell.ModShift: "S",
	}

	SpecialKeyMapReverse = map[string]tcell.Key{
		"<Up>":    tcell.KeyUp,
		"<Down>":  tcell.KeyDown,
		"<Left>":  tcell.KeyLeft,
		"<Right>": tcell.KeyRight,
		"<Enter>": tcell.KeyEnter,
		"<Esc>":   tcell.KeyEscape,
		"<Tab>":   tcell.KeyTab,
		"<Home>":  tcell.KeyHome,
		"<End>":   tcell.KeyEnd,
		"<PgUp>":  tcell.KeyPgUp,
		"<PgDn>":  tcell.KeyPgDn,
		"<F1>":    tcell.KeyF1,
		"<F2>":    tcell.KeyF2,
		"<F3>":    tcell.KeyF3,
		"<F4>":    tcell.KeyF4,
		"<F5>":    tcell.KeyF5,
		"<F6>":    tcell.KeyF6,
		"<F7>":    tcell.KeyF7,
		"<F8>":    tcell.KeyF8,
		"<F9>":    tcell.KeyF9,
		"<F10>":   tcell.KeyF10,
		"<F11>":   tcell.KeyF11,
		"<F12>":   tcell.KeyF12,
	}

	SpecialKeyMap = map[tcell.Key]string{
		tcell.KeyUp:     "<Up>",
		tcell.KeyDown:   "<Down>",
		tcell.KeyLeft:   "<Left>",
		tcell.KeyRight:  "<Right>",
		tcell.KeyEnter:  "<Enter>",
		tcell.KeyEscape: "<Esc>",
		tcell.KeyTab:    "<Tab>",
		tcell.KeyHome:   "<Home>",
		tcell.KeyEnd:    "<End>",
		tcell.KeyPgUp:   "<PgUp>",
		tcell.KeyPgDn:   "<PgDn>",
		tcell.KeyF1:     "<F1>",
		tcell.KeyF2:     "<F2>",
		tcell.KeyF3:     "<F3>",
		tcell.KeyF4:     "<F4>",
		tcell.KeyF5:     "<F5>",
		tcell.KeyF6:     "<F6>",
		tcell.KeyF7:     "<F7>",
		tcell.KeyF8:     "<F8>",
		tcell.KeyF9:     "<F9>",
		tcell.KeyF10:    "<F10>",
		tcell.KeyF11:    "<F11>",
		tcell.KeyF12:    "<F12>",
	}

	KeyPressUp     KeyPress = NewKeyPress(tcell.KeyUp, 0, 0)
	KeyPressDown   KeyPress = NewKeyPress(tcell.KeyDown, 0, 0)
	KeyPressLeft   KeyPress = NewKeyPress(tcell.KeyLeft, 0, 0)
	KeyPressRight  KeyPress = NewKeyPress(tcell.KeyRight, 0, 0)
	KeyPressEnter  KeyPress = NewKeyPress(tcell.KeyEnter, 0, 0)
	KeyPressEscape KeyPress = NewKeyPress(tcell.KeyEscape, 0, 0)
	KeyPressTab    KeyPress = NewKeyPress(tcell.KeyTab, 0, 0)
	KeyPressHome   KeyPress = NewKeyPress(tcell.KeyTab, 0, 0)
	KeyPressEnd    KeyPress = NewKeyPress(tcell.KeyTab, 0, 0)
	KeyPressPgUp   KeyPress = NewKeyPress(tcell.KeyPgUp, 0, 0)
	KeyPressPgDn   KeyPress = NewKeyPress(tcell.KeyPgDn, 0, 0)
	KeyPressF1     KeyPress = NewKeyPress(tcell.KeyF1, 0, 0)
	KeyPressF2     KeyPress = NewKeyPress(tcell.KeyF2, 0, 0)
	KeyPressF3     KeyPress = NewKeyPress(tcell.KeyF3, 0, 0)
	KeyPressF4     KeyPress = NewKeyPress(tcell.KeyF4, 0, 0)
	KeyPressF5     KeyPress = NewKeyPress(tcell.KeyF5, 0, 0)
	KeyPressF6     KeyPress = NewKeyPress(tcell.KeyF6, 0, 0)
	KeyPressF7     KeyPress = NewKeyPress(tcell.KeyF7, 0, 0)
	KeyPressF8     KeyPress = NewKeyPress(tcell.KeyF8, 0, 0)
	KeyPressF9     KeyPress = NewKeyPress(tcell.KeyF9, 0, 0)
	KeyPressF10    KeyPress = NewKeyPress(tcell.KeyF10, 0, 0)
	KeyPressF11    KeyPress = NewKeyPress(tcell.KeyF11, 0, 0)
	KeyPressF12    KeyPress = NewKeyPress(tcell.KeyF12, 0, 0)

	KeyPressF = []KeyPress{
		KeyPressF1,
		KeyPressF2,
		KeyPressF3,
		KeyPressF4,
		KeyPressF5,
		KeyPressF6,
		KeyPressF7,
		KeyPressF8,
		KeyPressF9,
		KeyPressF10,
		KeyPressF11,
		KeyPressF12,
	}
)

Functions

func KeyIn

func KeyIn(k *tcell.EventKey, keys []KeyPress) bool

Types

type KeyPress

type KeyPress gowid.Key

KeyPress represents a gowid keypress. It's a tcell.EventKey without the time of the keypress.

func Key

func Key(ch rune) KeyPress

func KeyCtrl

func KeyCtrl(r rune) KeyPress

func KeyPressFromTcell

func KeyPressFromTcell(k *tcell.EventKey) KeyPress

KeyPressFromTcell converts a *tcell.EventKey to a KeyPress. This can then be serialized to a vim-style keypress e.g. <C-s>

func NewKeyPress

func NewKeyPress(k tcell.Key, ch rune, mod tcell.ModMask) KeyPress

func NewSimpleKeyPress

func NewSimpleKeyPress(ch rune) KeyPress

func (KeyPress) String

func (k KeyPress) String() string

type KeySequence

type KeySequence []KeyPress

KeySequence is an array of KeyPress. The KeySequence type allows the sequence to be serialized the way vim would do it e.g. <C-s>abc<Esc>

func VimStringToKeys

func VimStringToKeys(input string) KeySequence

VimStringToKeys converts e.g. <C-s>abc<Esc> into a sequence of KeyPress

func (KeySequence) String

func (ks KeySequence) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL