forked from LeoJr2015/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextstarsim.py
More file actions
113 lines (105 loc) · 3.85 KB
/
textstarsim.py
File metadata and controls
113 lines (105 loc) · 3.85 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
class TextStarSim:
def __init__(self):
self.screen = []
self.line = 0
self.col = 0
self.window = 0
for i in range(0,16):
self.screen.append([])
for j in range(0,16):
self.screen[i].append(" ")
def print_screen(self):
print (self.line,self.col), "Screen:",self.window/2
#print "#0123456789ABCDEF#"
print "##################"
print "#%s#" % "".join(self.screen[self.window]).ljust(16)
print "#%s#" % "".join(self.screen[self.window+1]).ljust(16)
print "##################"
def write(self,data):
#for i in range(len(data)):
i = 0
while i < len(data):
#print self.line, self.col, data[i]
if self.col >15:
#print "New Line"
self.col = 0
self.line += 1
elif self.line >= 15:
self.col = 0
self.line = 0
if ord(data[i]) == 254:
if ord(data[i+1]) == 80: #Position Cursor
self.setcursor(ord(data[i+2]),ord(data[i+3]))
i += 4
elif ord(data[i+1]) == 83: #Clear Screen
for x in range(0,16):
for y in range(0,16):
self.screen[i][j] = " "
i += 1
elif ord(data[i+1]) == 98: #BarGraph
width = ord(data[i+2])
percent = (ord(data[i+3]))
self.blocks = "*" * int(float(width)*(float(percent)/100))
self.write(self.blocks)
i += 4
elif ord(data[i+1]) == 71: #GoToLine
self.line = ord(data[i+2])
self.col = 0
i += 3
elif ord(data[i+1]) == 79: #ScrollWindow
direction = ord(data[i+2])
if direction == 1:
self.window += 2
else:
self.window -= 2
if self.window < 0:
self.window = 14
elif self.window > 14:
self.window = 14
i += 3
elif data[i] == '\n': #new line
self.line += 1
self.col = 0
i += 1
else:
#if self.col >= 16:
# print "New Line2"
# self.col = 0
# self.line += 1
self.screen[self.line][self.col] = data[i]
self.col += 1
i += 1
def setcursor(self,l,c):
self.line = l
self.col = c
#self.screen[0] = data
if __name__ == "__main__":
import struct
tss = TextStarSim()
tss.print_screen()
tss.write("Screen 0\n")
tss.write("Screen 0\n")
tss.write("Screen 1\n")
tss.write("Screen 1\n")
tss.write("Screen 2\n")
tss.write("Screen 2\n")
tss.write("Screen 3\n")
tss.print_screen()
tss.setcursor(1,1)
tss.write(struct.pack('BBBB',254,98,16,25))
tss.write(struct.pack('BBB',254,79,1))#7
tss.print_screen()
tss.write(struct.pack('BBB',254,79,1))#6
tss.print_screen()
tss.write(struct.pack('BBB',254,79,1))#5
tss.print_screen()
tss.write(struct.pack('BBB',254,79,1))#4
tss.write(struct.pack('BBB',254,79,0))#3
tss.write(struct.pack('BBB',254,79,0))#2
tss.write(struct.pack('BBB',254,79,0))#1
tss.write(struct.pack('BBB',254,79,0))#0
#tss.write(struct.pack('BBBB',254,80,0,0))
tss.print_screen()
#tss.write(struct.pack('BB',254,83))
#tss.print_screen()