Skip to content

Commit

Permalink
This version may actually work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomoriah committed Mar 18, 2020
1 parent d722fe6 commit b78dbd3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
14 changes: 9 additions & 5 deletions WConio2.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,19 @@ def delline():
ciFill = CHAR_INFO()
hConOut = _getconout()
csbi = _getscreeninfo()
dwDest = ctypes.wintypes._COORD()
srSource.Top = csbi.dwCursorPosition.Y
srSource.Left = csbi.srWindow.Left
srSource.Bottom = csbi.srWindow.Bottom
srSource.Right = csbi.srWindow.Right
dwDest.X = csbi.srWindow.Left
dwDest.Y = csbi.dwCursorPosition.Y
ciFill.Char.UnicodeChar = ctypes.c_char(b' ')
ciFill.Char.UnicodeChar = ctypes.c_wchar(b' ')
ciFill.Attributes = csbi.wAttributes
kernel32.ScrollConsoleScreenBuffer(hConOut,
kernel32.ScrollConsoleScreenBufferW(hConOut,
ctypes.byref(srSource),
LPDWORD(ctypes.c_ulong(0)),
dwDest,
dwDest,
ctypes.byref(ciFill)
)

Expand All @@ -364,15 +365,16 @@ def insline():
ciFill = CHAR_INFO()
hConOut = _getconout()
csbi = _getscreeninfo()
dwDest = ctypes.wintypes._COORD()
srSource.Top = csbi.dwCursorPosition.Y
srSource.Left = csbi.srWindow.Left
srSource.Bottom = csbi.srWindow.Bottom
srSource.Right = csbi.srWindow.Right
dwDest.X = csbi.srWindow.Left
dwDest.Y = csbi.dwCursorPosition.Y
ciFill.Char.UnicodeChar = ctypes.c_char(b' ')
ciFill.Char.UnicodeChar = ctypes.c_wchar(b' ')
ciFill.Attributes = csbi.wAttributes
kernel32.ScrollConsoleScreenBuffer(hConOut,
kernel32.ScrollConsoleScreenBufferW(hConOut,
ctypes.byref(srSource),
LPDWORD(ctypes.c_ulong(0)),
dwDest,
Expand Down Expand Up @@ -405,6 +407,8 @@ def gettext(left, top, right, bottom):
# to replicate the Turbo C data structure. however, we
# almost never care about the internal structure, so here
# we will just return the buffer we got from kernel32.
# NOTE that test.py versions from the 1.5 release for
# Python 3 will fail because of this change!
_releaseconout(hConOut)
return buf
_releaseconout(hConOut)
Expand Down
40 changes: 23 additions & 17 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
tiNORMATTR = 5

if sys.version_info>=(3,0):
# in 3.0, bytes[n] -> int
# in 3.0, bytes[n] -> int
# no need to convert
def byte2int(x):
def byte2int(x):
return x
else:
else:
# in 2.x, bytes[n] = str[n] -> str
# convert to int using ord
def byte2int(x):
def byte2int(x):
return ord(x)

class WConioTest(unittest.TestCase):
Expand All @@ -35,8 +35,9 @@ def test_goto(self):
clreol()
self.assertEqual(wherex(), 35)
self.assertEqual(wherey(), 10)
self.assertEqual(gettext(29,10,38,11)[::2], b'soon: a while. ')

# the following line depends on the old binary format for gettext()
# self.assertEqual(gettext(29,10,38,11)[::2], b'soon: a while. ')

def test_cursor(self):
clrscr()
cputs("Look at the cursor.")
Expand All @@ -51,37 +52,41 @@ def test_cursor(self):
self.assertEqual(getch()[1].lower(), 'y')

def test_delline(self):
# the original version of this test used gettext() and expected
# the data to be in the original turbo c format; it's not, so the
# test failed. this test isn't really doing much anymore.
clrscr()
cputs("0\n1\n2")
self.assertEqual(gettext(0,0,0,2)[::2], b'012')
gotoxy(10, 1)
delline()
self.assertEqual(wherex(), 10)
self.assertEqual(wherey(), 1)
self.assertEqual(gettext(0,0,0,2)[::2], b'02 ')
gotoxy(10, 0)
delline()
self.assertEqual(gettext(0,0,0,2)[::2], b'2 ')

def test_insline(self):
clrscr()
cputs("0\n1\n2")
self.assertEqual(gettext(0,0,0,2)[::2], b'012')
# the following line depends on the old binary format for gettext()
# self.assertEqual(gettext(0,0,0,2)[::2], b'012')
gotoxy(10, 1)
insline()
self.assertEqual(wherex(), 10)
self.assertEqual(wherey(), 1)
self.assertEqual(gettext(0,0,0,3)[::2], b'0 12')
# the following line depends on the old binary format for gettext()
# self.assertEqual(gettext(0,0,0,3)[::2], b'0 12')
gotoxy(10, 0)
insline()
self.assertEqual(gettext(0,0,0,4)[::2], b' 0 12')
# the following line depends on the old binary format for gettext()
# self.assertEqual(gettext(0,0,0,4)[::2], b' 0 12')

def test_putch(self):
clrscr()
putch(ord('1'))
putch('2')
putch(b'3')
self.assertEqual(gettext(0, 0, 2, 0)[::2], b'123')
# the following line depends on the old binary format for gettext()
# self.assertEqual(gettext(0, 0, 2, 0)[::2], b'123')

def test_movetext(self):
pass
Expand All @@ -108,7 +113,8 @@ def test_puttext(self):
clrscr()
puttext(7, 1, 26, 3, saved)
t1 = gettext(7, 1, 10, 2)[::2]
self.assertEqual(t1, b"7.9..8.0")
# the following line depends on the old binary format for gettext()
# self.assertEqual(t1, b"7.9..8.0")

def test_input(self):
clrscr()
Expand Down Expand Up @@ -139,7 +145,7 @@ def test_attrs(self):
# rather than slavishly replicating the Turbo C format. Thus, this
# section is commented as not useful right now.

# attr = (CYAN<<4) | YELLOW
# attr = (CYAN<<4) | YELLOW
# textattr(attr)
# clrscr()
# cputs("Hello world!\n")
Expand All @@ -155,7 +161,7 @@ def test_attrs(self):
# self.assertEqual(list(map(byte2int,ta)), [BLUE<<4|RED] * 4)
# ta = gettext(4,1,8,1)[1::2]
# self.assertEqual(list(map(byte2int,ta)), [BLUE<<4|WHITE] * 5)


if __name__ == '__main__':
unittest.main()

0 comments on commit b78dbd3

Please sign in to comment.