nboard/nlong

91 lines
2.2 KiB
Text
Raw Normal View History

2020-03-21 19:35:22 +00:00
#!/usr/bin/env python3
2020-03-21 21:35:38 +00:00
import curses,time,json
dataPath = '/home/lickthecheese/nlong/nlong.json'
2020-03-21 20:22:27 +00:00
def main(stdscr):
stdscr.clear()
stdscr.refresh()
k=''
2020-03-21 21:35:38 +00:00
height, width = stdscr.getmaxyx()
vx = vy = tx = ty = 0
cx = width // 2
cy = height // 2
stdscr.move(cy,cx)
while True:
stdscr.clear()
2020-03-21 20:22:27 +00:00
height, width = stdscr.getmaxyx()
2020-03-21 21:35:38 +00:00
# detect where to move cursor
2020-03-21 20:22:27 +00:00
if k == 'KEY_UP':
cy += -1
2020-03-21 21:35:38 +00:00
if k == 'KEY_DOWN':
cy += 1
if k == 'KEY_LEFT':
cx += -1
if k == 'KEY_RIGHT':
cx += 1
# enter view move mode
if k == '&':
stdscr.addstr(height-1, 0, 'Welcome to switch view mode. press an arrow key to move the view or a if you wanted a &'[:width-1])
k = stdscr.getkey()
if k == 'a':
2020-03-21 21:51:42 +00:00
pass # il do this soon lol
2020-03-21 21:35:38 +00:00
if k == 'KEY_UP':
vy += -1
2020-03-21 21:51:42 +00:00
cy = height
2020-03-21 21:35:38 +00:00
if k == 'KEY_DOWN':
vy += 1
2020-03-21 21:51:42 +00:00
cy = 0
2020-03-21 21:35:38 +00:00
if k == 'KEY_LEFT':
vx += -1
2020-03-21 21:51:42 +00:00
cx = width
2020-03-21 21:35:38 +00:00
if k == 'KEY_RIGHT':
vx += 1
2020-03-21 21:51:42 +00:00
cx = 0
2020-03-21 21:35:38 +00:00
# make sure the cursor is on the screen
# this is not nessesary for the view as it is infinite
cx = max(0, cx)
cx = min(width-1, cx)
cy = max(0, cy)
2020-03-21 21:51:42 +00:00
cy = min(height-2, cy)
2020-03-21 21:35:38 +00:00
# calculate true position
tx = cx + (vx * width) - width // 2
2020-03-21 21:51:42 +00:00
ty = cy + (vy * height) - (height-1) // 2
# get json data
# draw the screen
stdscr.move(0, 0)
for y in range(height-1):
for x in range(width):
stdscr.addstr(data.get((ty - cy + y,tx - cx + x), ' '))
2020-03-21 21:35:38 +00:00
# display some info
stdscr.addstr(height-1, 0, 'x: {}, y: {}, arrow keys to move, & key to move to the next pane'.format(tx, ty)[:width-1])
# move the cursor where its actually supposed to be
stdscr.move(cy,cx)
#print(k) # debug keycodes
2020-03-21 21:51:42 +00:00
k = stdscr.getkey()
2020-03-21 21:35:38 +00:00
2020-03-21 20:22:27 +00:00
if __name__ == "__main__":
curses.wrapper(main)
print('bye!')