mirror of
https://github.com/zyedidia/micro
synced 2024-11-05 17:41:24 +00:00
Use the new and updated version of tcell
This commit is contained in:
parent
77d8a2217f
commit
ebaad9b00c
3 changed files with 163 additions and 159 deletions
|
@ -13,11 +13,17 @@ import (
|
|||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
var bindings map[tcell.Key]func(*View) bool
|
||||
var bindings map[Key]func(*View) bool
|
||||
|
||||
// The Key struct holds the data for a keypress (keycode + modifiers)
|
||||
type Key struct {
|
||||
keyCode tcell.Key
|
||||
modifiers tcell.ModMask
|
||||
}
|
||||
|
||||
// InitBindings initializes the keybindings for micro
|
||||
func InitBindings() {
|
||||
bindings = make(map[tcell.Key]func(*View) bool)
|
||||
bindings = make(map[Key]func(*View) bool)
|
||||
|
||||
actions := map[string]func(*View) bool{
|
||||
"CursorUp": (*View).CursorUp,
|
||||
|
@ -67,152 +73,151 @@ func InitBindings() {
|
|||
"JumpLine": (*View).JumpLine,
|
||||
}
|
||||
|
||||
keys := map[string]tcell.Key{
|
||||
"Up": tcell.KeyUp,
|
||||
"Down": tcell.KeyDown,
|
||||
"Right": tcell.KeyRight,
|
||||
"Left": tcell.KeyLeft,
|
||||
"AltUp": tcell.KeyAltUp,
|
||||
"AltDown": tcell.KeyAltDown,
|
||||
"AltLeft": tcell.KeyAltLeft,
|
||||
"AltRight": tcell.KeyAltRight,
|
||||
"CtrlUp": tcell.KeyCtrlUp,
|
||||
"CtrlDown": tcell.KeyCtrlDown,
|
||||
"CtrlLeft": tcell.KeyCtrlLeft,
|
||||
"CtrlRight": tcell.KeyCtrlRight,
|
||||
"ShiftUp": tcell.KeyShiftUp,
|
||||
"ShiftDown": tcell.KeyShiftDown,
|
||||
"ShiftLeft": tcell.KeyShiftLeft,
|
||||
"ShiftRight": tcell.KeyShiftRight,
|
||||
"AltShiftUp": tcell.KeyAltShiftUp,
|
||||
"AltShiftDown": tcell.KeyAltShiftDown,
|
||||
"AltShiftLeft": tcell.KeyAltShiftLeft,
|
||||
"AltShiftRight": tcell.KeyAltShiftRight,
|
||||
"CtrlShiftUp": tcell.KeyCtrlShiftUp,
|
||||
"CtrlShiftDown": tcell.KeyCtrlShiftDown,
|
||||
"CtrlShiftLeft": tcell.KeyCtrlShiftLeft,
|
||||
"CtrlShiftRight": tcell.KeyCtrlShiftRight,
|
||||
"UpLeft": tcell.KeyUpLeft,
|
||||
"UpRight": tcell.KeyUpRight,
|
||||
"DownLeft": tcell.KeyDownLeft,
|
||||
"DownRight": tcell.KeyDownRight,
|
||||
"Center": tcell.KeyCenter,
|
||||
"PgUp": tcell.KeyPgUp,
|
||||
"PgDn": tcell.KeyPgDn,
|
||||
"Home": tcell.KeyHome,
|
||||
"End": tcell.KeyEnd,
|
||||
"Insert": tcell.KeyInsert,
|
||||
"Delete": tcell.KeyDelete,
|
||||
"Help": tcell.KeyHelp,
|
||||
"Exit": tcell.KeyExit,
|
||||
"Clear": tcell.KeyClear,
|
||||
"Cancel": tcell.KeyCancel,
|
||||
"Print": tcell.KeyPrint,
|
||||
"Pause": tcell.KeyPause,
|
||||
"Backtab": tcell.KeyBacktab,
|
||||
"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,
|
||||
"F13": tcell.KeyF13,
|
||||
"F14": tcell.KeyF14,
|
||||
"F15": tcell.KeyF15,
|
||||
"F16": tcell.KeyF16,
|
||||
"F17": tcell.KeyF17,
|
||||
"F18": tcell.KeyF18,
|
||||
"F19": tcell.KeyF19,
|
||||
"F20": tcell.KeyF20,
|
||||
"F21": tcell.KeyF21,
|
||||
"F22": tcell.KeyF22,
|
||||
"F23": tcell.KeyF23,
|
||||
"F24": tcell.KeyF24,
|
||||
"F25": tcell.KeyF25,
|
||||
"F26": tcell.KeyF26,
|
||||
"F27": tcell.KeyF27,
|
||||
"F28": tcell.KeyF28,
|
||||
"F29": tcell.KeyF29,
|
||||
"F30": tcell.KeyF30,
|
||||
"F31": tcell.KeyF31,
|
||||
"F32": tcell.KeyF32,
|
||||
"F33": tcell.KeyF33,
|
||||
"F34": tcell.KeyF34,
|
||||
"F35": tcell.KeyF35,
|
||||
"F36": tcell.KeyF36,
|
||||
"F37": tcell.KeyF37,
|
||||
"F38": tcell.KeyF38,
|
||||
"F39": tcell.KeyF39,
|
||||
"F40": tcell.KeyF40,
|
||||
"F41": tcell.KeyF41,
|
||||
"F42": tcell.KeyF42,
|
||||
"F43": tcell.KeyF43,
|
||||
"F44": tcell.KeyF44,
|
||||
"F45": tcell.KeyF45,
|
||||
"F46": tcell.KeyF46,
|
||||
"F47": tcell.KeyF47,
|
||||
"F48": tcell.KeyF48,
|
||||
"F49": tcell.KeyF49,
|
||||
"F50": tcell.KeyF50,
|
||||
"F51": tcell.KeyF51,
|
||||
"F52": tcell.KeyF52,
|
||||
"F53": tcell.KeyF53,
|
||||
"F54": tcell.KeyF54,
|
||||
"F55": tcell.KeyF55,
|
||||
"F56": tcell.KeyF56,
|
||||
"F57": tcell.KeyF57,
|
||||
"F58": tcell.KeyF58,
|
||||
"F59": tcell.KeyF59,
|
||||
"F60": tcell.KeyF60,
|
||||
"F61": tcell.KeyF61,
|
||||
"F62": tcell.KeyF62,
|
||||
"F63": tcell.KeyF63,
|
||||
"F64": tcell.KeyF64,
|
||||
"CtrlSpace": tcell.KeyCtrlSpace,
|
||||
"CtrlA": tcell.KeyCtrlA,
|
||||
"CtrlB": tcell.KeyCtrlB,
|
||||
"CtrlC": tcell.KeyCtrlC,
|
||||
"CtrlD": tcell.KeyCtrlD,
|
||||
"CtrlE": tcell.KeyCtrlE,
|
||||
"CtrlF": tcell.KeyCtrlF,
|
||||
"CtrlG": tcell.KeyCtrlG,
|
||||
"CtrlH": tcell.KeyCtrlH,
|
||||
"CtrlI": tcell.KeyCtrlI,
|
||||
"CtrlJ": tcell.KeyCtrlJ,
|
||||
"CtrlK": tcell.KeyCtrlK,
|
||||
"CtrlL": tcell.KeyCtrlL,
|
||||
"CtrlM": tcell.KeyCtrlM,
|
||||
"CtrlN": tcell.KeyCtrlN,
|
||||
"CtrlO": tcell.KeyCtrlO,
|
||||
"CtrlP": tcell.KeyCtrlP,
|
||||
"CtrlQ": tcell.KeyCtrlQ,
|
||||
"CtrlR": tcell.KeyCtrlR,
|
||||
"CtrlS": tcell.KeyCtrlS,
|
||||
"CtrlT": tcell.KeyCtrlT,
|
||||
"CtrlU": tcell.KeyCtrlU,
|
||||
"CtrlV": tcell.KeyCtrlV,
|
||||
"CtrlW": tcell.KeyCtrlW,
|
||||
"CtrlX": tcell.KeyCtrlX,
|
||||
"CtrlY": tcell.KeyCtrlY,
|
||||
"CtrlZ": tcell.KeyCtrlZ,
|
||||
"CtrlLeftSq": tcell.KeyCtrlLeftSq,
|
||||
"CtrlBackslash": tcell.KeyCtrlBackslash,
|
||||
"CtrlRightSq": tcell.KeyCtrlRightSq,
|
||||
"CtrlCarat": tcell.KeyCtrlCarat,
|
||||
"CtrlUnderscore": tcell.KeyCtrlUnderscore,
|
||||
"Backspace": tcell.KeyBackspace,
|
||||
"Tab": tcell.KeyTab,
|
||||
"Esc": tcell.KeyEsc,
|
||||
"Escape": tcell.KeyEscape,
|
||||
"Enter": tcell.KeyEnter,
|
||||
"Space": tcell.KeySpace,
|
||||
"Backspace2": tcell.KeyBackspace2,
|
||||
keys := map[string]Key{
|
||||
"Up": Key{tcell.KeyUp, tcell.ModNone},
|
||||
"Down": Key{tcell.KeyDown, tcell.ModNone},
|
||||
"Right": Key{tcell.KeyRight, tcell.ModNone},
|
||||
"Left": Key{tcell.KeyLeft, tcell.ModNone},
|
||||
"AltUp": Key{tcell.KeyUp, tcell.ModAlt},
|
||||
"AltDown": Key{tcell.KeyDown, tcell.ModAlt},
|
||||
"AltLeft": Key{tcell.KeyLeft, tcell.ModAlt},
|
||||
"AltRight": Key{tcell.KeyRight, tcell.ModAlt},
|
||||
"CtrlUp": Key{tcell.KeyUp, tcell.ModCtrl},
|
||||
"CtrlDown": Key{tcell.KeyDown, tcell.ModCtrl},
|
||||
"CtrlLeft": Key{tcell.KeyLeft, tcell.ModCtrl},
|
||||
"CtrlRight": Key{tcell.KeyRight, tcell.ModCtrl},
|
||||
"ShiftUp": Key{tcell.KeyUp, tcell.ModShift},
|
||||
"ShiftDown": Key{tcell.KeyDown, tcell.ModShift},
|
||||
"ShiftLeft": Key{tcell.KeyLeft, tcell.ModShift},
|
||||
"ShiftRight": Key{tcell.KeyRight, tcell.ModShift},
|
||||
"AltShiftUp": Key{tcell.KeyUp, tcell.ModShift | tcell.ModAlt},
|
||||
"AltShiftDown": Key{tcell.KeyDown, tcell.ModShift | tcell.ModAlt},
|
||||
"AltShiftLeft": Key{tcell.KeyLeft, tcell.ModShift | tcell.ModAlt},
|
||||
"AltShiftRight": Key{tcell.KeyRight, tcell.ModShift | tcell.ModAlt},
|
||||
"CtrlShiftUp": Key{tcell.KeyUp, tcell.ModShift | tcell.ModCtrl},
|
||||
"CtrlShiftDown": Key{tcell.KeyDown, tcell.ModShift | tcell.ModCtrl},
|
||||
"CtrlShiftLeft": Key{tcell.KeyLeft, tcell.ModShift | tcell.ModCtrl},
|
||||
"CtrlShiftRight": Key{tcell.KeyRight, tcell.ModShift | tcell.ModCtrl},
|
||||
"UpLeft": Key{tcell.KeyUpLeft, tcell.ModNone},
|
||||
"UpRight": Key{tcell.KeyUpRight, tcell.ModNone},
|
||||
"DownLeft": Key{tcell.KeyDownLeft, tcell.ModNone},
|
||||
"DownRight": Key{tcell.KeyDownRight, tcell.ModNone},
|
||||
"Center": Key{tcell.KeyCenter, tcell.ModNone},
|
||||
"PgUp": Key{tcell.KeyPgUp, tcell.ModNone},
|
||||
"PgDn": Key{tcell.KeyPgDn, tcell.ModNone},
|
||||
"Home": Key{tcell.KeyHome, tcell.ModNone},
|
||||
"End": Key{tcell.KeyEnd, tcell.ModNone},
|
||||
"Insert": Key{tcell.KeyInsert, tcell.ModNone},
|
||||
"Delete": Key{tcell.KeyDelete, tcell.ModNone},
|
||||
"Help": Key{tcell.KeyHelp, tcell.ModNone},
|
||||
"Exit": Key{tcell.KeyExit, tcell.ModNone},
|
||||
"Clear": Key{tcell.KeyClear, tcell.ModNone},
|
||||
"Cancel": Key{tcell.KeyCancel, tcell.ModNone},
|
||||
"Print": Key{tcell.KeyPrint, tcell.ModNone},
|
||||
"Pause": Key{tcell.KeyPause, tcell.ModNone},
|
||||
"Backtab": Key{tcell.KeyBacktab, tcell.ModNone},
|
||||
"F1": Key{tcell.KeyF1, tcell.ModNone},
|
||||
"F2": Key{tcell.KeyF2, tcell.ModNone},
|
||||
"F3": Key{tcell.KeyF3, tcell.ModNone},
|
||||
"F4": Key{tcell.KeyF4, tcell.ModNone},
|
||||
"F5": Key{tcell.KeyF5, tcell.ModNone},
|
||||
"F6": Key{tcell.KeyF6, tcell.ModNone},
|
||||
"F7": Key{tcell.KeyF7, tcell.ModNone},
|
||||
"F8": Key{tcell.KeyF8, tcell.ModNone},
|
||||
"F9": Key{tcell.KeyF9, tcell.ModNone},
|
||||
"F10": Key{tcell.KeyF10, tcell.ModNone},
|
||||
"F11": Key{tcell.KeyF11, tcell.ModNone},
|
||||
"F12": Key{tcell.KeyF12, tcell.ModNone},
|
||||
"F13": Key{tcell.KeyF13, tcell.ModNone},
|
||||
"F14": Key{tcell.KeyF14, tcell.ModNone},
|
||||
"F15": Key{tcell.KeyF15, tcell.ModNone},
|
||||
"F16": Key{tcell.KeyF16, tcell.ModNone},
|
||||
"F17": Key{tcell.KeyF17, tcell.ModNone},
|
||||
"F18": Key{tcell.KeyF18, tcell.ModNone},
|
||||
"F19": Key{tcell.KeyF19, tcell.ModNone},
|
||||
"F20": Key{tcell.KeyF20, tcell.ModNone},
|
||||
"F21": Key{tcell.KeyF21, tcell.ModNone},
|
||||
"F22": Key{tcell.KeyF22, tcell.ModNone},
|
||||
"F23": Key{tcell.KeyF23, tcell.ModNone},
|
||||
"F24": Key{tcell.KeyF24, tcell.ModNone},
|
||||
"F25": Key{tcell.KeyF25, tcell.ModNone},
|
||||
"F26": Key{tcell.KeyF26, tcell.ModNone},
|
||||
"F27": Key{tcell.KeyF27, tcell.ModNone},
|
||||
"F28": Key{tcell.KeyF28, tcell.ModNone},
|
||||
"F29": Key{tcell.KeyF29, tcell.ModNone},
|
||||
"F30": Key{tcell.KeyF30, tcell.ModNone},
|
||||
"F31": Key{tcell.KeyF31, tcell.ModNone},
|
||||
"F32": Key{tcell.KeyF32, tcell.ModNone},
|
||||
"F33": Key{tcell.KeyF33, tcell.ModNone},
|
||||
"F34": Key{tcell.KeyF34, tcell.ModNone},
|
||||
"F35": Key{tcell.KeyF35, tcell.ModNone},
|
||||
"F36": Key{tcell.KeyF36, tcell.ModNone},
|
||||
"F37": Key{tcell.KeyF37, tcell.ModNone},
|
||||
"F38": Key{tcell.KeyF38, tcell.ModNone},
|
||||
"F39": Key{tcell.KeyF39, tcell.ModNone},
|
||||
"F40": Key{tcell.KeyF40, tcell.ModNone},
|
||||
"F41": Key{tcell.KeyF41, tcell.ModNone},
|
||||
"F42": Key{tcell.KeyF42, tcell.ModNone},
|
||||
"F43": Key{tcell.KeyF43, tcell.ModNone},
|
||||
"F44": Key{tcell.KeyF44, tcell.ModNone},
|
||||
"F45": Key{tcell.KeyF45, tcell.ModNone},
|
||||
"F46": Key{tcell.KeyF46, tcell.ModNone},
|
||||
"F47": Key{tcell.KeyF47, tcell.ModNone},
|
||||
"F48": Key{tcell.KeyF48, tcell.ModNone},
|
||||
"F49": Key{tcell.KeyF49, tcell.ModNone},
|
||||
"F50": Key{tcell.KeyF50, tcell.ModNone},
|
||||
"F51": Key{tcell.KeyF51, tcell.ModNone},
|
||||
"F52": Key{tcell.KeyF52, tcell.ModNone},
|
||||
"F53": Key{tcell.KeyF53, tcell.ModNone},
|
||||
"F54": Key{tcell.KeyF54, tcell.ModNone},
|
||||
"F55": Key{tcell.KeyF55, tcell.ModNone},
|
||||
"F56": Key{tcell.KeyF56, tcell.ModNone},
|
||||
"F57": Key{tcell.KeyF57, tcell.ModNone},
|
||||
"F58": Key{tcell.KeyF58, tcell.ModNone},
|
||||
"F59": Key{tcell.KeyF59, tcell.ModNone},
|
||||
"F60": Key{tcell.KeyF60, tcell.ModNone},
|
||||
"F61": Key{tcell.KeyF61, tcell.ModNone},
|
||||
"F62": Key{tcell.KeyF62, tcell.ModNone},
|
||||
"F63": Key{tcell.KeyF63, tcell.ModNone},
|
||||
"F64": Key{tcell.KeyF64, tcell.ModNone},
|
||||
"CtrlSpace": Key{tcell.KeyCtrlSpace, tcell.ModNone},
|
||||
"CtrlA": Key{tcell.KeyCtrlA, tcell.ModNone},
|
||||
"CtrlB": Key{tcell.KeyCtrlB, tcell.ModNone},
|
||||
"CtrlC": Key{tcell.KeyCtrlC, tcell.ModNone},
|
||||
"CtrlD": Key{tcell.KeyCtrlD, tcell.ModNone},
|
||||
"CtrlE": Key{tcell.KeyCtrlE, tcell.ModNone},
|
||||
"CtrlF": Key{tcell.KeyCtrlF, tcell.ModNone},
|
||||
"CtrlG": Key{tcell.KeyCtrlG, tcell.ModNone},
|
||||
"CtrlH": Key{tcell.KeyCtrlH, tcell.ModNone},
|
||||
"CtrlI": Key{tcell.KeyCtrlI, tcell.ModNone},
|
||||
"CtrlJ": Key{tcell.KeyCtrlJ, tcell.ModNone},
|
||||
"CtrlK": Key{tcell.KeyCtrlK, tcell.ModNone},
|
||||
"CtrlL": Key{tcell.KeyCtrlL, tcell.ModNone},
|
||||
"CtrlM": Key{tcell.KeyCtrlM, tcell.ModNone},
|
||||
"CtrlN": Key{tcell.KeyCtrlN, tcell.ModNone},
|
||||
"CtrlO": Key{tcell.KeyCtrlO, tcell.ModNone},
|
||||
"CtrlP": Key{tcell.KeyCtrlP, tcell.ModNone},
|
||||
"CtrlQ": Key{tcell.KeyCtrlQ, tcell.ModNone},
|
||||
"CtrlR": Key{tcell.KeyCtrlR, tcell.ModNone},
|
||||
"CtrlS": Key{tcell.KeyCtrlS, tcell.ModNone},
|
||||
"CtrlT": Key{tcell.KeyCtrlT, tcell.ModNone},
|
||||
"CtrlU": Key{tcell.KeyCtrlU, tcell.ModNone},
|
||||
"CtrlV": Key{tcell.KeyCtrlV, tcell.ModNone},
|
||||
"CtrlW": Key{tcell.KeyCtrlW, tcell.ModNone},
|
||||
"CtrlX": Key{tcell.KeyCtrlX, tcell.ModNone},
|
||||
"CtrlY": Key{tcell.KeyCtrlY, tcell.ModNone},
|
||||
"CtrlZ": Key{tcell.KeyCtrlZ, tcell.ModNone},
|
||||
"CtrlLeftSq": Key{tcell.KeyCtrlLeftSq, tcell.ModNone},
|
||||
"CtrlBackslash": Key{tcell.KeyCtrlBackslash, tcell.ModNone},
|
||||
"CtrlRightSq": Key{tcell.KeyCtrlRightSq, tcell.ModNone},
|
||||
"CtrlCarat": Key{tcell.KeyCtrlCarat, tcell.ModNone},
|
||||
"CtrlUnderscore": Key{tcell.KeyCtrlUnderscore, tcell.ModNone},
|
||||
"Backspace": Key{tcell.KeyBackspace, tcell.ModNone},
|
||||
"Tab": Key{tcell.KeyTab, tcell.ModNone},
|
||||
"Esc": Key{tcell.KeyEsc, tcell.ModNone},
|
||||
"Escape": Key{tcell.KeyEscape, tcell.ModNone},
|
||||
"Enter": Key{tcell.KeyEnter, tcell.ModNone},
|
||||
"Backspace2": Key{tcell.KeyBackspace2, tcell.ModNone},
|
||||
}
|
||||
|
||||
var parsed map[string]string
|
||||
|
|
|
@ -172,9 +172,6 @@ func (m *Messenger) HandleEvent(event tcell.Event) {
|
|||
m.response = string([]rune(m.response)[:m.cursorx-1]) + string(m.response[m.cursorx:])
|
||||
}
|
||||
m.cursorx--
|
||||
case tcell.KeySpace:
|
||||
m.response += " "
|
||||
m.cursorx++
|
||||
case tcell.KeyRune:
|
||||
m.response = Insert(m.response, m.cursorx, string(e.Rune()))
|
||||
m.cursorx++
|
||||
|
|
|
@ -273,13 +273,15 @@ func (v *View) HandleEvent(event tcell.Event) {
|
|||
v.Cursor.Right()
|
||||
} else {
|
||||
for key, action := range bindings {
|
||||
if e.Key() == key {
|
||||
relocate = action(v)
|
||||
for _, pl := range loadedPlugins {
|
||||
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
|
||||
err := Call(pl + "_on" + funcName[len(funcName)-1])
|
||||
if err != nil {
|
||||
TermMessage(err)
|
||||
if e.Key() == key.keyCode {
|
||||
if e.Modifiers() == key.modifiers {
|
||||
relocate = action(v)
|
||||
for _, pl := range loadedPlugins {
|
||||
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
|
||||
err := Call(pl + "_on" + funcName[len(funcName)-1])
|
||||
if err != nil {
|
||||
TermMessage(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +308,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
|||
switch button {
|
||||
case tcell.Button1:
|
||||
// Left click
|
||||
if v.mouseReleased && !e.HasMotion() {
|
||||
if v.mouseReleased {
|
||||
v.MoveToMouseClick(x, y)
|
||||
if time.Since(v.lastClickTime)/time.Millisecond < doubleClickThreshold {
|
||||
if v.doubleClick {
|
||||
|
|
Loading…
Reference in a new issue