more work on restructure (screenManager, input handling)

This commit is contained in:
chrys 2016-09-04 15:04:23 +02:00
parent 9d63a30597
commit ae71bd4ef7
5 changed files with 23 additions and 13 deletions

View File

@ -35,7 +35,7 @@ class commandManager():
return environment
def executeTriggerCommands(self, environment, trigger):
if environment['generalInformation']['suspend']:
if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
return environment
for cmd in sorted(environment['commands'][trigger]):
try:
@ -43,6 +43,7 @@ class commandManager():
if environ != None:
environment = environ
except Exception as e:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
return environment
@ -56,21 +57,27 @@ class commandManager():
if environ != None:
environment = environ
except Exception as e:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + currCommand ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
environment['commandInfo']['currCommand'] = ''
environment['commandInfo']['lastCommandTime'] = time.time()
return environment
def isShortcutDefined(self, environment):
def isShortcutDefined(self, environment, currCommand):
return( environment['input']['currShortcutString'] in environment['bindings'])
def getCommandForShortcut(self, environment):
def setCurrCommandForExec(self, environment, currCommand=''):
if not self.isShortcutDefined(environment):
return environment
environment['commandInfo']['currCommand'] = environment['bindings'][environment['input']['currShortcutString']]
environment['commandInfo']['currCommand'] = currCommand
return environment
def isCommandDefined(self, environment):
return( environment['commandInfo']['currCommand'] in environment['commands']['commands'])
def getCommandForShortcut(self, environment, currShortcutString):
if not self.isShortcutDefined(environment):
return environment
return environment['bindings'][currShortcutString]
def isCommandDefined(self, environment, currCommand):
return( currCommand in environment['commands']['commands'])

View File

@ -2,5 +2,4 @@
generalInformation = {
'running': True,
'suspend': False,
}

View File

@ -13,6 +13,7 @@ class screenManager():
environment['generalInformation']['suspend'] = self.isSuspendingScreen(environment)
if not environment['generalInformation']['suspend']:
environment = environment['runtime']['screenDriver'].update(environment)
environment['screenData']['lastScreenUpdate'] = time.time()
return environment
def isSuspendingScreen(self, environment):

View File

@ -35,7 +35,9 @@ class fenrir():
except Exception as e:
self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)
if not self.environment['input']['keyForeward']:
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
currCommand = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
self.environment = self.environment['runtime']['commandManager'].setCurrCommandForExec(self.environment, currCommand)
if not timeout:
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')

View File

@ -2,19 +2,21 @@
# -*- coding: utf-8 -*-
import difflib
import time
import re
from utils import debug
class screen():
def __init__(self):
self.vcsaDevicePath = '/dev/vcsa'
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def insert_newlines(self, string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
def getCurrScreen(self):
currScreen = -1
try:
@ -63,7 +65,6 @@ class screen():
# analyze content
environment['screenData']['newContentText'] = environment['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2]
#environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2]
environment['screenData']['newContentText'] = self.insert_newlines(environment['screenData']['newContentText'], environment['screenData']['columns'])
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: