summaryrefslogtreecommitdiffstats
path: root/cholerab/cholerab-live
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-07-24 02:41:13 +0200
committermakefu <github@syntax-fehler.de>2011-07-24 02:41:13 +0200
commit531d9d4309fa09e893a19fdcf8165dc7bf1b3731 (patch)
treeb4172c2eec1ae842c3b0726fd2e91a5974557323 /cholerab/cholerab-live
parent10788dffb408325cb6e73fa4154ce9e5d3ac10ad (diff)
added curses stuff
cholerab-live/view.py: now able to write basic utf-8 on the plane, handles some rudimentary colors handles backspace correctly
Diffstat (limited to 'cholerab/cholerab-live')
-rwxr-xr-x[-rw-r--r--]cholerab/cholerab-live/cholerab.py31
-rw-r--r--cholerab/cholerab-live/here.log149
-rw-r--r--cholerab/cholerab-live/view.py142
-rw-r--r--cholerab/cholerab-live/view.pycbin0 -> 3949 bytes
4 files changed, 253 insertions, 69 deletions
diff --git a/cholerab/cholerab-live/cholerab.py b/cholerab/cholerab-live/cholerab.py
index 4739d9cf..0ac44e09 100644..100755
--- a/cholerab/cholerab-live/cholerab.py
+++ b/cholerab/cholerab-live/cholerab.py
@@ -1,10 +1,23 @@
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+import curses,time
from view import CursesView
-
-a = CursesView()
-a.start()
-a.write_char(5,5,'p')
-a.write_char(6,5,'e')
-a.write_char(7,5,'n')
-a.write_char(8,5,'i')
-a.write_char(9,5,'s')
-a.join()
+import logging
+logging.basicConfig(filename='here.log',level=logging.DEBUG)
+log = logging.getLogger('main')
+def main(scr):
+ log.debug('started main')
+ a = CursesView(scr=scr)
+ a.start()
+ log.debug
+ a.write_char(5,5,'p')
+ a.write_char(6,5,'e')
+ a.write_char(7,5,'n')
+ a.write_char(8,5,'i')
+ a.write_char(9,5,'s')
+ a.write_str(5,6,'¯\(°_o)/¯',user=2)
+ for i in range(7,11):
+ time.sleep(2)
+ a.write_str(5,i,'¯\(°_o)/¯',user=3)
+ a.join()
+curses.wrapper(main)
diff --git a/cholerab/cholerab-live/here.log b/cholerab/cholerab-live/here.log
new file mode 100644
index 00000000..80e02d4c
--- /dev/null
+++ b/cholerab/cholerab-live/here.log
@@ -0,0 +1,149 @@
+DEBUG:main:started main
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:127
+DEBUG:cholerab-curses:113
+DEBUG:main:started main
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:115
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:115
+DEBUG:cholerab-curses:100
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:115
+DEBUG:cholerab-curses:100
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:115
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:100
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:115
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:97
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:113
+DEBUG:main:started main
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:260
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:258
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:127
+INFO:cholerab-curses:backspace pressed
+DEBUG:cholerab-curses:259
+DEBUG:cholerab-curses:259
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:261
+DEBUG:cholerab-curses:113
diff --git a/cholerab/cholerab-live/view.py b/cholerab/cholerab-live/view.py
index b798e712..fe90b926 100644
--- a/cholerab/cholerab-live/view.py
+++ b/cholerab/cholerab-live/view.py
@@ -3,73 +3,95 @@
from curses import *
import socket
import threading
+import logging
+log = logging.getLogger('cholerab-curses')
class CursesView(threading.Thread):
- def stop(self):
- self.running = False
- nocbreak(); self.scr.keypad(0); echo()
- endwin()
+ def stop(self):
+ self.running = False
+ nocbreak(); self.scr.keypad(0); echo()
+ endwin()
- def run(self):
- self.running = True
- def try_move(x,y):
- if x >= self.width: x = 0;y = y+1
- if x < 0 : x = self.width-1; y= y-1
- if y >= self.height : x = x+1;y = 0
- if y < 0 : x = x-1; y = self.height-1
- self.win.move(y,x); return x,y
+ def run(self):
+ """
+ input loop
- while self.running:
- c = self.scr.getch()
- if c == KEY_LEFT : self.x -=1
- elif c == KEY_RIGHT : self.x +=1
- elif c == KEY_UP : self.y -=1
- elif c == KEY_DOWN : self.y +=1
- elif c == ord('q') : self.stop()
- #TODO handle backspace correctly
- else :
- try:
- self.win.addch(c) #TODO UTF8 here
- #self.cholerab.write_char(self.x,self.y,c)
- except:
- pass
- self.x +=1
- self.x,self.y = try_move(self.x,self.y)
- self.refresh()
+ TODO add Unicode Input Support
+ """
+ self.running = True
+ def try_move(x,y):
+ if x >= self.width: x = 0;y = y+1
+ if x < 0 : x = self.width-1; y= y-1
+ if y >= self.height : x = x+1;y = 0
+ if y < 0 : x = x-1; y = self.height-1
+ self.win.move(y,x); return x,y
- def write_char(self,x,y,char):
- self.win.addch(y,x,char)
- self.win.move(self.y,self.x)
- self.refresh()
- def refresh(self):
- self.scr.refresh()
- self.win.refresh()
- def clear(self):
- pass
- def write_field(self,ar):
- """
- writes the whole field with given 2-dimensional array
- """
- self.clear()
- pass
+ while self.running:
+ c = self.scr.getch() #get_char(self.scr)
+ log.debug(str(c))
+ if c == KEY_LEFT : self.x -=1
+ elif c == KEY_RIGHT : self.x +=1
+ elif c == KEY_UP : self.y -=1
+ elif c == KEY_DOWN : self.y +=1
+ elif c == ord('q') : self.stop()
+ elif c == 127:
+ log.info('backspace pressed')
+ self.x -=1;
+ self.x,self.y = try_move(self.x,self.y)
+ self.win.addch(' ')
+ #TODO handle backspace correctly
+ else :
+ try:
+ self.win.addch(c) #TODO UTF8 here
+ #self.cholerab.write_char(self.x,self.y,c)
+ except:
+ pass
+ self.x +=1
+ self.x,self.y = try_move(self.x,self.y)
+ self.refresh()
- def __init__(self,height=24,width=80,cholerab=None):
- self.cholerab = cholerab
- threading.Thread.__init__(self)
- self.scr = initscr()
- noecho()
- cbreak()
- self.scr.keypad(1)
- try:
- curs_set(2)
- except: # go home with your non-standard terminals!
- pass
+ def write_char(self,x,y,char):
+ self.win.addch(y,x,char)
+ self.win.move(self.y,self.x)
+ self.refresh()
+ def write_str(self,x,y,string,user=1):
+ self.win.addstr(y,x,string,color_pair(user))
+ self.win.move(self.y,self.x)
+ self.refresh()
+ def refresh(self):
+ self.scr.refresh()
+ self.win.refresh()
+ def clear(self):
+ pass
+ def write_field(self,ar):
+ """
+ writes the whole field with given 2-dimensional array
+ """
+ self.clear()
+ pass
- begin_x = 0;begin_y = 0
- self.height = height
- self.width = width
- self.x = 0 ; self.y = 0
- self.win = newwin(height,width,begin_y,begin_x)
+ def __init__(self,height=24,width=80,cholerab=None,scr=None):
+ init_pair(1,COLOR_WHITE,COLOR_BLACK)
+ init_pair(2,COLOR_RED,COLOR_BLACK)
+ init_pair(3,COLOR_GREEN,COLOR_BLACK)
+ self.cholerab = cholerab
+ threading.Thread.__init__(self)
+ if scr:
+ self.scr = scr
+ else:
+ self.scr = initscr()
+ noecho()
+ cbreak()
+ self.scr.keypad(1)
+ try: curs_set(2)
+ except: pass # go home with your non-standard terminals!
+
+ begin_x = 0;begin_y = 0
+ self.height = height
+ self.width = width
+ self.x = 0 ; self.y = 0
+
+ self.win = newwin(height,width,begin_y,begin_x)
diff --git a/cholerab/cholerab-live/view.pyc b/cholerab/cholerab-live/view.pyc
new file mode 100644
index 00000000..5516ae2f
--- /dev/null
+++ b/cholerab/cholerab-live/view.pyc
Binary files differ