remove trailing spaces
This commit is contained in:
parent
371adb7417
commit
224739ecfb
@ -30,14 +30,13 @@ class Terminal:
|
|||||||
self.stream.feed(data)
|
self.stream.feed(data)
|
||||||
|
|
||||||
def updateAttributes(self, initialize = False):
|
def updateAttributes(self, initialize = False):
|
||||||
buffer = self.screen.buffer
|
buffer = self.screen.buffer
|
||||||
lines = None
|
lines = None
|
||||||
if not initialize:
|
if not initialize:
|
||||||
lines = self.screen.dirty
|
lines = self.screen.dirty
|
||||||
else:
|
else:
|
||||||
lines = range(self.screen.lines)
|
lines = range(self.screen.lines)
|
||||||
self.attributes = [[list(attribute[1:]) + [False, 'default', 'default'] for attribute in line.values()] for line in buffer.values()]
|
self.attributes = [[list(attribute[1:]) + [False, 'default', 'default'] for attribute in line.values()] for line in buffer.values()]
|
||||||
|
|
||||||
for y in lines:
|
for y in lines:
|
||||||
try:
|
try:
|
||||||
t = self.attributes[y]
|
t = self.attributes[y]
|
||||||
@ -61,24 +60,24 @@ class Terminal:
|
|||||||
if yPos == -1:
|
if yPos == -1:
|
||||||
yPos = self.screen.cursor.y
|
yPos = self.screen.cursor.y
|
||||||
self.screen.cursor.x = min(self.screen.cursor.x, self.screen.columns - 1)
|
self.screen.cursor.x = min(self.screen.cursor.x, self.screen.columns - 1)
|
||||||
self.screen.cursor.y = min(self.screen.cursor.y, self.screen.lines - 1)
|
self.screen.cursor.y = min(self.screen.cursor.y, self.screen.lines - 1)
|
||||||
def GetScreenContent(self):
|
def GetScreenContent(self):
|
||||||
cursor = self.screen.cursor
|
cursor = self.screen.cursor
|
||||||
self.text = '\n'.join(self.screen.display)
|
self.text = '\n'.join(self.screen.display)
|
||||||
self.updateAttributes(self.attributes == None)
|
self.updateAttributes(self.attributes == None)
|
||||||
self.screen.dirty.clear()
|
self.screen.dirty.clear()
|
||||||
return {"cursor": (cursor.x, cursor.y),
|
return {"cursor": (cursor.x, cursor.y),
|
||||||
'lines': self.screen.lines,
|
'lines': self.screen.lines,
|
||||||
'columns': self.screen.columns,
|
'columns': self.screen.columns,
|
||||||
"text": self.text,
|
"text": self.text,
|
||||||
'attributes': self.attributes.copy(),
|
'attributes': self.attributes.copy(),
|
||||||
'screen': 'pty',
|
'screen': 'pty',
|
||||||
'screenUpdateTime': time.time(),
|
'screenUpdateTime': time.time(),
|
||||||
}.copy()
|
}.copy()
|
||||||
|
|
||||||
class driver(screenDriver):
|
class driver(screenDriver):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
screenDriver.__init__(self)
|
screenDriver.__init__(self)
|
||||||
self.signalPipe = os.pipe()
|
self.signalPipe = os.pipe()
|
||||||
self.p_out = None
|
self.p_out = None
|
||||||
signal.signal(signal.SIGWINCH, self.handleSigwinch)
|
signal.signal(signal.SIGWINCH, self.handleSigwinch)
|
||||||
@ -105,14 +104,14 @@ class driver(screenDriver):
|
|||||||
def readAll(self, fd, timeout = 9999999, interruptFd = None, len = 2048):
|
def readAll(self, fd, timeout = 9999999, interruptFd = None, len = 2048):
|
||||||
bytes = b''
|
bytes = b''
|
||||||
fdList = []
|
fdList = []
|
||||||
fdList += [fd]
|
fdList += [fd]
|
||||||
if interruptFd:
|
if interruptFd:
|
||||||
fdList += [interruptFd]
|
fdList += [interruptFd]
|
||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
while True:
|
while True:
|
||||||
# respect timeout but wait a little bit of time to see if something more is here
|
# respect timeout but wait a little bit of time to see if something more is here
|
||||||
if (time.time() - starttime) >= timeout:
|
if (time.time() - starttime) >= timeout:
|
||||||
break
|
break
|
||||||
r = screen_utils.hasMoreWhat(fdList,0)
|
r = screen_utils.hasMoreWhat(fdList,0)
|
||||||
hasmore = fd in r
|
hasmore = fd in r
|
||||||
if not hasmore:
|
if not hasmore:
|
||||||
@ -124,7 +123,7 @@ class driver(screenDriver):
|
|||||||
if data == b'':
|
if data == b'':
|
||||||
raise EOFError
|
raise EOFError
|
||||||
bytes += data
|
bytes += data
|
||||||
return bytes
|
return bytes
|
||||||
def openTerminal(self, columns, lines, command):
|
def openTerminal(self, columns, lines, command):
|
||||||
p_pid, master_fd = pty.fork()
|
p_pid, master_fd = pty.fork()
|
||||||
if p_pid == 0: # Child.
|
if p_pid == 0: # Child.
|
||||||
@ -151,17 +150,17 @@ class driver(screenDriver):
|
|||||||
lines, columns, _, _ = struct.unpack('HHHH', fcntl.ioctl(fd, termios.TIOCGWINSZ, s))
|
lines, columns, _, _ = struct.unpack('HHHH', fcntl.ioctl(fd, termios.TIOCGWINSZ, s))
|
||||||
return lines, columns
|
return lines, columns
|
||||||
def handleSigwinch(self, *args):
|
def handleSigwinch(self, *args):
|
||||||
os.write(self.signalPipe[1], b'w')
|
os.write(self.signalPipe[1], b'w')
|
||||||
def terminalEmulation(self,active , eventQueue):
|
def terminalEmulation(self,active , eventQueue):
|
||||||
try:
|
try:
|
||||||
old_attr = termios.tcgetattr(sys.stdin)
|
old_attr = termios.tcgetattr(sys.stdin)
|
||||||
tty.setraw(0)
|
tty.setraw(0)
|
||||||
lines, columns = self.getTerminalSize(0)
|
lines, columns = self.getTerminalSize(0)
|
||||||
if self.command == '':
|
if self.command == '':
|
||||||
self.command = screen_utils.getShell()
|
self.command = screen_utils.getShell()
|
||||||
terminal, p_pid, self.p_out = self.openTerminal(columns, lines, self.command)
|
terminal, p_pid, self.p_out = self.openTerminal(columns, lines, self.command)
|
||||||
lines, columns = self.resizeTerminal(self.p_out)
|
lines, columns = self.resizeTerminal(self.p_out)
|
||||||
terminal.resize(lines, columns)
|
terminal.resize(lines, columns)
|
||||||
fdList = [sys.stdin, self.p_out, self.signalPipe[0]]
|
fdList = [sys.stdin, self.p_out, self.signalPipe[0]]
|
||||||
while active.value:
|
while active.value:
|
||||||
r, _, _ = select.select(fdList, [], [], 1)
|
r, _, _ = select.select(fdList, [], [], 1)
|
||||||
@ -172,31 +171,31 @@ class driver(screenDriver):
|
|||||||
if self.signalPipe[0] in r:
|
if self.signalPipe[0] in r:
|
||||||
os.read(self.signalPipe[0], 1)
|
os.read(self.signalPipe[0], 1)
|
||||||
lines, columns = self.resizeTerminal(self.p_out)
|
lines, columns = self.resizeTerminal(self.p_out)
|
||||||
terminal.resize(lines, columns)
|
terminal.resize(lines, columns)
|
||||||
# input
|
# input
|
||||||
if sys.stdin in r:
|
if sys.stdin in r:
|
||||||
try:
|
try:
|
||||||
msgBytes = self.readAll(sys.stdin.fileno())
|
msgBytes = self.readAll(sys.stdin.fileno())
|
||||||
except (EOFError, OSError):
|
except (EOFError, OSError):
|
||||||
active.value = False
|
active.value = False
|
||||||
break
|
break
|
||||||
if self.shortcutType == 'KEY':
|
if self.shortcutType == 'KEY':
|
||||||
try:
|
try:
|
||||||
self.injectTextToScreen(msgBytes)
|
self.injectTextToScreen(msgBytes)
|
||||||
except:
|
except:
|
||||||
active.value = False
|
active.value = False
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
eventQueue.put({"Type":fenrirEventType.ByteInput,
|
eventQueue.put({"Type":fenrirEventType.ByteInput,
|
||||||
"Data":msgBytes })
|
"Data":msgBytes })
|
||||||
# output
|
# output
|
||||||
if self.p_out in r:
|
if self.p_out in r:
|
||||||
try:
|
try:
|
||||||
msgBytes = self.readAll(self.p_out.fileno(), timeout=0.001, interruptFd=sys.stdin)
|
msgBytes = self.readAll(self.p_out.fileno(), timeout=0.001, interruptFd=sys.stdin)
|
||||||
except (EOFError, OSError):
|
except (EOFError, OSError):
|
||||||
active.value = False
|
active.value = False
|
||||||
break
|
break
|
||||||
terminal.feed(msgBytes)
|
terminal.feed(msgBytes)
|
||||||
os.write(sys.stdout.fileno(), msgBytes)
|
os.write(sys.stdout.fileno(), msgBytes)
|
||||||
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
||||||
"Data":screen_utils.createScreenEventData(terminal.GetScreenContent())
|
"Data":screen_utils.createScreenEventData(terminal.GetScreenContent())
|
||||||
@ -206,7 +205,7 @@ class driver(screenDriver):
|
|||||||
active.value = False
|
active.value = False
|
||||||
finally:
|
finally:
|
||||||
os.kill(p_pid, signal.SIGTERM)
|
os.kill(p_pid, signal.SIGTERM)
|
||||||
self.p_out.close()
|
self.p_out.close()
|
||||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
|
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
|
||||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user