git.haldean.org e / master e.nim
master

Tree @master (Download .tar.gz)

e.nim @masterraw · history · blame

import blit, buf, comp, find
import illwill
import input
import os, system

var c = newComp(Size(w: 30, h: 20))

var fb = newFindBuf()
var lx = newLayer(fb.blit)
lx.tag = LayoutTag.center

#var bx = newBuf()
#bx.load("test/pg844.txt")
#var ly = newLayer(bx.blit)
#ly.tag = LayoutTag.left
#var lz = newLayer(bx.blit)
#lz.tag = LayoutTag.right

proc exitProc() {.noconv.} =
  illwillDeinit()
  showCursor()
  let
    e = getCurrentException()
    msg = getCurrentExceptionMsg()
  if e != nil:
    echo "exception", repr(e), "raised:", msg
    writeFile("err.txt", msg)
  quit(0)

proc main() =
  illwillInit(fullscreen=true)
  setControlCHook(exitProc)
  hideCursor()

  #var bufs = @[(fb, lx), (bx, ly), (bx, lz)]
  var bufs = @[(fb, lx)]
  var focused = 0
  for bl in bufs:
    c.pushlayer(bl[1])
  c.focus(bufs[focused][1])

  try:
    while true:
      var size = Size(w: terminalWidth(), h: terminalHeight())
      if size != c.size:
        c.size = size

      var k = input.Key(illwill.getKey())

      if not bufs[focused][0].handlekey(k):
        case k.toIllwill
        of illwill.Key.Escape, illwill.Key.Q:
          exitProc()
        of illwill.Key.Tab:
          focused = (focused + 1) mod bufs.len
          c.focus(bufs[focused][1])
        of illwill.Key.J:
          c.focused().src.y += 1
        of illwill.Key.K:
          c.focused().src.y -= 1
        of illwill.Key.H:
          c.focused().src.x += 1
        of illwill.Key.L:
          c.focused().src.x -= 1
        of illwill.Key.None:
          discard
        else:
          discard

      c.paint()
      sleep(16)
  except:
    exitProc()

main()