summaryrefslogtreecommitdiff
path: root/python/test.py
blob: a7f618d9f336174af466fd75f80cb65f4de2e241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from aewan import AeDoc, AeLayer
import curses
import sys

def setattr(wnd, at):
   at = int(at)
   fg = at >> 4
   bg = at & 0x0f
   bold = 0
   blink = 0
   
   if fg > 7:
      bold = 1
      fg = fg - 8

   if bg > 7:
      blink = 1
      bg = bg - 8

   if fg == 7 and bg == 0: wnd.attrset(curses.A_NORMAL)
   elif fg == 0 and bg == 0: wnd.attrset(curses.color_pair(7))
   else: wnd.attrset(curses.color_pair(bg * 8 + fg))

   if bold: wnd.attron(curses.A_BOLD)
   if blink: wnd.attron(curses.A_BLINK)

stdscr = curses.initscr()
curses.noecho()
curses.start_color()

for bg in range(8):
   for fg in range(8):
      if bg > 0 or fg > 0: curses.init_pair(bg*8 + fg, fg, bg)

curses.init_pair(7, 0, 0)


stdscr.clear()

d = AeDoc("/tmp/ut.aes.gz")

sx = sy = 0
while 1:
   d.layers[0].render(stdscr, 20, 8, 40, 10, sx, sy, setattr)
   stdscr.refresh()
   ch = chr(stdscr.getch())
   if ch == 'h': sx = sx - 1
   elif ch == 'l': sx = sx + 1
   elif ch == 'k': sy = sy - 1
   elif ch == 'j': sy = sy + 1
   elif ch == 'q':
      curses.endwin()
      sys.exit(0)