From 0d2c095b6274792d61296fe1ad671e8630490b60 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 2 Oct 2016 18:08:21 +0200 Subject: [PATCH] add review_line_last_char --- config/keyboard/desktop.conf | 1 + config/keyboard/laptop.conf | 1 + config/keyboard/test.conf | 3 +- .../commands/review_line_last_char.py | 33 +++++++++++++++++++ src/fenrir-package/utils/char_utils.py | 10 ++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/fenrir-package/commands/commands/review_line_last_char.py diff --git a/config/keyboard/desktop.conf b/config/keyboard/desktop.conf index 8877893b..670834f8 100644 --- a/config/keyboard/desktop.conf +++ b/config/keyboard/desktop.conf @@ -7,6 +7,7 @@ KEY_KP7=review_prev_line KEY_KP9=review_next_line KEY_FENRIR,KEY_KP4=review_line_begin KEY_FENRIR,KEY_KP6=review_line_end +#=review_line_last_char KEY_FENRIR,KEY_ALT,KEY_1=present_first_line KEY_FENRIR,KEY_ALT,KEY_2=present_last_line KEY_KP5=review_curr_word diff --git a/config/keyboard/laptop.conf b/config/keyboard/laptop.conf index 7c198733..fcbdcf0e 100644 --- a/config/keyboard/laptop.conf +++ b/config/keyboard/laptop.conf @@ -7,6 +7,7 @@ KEY_FENRIR,KEY_U=review_prev_line KEY_FENRIR,KEY_O=review_next_line KEY_FENRIR,KEY_SHIFT,KEY_J=review_line_begin KEY_FENRIR,KEY_SHFIT,KEY_L=review_line_end +#=review_line_last_char KEY_FENRIR,KEY_ALT,KEY_1=present_first_line KEY_FENRIR,KEY_ALT,KEY_2=present_last_line KEY_FENRIR,KEY_K=review_curr_word diff --git a/config/keyboard/test.conf b/config/keyboard/test.conf index b7235885..61ff8c8e 100644 --- a/config/keyboard/test.conf +++ b/config/keyboard/test.conf @@ -5,8 +5,9 @@ KEY_FENRIR,KEY_KP7=review_top KEY_KP8=review_curr_line KEY_KP7=review_prev_line KEY_KP9=review_next_line -KEY_FENRIR,KEY_KP6=review_line_end +#KEY_FENRIR,KEY_KP6=review_line_end KEY_FENRIR,KEY_KP5=review_line_begin +KEY_FENRIR,KEY_KP6=review_line_last_char #=present_first_line #=present_last_line KEY_KP5=review_curr_word diff --git a/src/fenrir-package/commands/commands/review_line_last_char.py b/src/fenrir-package/commands/commands/review_line_last_char.py new file mode 100644 index 00000000..6a494543 --- /dev/null +++ b/src/fenrir-package/commands/commands/review_line_last_char.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to end of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['runtime']['cursorManager'].setReviewCursorPosition(self.env['screenData']['columns']-1 ,cursorPos['y']) + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], lastChar = \ + char_utils.getLastCharInLine(self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if lastChar.strip(" \t\n") == '': + self.env['runtime']['outputManager'].presentText("line is empty" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(lastChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + self.env['runtime']['outputManager'].presentText("last char in line", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir-package/utils/char_utils.py b/src/fenrir-package/utils/char_utils.py index 902d781c..baa0ec4e 100644 --- a/src/fenrir-package/utils/char_utils.py +++ b/src/fenrir-package/utils/char_utils.py @@ -28,6 +28,16 @@ def getCurrentChar(currX,currY, currText): currChar = wrappedLines[currY][currX] return currX, currY, currChar +def getLastCharInLine(currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currX = len(wrappedLines[currY].rstrip())-1 + if currX < 0: + currX = 0 + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + def getNextChar(currX,currY, currText): if currText == '': return -1, -1, ''