Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4432
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CHANGELOG b/CHANGELOG
index f2f8cba..8742201 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,57 +1,59 @@
Copyright (C) 2022 LANNOCC (Shawn A. Wilson [lannocc@yahoo.com])
@%@~LICENSE:MIT~@%@
+saw_080222_3 - Fix curses screen refresh. Add some debugging.
+
saw_080222_2 - New matrix method mostly working now.
saw_080222_1 - Working on new matrix-based universal screen mapping.
saw_080122_3 - Start to play with multiple windows.
saw_080122_2 - Let run() be wrapped. User setup should happen in init().
saw_080122_1 - Fix for python 3.8.
saw_073122_3 - Fix ctrl-c interrupt on Windows.
saw_073122_2 - Tested and working on Linux and Win7.
saw_073122_1 - Text scrolling and justification, window resizing.
saw_073022_10 - Linux: Improved mouse responsiveness.
saw_073022_9 - Windows: Fix unreliable mouse position while scrolling.
saw_073022_8 - Version bump: tested on Linux and Win7.
saw_073022_7 - Window movement (Windows).
saw_073022_6 - Window movement (Linux).
saw_073022_5 - Version bump: tested on Linux and Win7.
saw_073022_4 - Print containment on Windows.
saw_073022_3 - Normalized mouse input across platforms.
saw_073022_2 - Mouse input on Windows.
saw_073022_1 - Input wrangling and exception propagation.
saw_072922_3 - Version bump: tested on Linux and Win7.
saw_072922_2 - Beginning Windows backend.
saw_072922_1 - A possible approach to multiple backends.
saw_072822_6 - Some window fun.
saw_072822_5 - Bump version for pip platform dependency test.
saw_072822_4 - Test commit (turned on GPG sign in Windows).
saw_072822_3 - Add Windows support to mouse test script.
saw_072822_2 - Add a mouse test script.
saw_072822_1 - Initial commit (just termio.py from my vipy project).
diff --git a/appscii/__version__.py b/appscii/__version__.py
index de4b94f..748f812 100644
--- a/appscii/__version__.py
+++ b/appscii/__version__.py
@@ -1,2 +1,2 @@
-__version__ = '0.1.0'
+__version__ = '0.1.1'
diff --git a/appscii/backend/curses.py b/appscii/backend/curses.py
index b843ae0..e3f404b 100644
--- a/appscii/backend/curses.py
+++ b/appscii/backend/curses.py
@@ -1,120 +1,132 @@
from .common import Window
from .matrix import CharMap
import curses
class Application:
def __init__(self, shell):
self.shell = shell
self.screen = curses.initscr()
curses.flushinp()
curses.curs_set(0)
curses.noecho()
curses.cbreak()
self.screen.keypad(True)
try: curses.set_escdelay(222)
except AttributeError: pass
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
curses.mouseinterval(0)
self.matrix = CharMap(self.w, self.h)
self.mbtns = [False, False, False] # mouse buttons (left, mid, right)
def exit(self):
self.screen.keypad(False)
curses.nocbreak()
curses.echo()
curses.curs_set(1)
curses.flushinp()
curses.endwin()
@property
def w(self):
return curses.COLS
@property
def h(self):
return curses.LINES
def inputs(self):
while self.shell.go:
key = self.screen.getch()
if key == curses.KEY_MOUSE:
_, x, y, _, btn = curses.getmouse()
mbtns = self.mbtns
if btn & curses.BUTTON1_PRESSED:
mbtns[0] = True
elif btn & curses.BUTTON1_RELEASED:
mbtns[0] = False
if btn & curses.BUTTON2_PRESSED:
mbtns[1] = True
elif btn & curses.BUTTON2_RELEASED:
mbtns[1] = False
if btn & curses.BUTTON3_PRESSED:
mbtns[2] = True
elif btn & curses.BUTTON3_RELEASED:
mbtns[2] = False
if btn & curses.BUTTON1_CLICKED \
or btn & curses.BUTTON1_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, True, mbtns[1], mbtns[2], 0)
self.shell.on_mouse(x, y, False, mbtns[1], mbtns[2], 0)
if btn & curses.BUTTON1_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, True, mbtns[1], mbtns[2], 0)
self.shell.on_mouse(x, y, False, mbtns[1], mbtns[2], 0)
elif btn & curses.BUTTON2_CLICKED \
or btn & curses.BUTTON2_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, mbtns[0], True, mbtns[2], 0)
self.shell.on_mouse(x, y, mbtns[0], False, mbtns[2], 0)
if btn & curses.BUTTON2_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, mbtns[0], True, mbtns[2], 0)
self.shell.on_mouse(x, y, mbtns[0], False, mbtns[2], 0)
elif btn & curses.BUTTON3_CLICKED \
or btn & curses.BUTTON3_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], True, 0)
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], False, 0)
if btn & curses.BUTTON3_DOUBLE_CLICKED:
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], True, 0)
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], False, 0)
elif btn & curses.BUTTON4_PRESSED:
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], mbtns[2], 1)
elif btn & 2097152:
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], mbtns[2], -1)
else:
self.shell.on_mouse(x, y, mbtns[0], mbtns[1], mbtns[2], 0)
else:
#raise RuntimeError('just a test')
self.shell.on_key(key)
def refresh(self):
- try:
- for y in range(self.matrix.h):
- chars = self.matrix.chars[y]
- changes = self.matrix.changes[y]
-
- for x in range(self.matrix.w):
- if changes[x]:
- c = chars[x]
+ #self.debug()
+
+ for y in range(self.matrix.h):
+ chars = self.matrix.chars[y]
+ changes = self.matrix.changes[y]
+
+ for x in range(self.matrix.w):
+ if changes[x]:
+ c = chars[x]
+ try:
self.screen.addstr(y, x, '.' if c is None else c)
- changes[x] = False
- except curses.error as e:
- # we can ignore error on bottom-right character
- if not (x == self.w - 1 and y == self.h - 1):
- raise ValueError(f'at {x},{y} (x,y)') from e
+ except curses.error as e:
+ # we can ignore error on bottom-right character
+ if not (x == self.w - 1 and y == self.h - 1):
+ raise ValueError(f'at {x},{y} (x,y)') from e
+
+ changes[x] = False
+
+ self.screen.refresh()
+
+ def debug(self):
+ with open('debug.txt', 'a') as out:
+ out.write('\n\n')
+ out.write(self.matrix.debug_changes())
+ out.write('\n---\n')
+ out.write(self.matrix.debug_chars())
diff --git a/appscii/backend/matrix.py b/appscii/backend/matrix.py
index fefe797..7a755bb 100644
--- a/appscii/backend/matrix.py
+++ b/appscii/backend/matrix.py
@@ -1,84 +1,96 @@
class CharMap:
def __init__(self, w, h, fill=' '):
assert w >= 0
assert h >= 0
assert fill is None or (isinstance(fill, str) and len(fill) == 1)
self.w = w
self.h = h
self.chars = [ [ fill for x in range(w) ] for y in range(h) ]
self.changes = [ [ True for x in range(w) ] for y in range(h) ]
def set_size(self, w, h, fill=' '):
if w == self.w and h == self.h: return
assert w >= 0 and h >= 0
if h > self.h:
self.chars.extend(
[ [ fill for x in range(w) ] for y in range(self.h, h) ])
self.changes.extend(
[ [ True for x in range(w) ] for y in range(self.h, h) ])
elif h < self.h:
self.chars = self.chars[:h]
self.changes = self.changes[:h]
if w > self.w:
for row in self.chars[:min(self.h, h)]:
row.extend([ fill for x in range(self.w, w) ])
for row in self.changes[:min(self.h, h)]:
row.extend([ True for x in range(self.w, w) ])
elif w < self.w:
for row in self.chars[:min(self.h, h)]:
del row[w:]
for row in self.changes[:min(self.h, h)]:
del row[w:]
self.w = w
self.h = h
def set(self, c, x, y):
assert c is None or (isinstance(c, str) and len(c) == 1)
assert x >= 0 and x < self.w
assert y >= 0 and y < self.h
if self.chars[y][x] == c: return
self.chars[y][x] = c
self.changes[y][x] = True
def fill(self, c, x, y, w, h):
assert c is None or (isinstance(c, str) and len(c) == 1)
assert x >= 0 and x + w <= self.w
assert y >= 0 and y + h <= self.h
for cy in range(y, y + h):
chars = self.chars[cy]
changes = self.changes[cy]
for cx in range(x, x + w):
if chars[cx] != c:
chars[cx] = c
changes[cx] = True
def merge(self, matrix, x=0, y=0):
assert x >= 0 and x + matrix.w <= self.w
assert y >= 0 and y + matrix.h <= self.h
# FIXME: consider only changed items of matrix then clear changes?
for cy in range(y, y + matrix.h):
chars = self.chars[cy]
changes = self.changes[cy]
mchars = matrix.chars[cy - y]
for cx in range(x, x + matrix.w):
mchar = mchars[cx - x]
if mchar is not None and chars[cx] != mchar:
chars[cx] = mchar
changes[cx] = True
+ def debug_chars(self):
+ return '\n'.join([
+ ''.join([ c for c in line ])
+ for line in self.chars
+ ])
+
+ def debug_changes(self):
+ return '\n'.join([
+ ''.join([ '#' if c else '.' for c in line ])
+ for line in self.changes
+ ])
+
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Sep 14, 10:35 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3653
Default Alt Text
(10 KB)
Attached To
Mode
rAPPSCII Terminal Framework
Attached
Detach File
Event Timeline
Log In to Comment