From 7f91223f945b8376340aed9f444ae1109d134235 Mon Sep 17 00:00:00 2001 From: Chrys Date: Thu, 29 Aug 2019 17:51:34 +0200 Subject: [PATCH 1/8] replace replace by sub --- .../core/punctuationManager.py | 9 ++--- .../screenDriver/ptyDriver.py | 38 +++++++++++++------ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/fenrirscreenreader/core/punctuationManager.py b/src/fenrirscreenreader/core/punctuationManager.py index a98577ea..095b8506 100644 --- a/src/fenrirscreenreader/core/punctuationManager.py +++ b/src/fenrirscreenreader/core/punctuationManager.py @@ -33,15 +33,14 @@ class punctuationManager(): del currAllPunctNone[ord(char)] except: pass - return text.translate(currAllPunctNone) - + return text.translate(currAllPunctNone) def useCustomDict(self, text, customDict, seperator=''): resultText = str(text) if customDict: for key,item in customDict.items(): - resultText = resultText.replace(str(key),seperator + str(item) + seperator) + #resultText = resultText.replace(str(key),seperator + str(item) + seperator) + resultText = re.sub(str(key), str(item), resultText) return resultText - def usePunctuationDict(self, text, punctuationDict, punctuation): resultText = str(text) @@ -53,7 +52,7 @@ class punctuationManager(): if self.env['runtime']['settingsManager'].getSetting('general', 'respectPunctuationPause') and \ len(key) == 1 and \ key in "',.;:?!": - resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') + resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') else: resultText = resultText.replace(str(key),' ' +str(item) + ' ') return resultText diff --git a/src/fenrirscreenreader/screenDriver/ptyDriver.py b/src/fenrirscreenreader/screenDriver/ptyDriver.py index 7f0ced69..388083a6 100644 --- a/src/fenrirscreenreader/screenDriver/ptyDriver.py +++ b/src/fenrirscreenreader/screenDriver/ptyDriver.py @@ -87,6 +87,13 @@ class driver(screenDriver): self.env = environment self.command = self.env['runtime']['settingsManager'].getSetting('general','shell') self.shortcutType = self.env['runtime']['inputManager'].getShortcutType() + param = [sys.stdin.fileno(), sys.stdout.fileno(), self.signalPipe, self.p_out, self.p_pid] + #param[0] = sys.stdin + #param[1] = sys.stdout + #param[2] = self.signalPipe + #param[3] = self.p_out + #param[4] = self.p_pid + self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation, pargs = param, multiprocess = False) self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation) def getCurrScreen(self): self.env['screen']['oldTTY'] = 'pty' @@ -153,17 +160,26 @@ class driver(screenDriver): return lines, columns def handleSigwinch(self, *args): os.write(self.signalPipe[1], b'w') - def terminalEmulation(self,active , eventQueue): - try: - old_attr = termios.tcgetattr(sys.stdin) - tty.setraw(0) - lines, columns = self.getTerminalSize(0) - if self.command == '': - self.command = screen_utils.getShell() - self.terminal, self.p_pid, self.p_out = self.openTerminal(columns, lines, self.command) - lines, columns = self.resizeTerminal(self.p_out) - self.terminal.resize(lines, columns) - fdList = [sys.stdin, self.p_out, self.signalPipe[0]] + def terminalEmulation(self,active , eventQueue, param = None): + try: + #stdin = param[0] + stdin = os.fdopen(param[0]) + stdout = os.fdopen(param[1]) + signalPipe = param[2] + p_outFd = param[3] + p_pid = param[4] + old_attr = termios.tcgetattr(stdin) + tty.setraw(0) + lines, columns = self.getTerminalSize(0) + if self.command == '': + self.command = screen_utils.getShell() + terminal, p_pid.value, fd = self.openTerminal(columns, lines, self.command) + p_outFd.value = os.dup(fd) + p_out = fd + #p_out = os.fdopen(p_outFd.value, "r+b", 0) + lines, columns = self.resizeTerminal(p_out) + terminal.resize(lines, columns) + fdList = [stdin, p_out, signalPipe[0]] while active.value: r, _, _ = select(fdList, [], [], 1) # none From 6b6de57c9ec26fa2af30d8cfd93382be75da579b Mon Sep 17 00:00:00 2001 From: Chrys Date: Thu, 29 Aug 2019 17:52:57 +0200 Subject: [PATCH 2/8] Revert "replace replace by sub" This reverts commit 7f91223f945b8376340aed9f444ae1109d134235. --- .../core/punctuationManager.py | 9 +++-- .../screenDriver/ptyDriver.py | 38 ++++++------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/fenrirscreenreader/core/punctuationManager.py b/src/fenrirscreenreader/core/punctuationManager.py index 095b8506..a98577ea 100644 --- a/src/fenrirscreenreader/core/punctuationManager.py +++ b/src/fenrirscreenreader/core/punctuationManager.py @@ -33,14 +33,15 @@ class punctuationManager(): del currAllPunctNone[ord(char)] except: pass - return text.translate(currAllPunctNone) + return text.translate(currAllPunctNone) + def useCustomDict(self, text, customDict, seperator=''): resultText = str(text) if customDict: for key,item in customDict.items(): - #resultText = resultText.replace(str(key),seperator + str(item) + seperator) - resultText = re.sub(str(key), str(item), resultText) + resultText = resultText.replace(str(key),seperator + str(item) + seperator) return resultText + def usePunctuationDict(self, text, punctuationDict, punctuation): resultText = str(text) @@ -52,7 +53,7 @@ class punctuationManager(): if self.env['runtime']['settingsManager'].getSetting('general', 'respectPunctuationPause') and \ len(key) == 1 and \ key in "',.;:?!": - resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') + resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') else: resultText = resultText.replace(str(key),' ' +str(item) + ' ') return resultText diff --git a/src/fenrirscreenreader/screenDriver/ptyDriver.py b/src/fenrirscreenreader/screenDriver/ptyDriver.py index 388083a6..7f0ced69 100644 --- a/src/fenrirscreenreader/screenDriver/ptyDriver.py +++ b/src/fenrirscreenreader/screenDriver/ptyDriver.py @@ -87,13 +87,6 @@ class driver(screenDriver): self.env = environment self.command = self.env['runtime']['settingsManager'].getSetting('general','shell') self.shortcutType = self.env['runtime']['inputManager'].getShortcutType() - param = [sys.stdin.fileno(), sys.stdout.fileno(), self.signalPipe, self.p_out, self.p_pid] - #param[0] = sys.stdin - #param[1] = sys.stdout - #param[2] = self.signalPipe - #param[3] = self.p_out - #param[4] = self.p_pid - self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation, pargs = param, multiprocess = False) self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation) def getCurrScreen(self): self.env['screen']['oldTTY'] = 'pty' @@ -160,26 +153,17 @@ class driver(screenDriver): return lines, columns def handleSigwinch(self, *args): os.write(self.signalPipe[1], b'w') - def terminalEmulation(self,active , eventQueue, param = None): - try: - #stdin = param[0] - stdin = os.fdopen(param[0]) - stdout = os.fdopen(param[1]) - signalPipe = param[2] - p_outFd = param[3] - p_pid = param[4] - old_attr = termios.tcgetattr(stdin) - tty.setraw(0) - lines, columns = self.getTerminalSize(0) - if self.command == '': - self.command = screen_utils.getShell() - terminal, p_pid.value, fd = self.openTerminal(columns, lines, self.command) - p_outFd.value = os.dup(fd) - p_out = fd - #p_out = os.fdopen(p_outFd.value, "r+b", 0) - lines, columns = self.resizeTerminal(p_out) - terminal.resize(lines, columns) - fdList = [stdin, p_out, signalPipe[0]] + def terminalEmulation(self,active , eventQueue): + try: + old_attr = termios.tcgetattr(sys.stdin) + tty.setraw(0) + lines, columns = self.getTerminalSize(0) + if self.command == '': + self.command = screen_utils.getShell() + self.terminal, self.p_pid, self.p_out = self.openTerminal(columns, lines, self.command) + lines, columns = self.resizeTerminal(self.p_out) + self.terminal.resize(lines, columns) + fdList = [sys.stdin, self.p_out, self.signalPipe[0]] while active.value: r, _, _ = select(fdList, [], [], 1) # none From 1155103389715321ba2c0b720571082418924110 Mon Sep 17 00:00:00 2001 From: Chrys Date: Thu, 29 Aug 2019 17:55:19 +0200 Subject: [PATCH 3/8] replace replace by sub --- src/fenrirscreenreader/core/punctuationManager.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fenrirscreenreader/core/punctuationManager.py b/src/fenrirscreenreader/core/punctuationManager.py index a98577ea..f7c6bfb6 100644 --- a/src/fenrirscreenreader/core/punctuationManager.py +++ b/src/fenrirscreenreader/core/punctuationManager.py @@ -33,15 +33,14 @@ class punctuationManager(): del currAllPunctNone[ord(char)] except: pass - return text.translate(currAllPunctNone) - + return text.translate(currAllPunctNone) def useCustomDict(self, text, customDict, seperator=''): resultText = str(text) if customDict: for key,item in customDict.items(): - resultText = resultText.replace(str(key),seperator + str(item) + seperator) + #resultText = resultText.replace(str(key),seperator + str(item) + seperator) + resultText = re.sub(str(key), seperator + str(item) + seperator, resultText) return resultText - def usePunctuationDict(self, text, punctuationDict, punctuation): resultText = str(text) @@ -53,7 +52,7 @@ class punctuationManager(): if self.env['runtime']['settingsManager'].getSetting('general', 'respectPunctuationPause') and \ len(key) == 1 and \ key in "',.;:?!": - resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') + resultText = resultText.replace(str(key),' ' +str(item) + str(key) + ' ') else: resultText = resultText.replace(str(key),' ' +str(item) + ' ') return resultText From 7dd5b609de907f72d09048260e06a19ef608dace Mon Sep 17 00:00:00 2001 From: Chrys Date: Thu, 29 Aug 2019 18:08:22 +0200 Subject: [PATCH 4/8] replace replace by sub --- src/fenrirscreenreader/core/punctuationManager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fenrirscreenreader/core/punctuationManager.py b/src/fenrirscreenreader/core/punctuationManager.py index f7c6bfb6..767d62ae 100644 --- a/src/fenrirscreenreader/core/punctuationManager.py +++ b/src/fenrirscreenreader/core/punctuationManager.py @@ -38,8 +38,10 @@ class punctuationManager(): resultText = str(text) if customDict: for key,item in customDict.items(): - #resultText = resultText.replace(str(key),seperator + str(item) + seperator) - resultText = re.sub(str(key), seperator + str(item) + seperator, resultText) + try: + resultText = re.sub(str(key), seperator + str(item) + seperator, resultText) + except: + resultText = resultText.replace(str(key),seperator + str(item) + seperator) return resultText def usePunctuationDict(self, text, punctuationDict, punctuation): resultText = str(text) From 46427342b351c3ef117030a079591b2cea468129 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 29 Aug 2019 12:33:32 -0400 Subject: [PATCH 5/8] Emoticons escaped. Comments added explaing custom and emoticon dicts use regexp. --- config/punctuation/default.conf | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/config/punctuation/default.conf b/config/punctuation/default.conf index e3995e53..f99d0d6c 100644 --- a/config/punctuation/default.conf +++ b/config/punctuation/default.conf @@ -44,26 +44,28 @@ _:===:line =:===:equals [customDict] +# This dictionary uses regexp, so be sure to escape anything that would be parsed by regexp, e.g. *, ., ^, $, etc. [emoticonDict] +# This dictionary uses regexp, so be sure to escape anything that would be parsed by regexp, e.g. *, ., ^, $, etc. <{-.-}>:===:Raves -8-):===:smile with sunglasses +8-\):===:smile with sunglasses :-/:===:confused --.-:===:bugged ->.<:===:laughing +-\.-:===:bugged +>\.<:===:laughing 8-X:===:skull ->:):===:evil smile ->:-):===:evil smile -\o/:===:Hurray +>:\):===:evil smile +>:-\):===:evil smile +\\o/:===:Hurray :/:===:confused -8):===:smile with sunglasses +8\):===:smile with sunglasses :D:===:laugh -;):===:wink +;\):===:wink XD:===:LOL -:-):===:smile -:):===:smile +:-\):===:smile +:\):===:smile ->:===:arrow right <-:===:arrow left oO:===:WTF? Oo:===:WTF? -^^:===:enjoy smile +\^\^:===:enjoy smile From f676819eaedb881f035e05f207d4f2c829c503cf Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 29 Aug 2019 12:46:40 -0400 Subject: [PATCH 6/8] Regexp for emoticons. --- config/punctuation/default.conf | 41 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/config/punctuation/default.conf b/config/punctuation/default.conf index f99d0d6c..4e127f09 100644 --- a/config/punctuation/default.conf +++ b/config/punctuation/default.conf @@ -48,24 +48,23 @@ _:===:line [emoticonDict] # This dictionary uses regexp, so be sure to escape anything that would be parsed by regexp, e.g. *, ., ^, $, etc. -<{-.-}>:===:Raves -8-\):===:smile with sunglasses -:-/:===:confused --\.-:===:bugged ->\.<:===:laughing -8-X:===:skull ->:\):===:evil smile ->:-\):===:evil smile -\\o/:===:Hurray -:/:===:confused -8\):===:smile with sunglasses -:D:===:laugh -;\):===:wink -XD:===:LOL -:-\):===:smile -:\):===:smile -->:===:arrow right -<-:===:arrow left -oO:===:WTF? -Oo:===:WTF? -\^\^:===:enjoy smile +[\s*|'|"][\s*|'|"]<{-.-}>:===:Raves +[\s*|'|"][\s*|'|"]8-\):===:smile with sunglasses +[\s*|'|"][\s*|'|"]:-/:===:confused +[\s*|'|"][\s*|'|"]-\.-:===:bugged +[\s*|'|"][\s*|'|"]>\.<:===:laughing +[\s*|'|"][\s*|'|"]8-X:===:skull +[\s*|'|"][\s*|'|"]>:\):===:evil smile +[\s*|'|"][\s*|'|"]>:-\):===:evil smile +[\s*|'|"][\s*|'|"]\\o/:===:Hurray +[\s*|'|"][\s*|'|"]:/:===:confused +[\s*|'|"][\s*|'|"]8\):===:smile with sunglasses +[\s*|'|"][\s*|'|"]:D:===:laugh +[\s*|'|"][\s*|'|"];\):===:wink +[\s*|'|"]XD[\s*|'|"]:===:LOL +[\s*|'|"]:-\)[\s*|'|"]:===:smile +[\s*|'|"]:\)[\s*|'|"]:===:smile +[\s*|'|"]->[\s*|'|"]:===:arrow right +[\s*|'|"]<-[\s*|'|"]:===:arrow left +[\s*|'|"][O|o][O|o][\s*|'|"]:===:WTF? +[\s*|'|"]\^\^[\s*|'|"]:===:enjoy smile From 45a27be67992f682fd88a8eeaab5d9a71c525110 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 30 Aug 2019 07:02:25 -0400 Subject: [PATCH 7/8] Regexp changes for smileys. --- config/punctuation/default.conf | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/config/punctuation/default.conf b/config/punctuation/default.conf index 4e127f09..f177c2ac 100644 --- a/config/punctuation/default.conf +++ b/config/punctuation/default.conf @@ -48,23 +48,23 @@ _:===:line [emoticonDict] # This dictionary uses regexp, so be sure to escape anything that would be parsed by regexp, e.g. *, ., ^, $, etc. -[\s*|'|"][\s*|'|"]<{-.-}>:===:Raves -[\s*|'|"][\s*|'|"]8-\):===:smile with sunglasses -[\s*|'|"][\s*|'|"]:-/:===:confused -[\s*|'|"][\s*|'|"]-\.-:===:bugged -[\s*|'|"][\s*|'|"]>\.<:===:laughing -[\s*|'|"][\s*|'|"]8-X:===:skull -[\s*|'|"][\s*|'|"]>:\):===:evil smile -[\s*|'|"][\s*|'|"]>:-\):===:evil smile -[\s*|'|"][\s*|'|"]\\o/:===:Hurray -[\s*|'|"][\s*|'|"]:/:===:confused -[\s*|'|"][\s*|'|"]8\):===:smile with sunglasses -[\s*|'|"][\s*|'|"]:D:===:laugh -[\s*|'|"][\s*|'|"];\):===:wink -[\s*|'|"]XD[\s*|'|"]:===:LOL -[\s*|'|"]:-\)[\s*|'|"]:===:smile -[\s*|'|"]:\)[\s*|'|"]:===:smile -[\s*|'|"]->[\s*|'|"]:===:arrow right -[\s*|'|"]<-[\s*|'|"]:===:arrow left -[\s*|'|"][O|o][O|o][\s*|'|"]:===:WTF? -[\s*|'|"]\^\^[\s*|'|"]:===:enjoy smile +.*[\s*|'|"][\s*|'|"]<{-.-}>.*:===:Raves +.*[\s*|'|"][\s*|'|"]8-\).*:===:smile with sunglasses +.*[\s*|'|"][\s*|'|"]:-/.*:===:confused +.*[\s*|'|"][\s*|'|"]-\.-.*:===:bugged +.*[\s*|'|"][\s*|'|"]>\.<.*:===:laughing +.*[\s*|'|"][\s*|'|"]8-X.*:===:skull +.*[\s*|'|"][\s*|'|"]>:\).*:===:evil smile +.*[\s*|'|"][\s*|'|"]>:-\).*:===:evil smile +.*[\s*|'|"][\s*|'|"]\\o/.*:===:Hurray +.*[\s*|'|"][\s*|'|"]:/.*:===:confused +.*[\s*|'|"][\s*|'|"]8\).*:===:smile with sunglasses +.*[\s*|'|"]:D[\s*|'|"].*:===:laugh +.*[\s*|'|"];\)[\s*|'|"].*:===:wink +.*[\s*|'|"]XD[\s*|'|"].*:===:LOL +.*[\s*|'|"]:-\)[\s*|'|"].*:===:smile +.*[\s*|'|"]:\)[\s*|'|"].*:===:smile +.*[\s*|'|"]->[\s*|'|"].*:===:arrow right +.*[\s*|'|"]<-[\s*|'|"].*:===:arrow left +.*[\s*|'|"][O|o][O|o][\s*|'|"].*:===:WTF? +.*[\s*|'|"]\^\^[\s*|'|"].*:===:enjoy smile From 6dbd82da7139468f67afa02137f75427279c210b Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 30 Aug 2019 13:57:28 +0200 Subject: [PATCH 8/8] Update default.conf --- config/punctuation/default.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/punctuation/default.conf b/config/punctuation/default.conf index f177c2ac..9b5e1622 100644 --- a/config/punctuation/default.conf +++ b/config/punctuation/default.conf @@ -65,6 +65,10 @@ _:===:line .*[\s*|'|"]:-\)[\s*|'|"].*:===:smile .*[\s*|'|"]:\)[\s*|'|"].*:===:smile .*[\s*|'|"]->[\s*|'|"].*:===:arrow right +# example for arrow left +#(?:[ |^])(<-)(?:[ ,.!?$]):===:arrow left +# or +#([ |^])<-([ ,.!?$]):===:arrow left\2 .*[\s*|'|"]<-[\s*|'|"].*:===:arrow left .*[\s*|'|"][O|o][O|o][\s*|'|"].*:===:WTF? .*[\s*|'|"]\^\^[\s*|'|"].*:===:enjoy smile