jale/templates.nim

25 lines
682 B
Nim
Raw Normal View History

2021-02-15 20:18:31 +01:00
import editor
import event
import keycodes
2021-02-15 20:59:40 +01:00
import tables
2021-02-15 20:18:31 +01:00
template bindKey*(editor: LineEditor, key: int, body: untyped) =
proc action {.gensym.} =
body
editor.keystrokes.add(key, action)
template bindKey*(editor: LineEditor, key: char, body: untyped) =
editor.bindKey(int(key)):
body
template bindKey*(editor: LineEditor, key: string, body: untyped) =
if not keysByName.hasKey(key):
raise newException(Defect, "Invalid key " & key & ", it's not in the keycode table")
2021-02-15 20:18:31 +01:00
editor.bindKey(keysByName[key]):
body
template bindEvent*(editor: LineEditor, event: JaleEvent, body: untyped) =
proc action {.gensym.} =
body
editor.events.add(event, action)