More pep8 fixes. A tiny bit of refactoring.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
@ -10,9 +10,9 @@ from fenrirscreenreader.core import debug
|
||||
def get_prev_char(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if x - 1 < 0:
|
||||
@ -25,31 +25,31 @@ def get_prev_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = True
|
||||
else:
|
||||
x -= 1
|
||||
curr_char = ''
|
||||
curr_char = ""
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[y][x]
|
||||
return x, y, curr_char, end_of_screen, line_break
|
||||
|
||||
|
||||
def get_current_char(curr_x, curr_y, curr_text):
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, ""
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char
|
||||
|
||||
|
||||
def get_up_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_y -= 1
|
||||
if curr_y < 0:
|
||||
curr_y = 0
|
||||
else:
|
||||
end_of_screen = True
|
||||
curr_char = ''
|
||||
curr_char = ""
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char, end_of_screen
|
||||
@ -57,15 +57,15 @@ def get_up_char(curr_x, curr_y, curr_text):
|
||||
|
||||
def get_down_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_y += 1
|
||||
if curr_y >= len(wrapped_lines):
|
||||
curr_y = len(wrapped_lines) - 1
|
||||
else:
|
||||
end_of_screen = True
|
||||
curr_char = ''
|
||||
curr_char = ""
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char, end_of_screen
|
||||
@ -73,9 +73,9 @@ def get_down_char(curr_x, curr_y, curr_text):
|
||||
|
||||
def get_last_char_in_line(curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, ""
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_x = len(wrapped_lines[curr_y].rstrip()) - 1
|
||||
if curr_x < 0:
|
||||
curr_x = 0
|
||||
@ -86,9 +86,9 @@ def get_last_char_in_line(curr_y, curr_text):
|
||||
def get_next_char(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if x + 1 == len(wrapped_lines[y]):
|
||||
@ -101,7 +101,7 @@ def get_next_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = True
|
||||
else:
|
||||
x += 1
|
||||
curr_char = ''
|
||||
curr_char = ""
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[y][x]
|
||||
|
||||
@ -112,12 +112,32 @@ def get_phonetic(curr_char):
|
||||
if len(curr_char) != 1:
|
||||
return curr_char
|
||||
phonetics_dict = {
|
||||
"A": "alpha", "B": "bravo", "C": "charlie", "D": "delta", "E": "echo",
|
||||
"F": "foxtrot", "G": "golf", "H": "hotel", "I": "india", "J": "juliet",
|
||||
"K": "kilo", "L": "lima", "M": "mike", "N": "november", "O": "oscar",
|
||||
"P": "papa", "Q": "quebec", "R": "romeo", "S": "sierra", "T": "tango",
|
||||
"U": "uniform", "V": "victor", "W": "whisky", "X": "x ray",
|
||||
"Y": "yankee", "Z": "zulu"
|
||||
"A": "alpha",
|
||||
"B": "bravo",
|
||||
"C": "charlie",
|
||||
"D": "delta",
|
||||
"E": "echo",
|
||||
"F": "foxtrot",
|
||||
"G": "golf",
|
||||
"H": "hotel",
|
||||
"I": "india",
|
||||
"J": "juliet",
|
||||
"K": "kilo",
|
||||
"L": "lima",
|
||||
"M": "mike",
|
||||
"N": "november",
|
||||
"O": "oscar",
|
||||
"P": "papa",
|
||||
"Q": "quebec",
|
||||
"R": "romeo",
|
||||
"S": "sierra",
|
||||
"T": "tango",
|
||||
"U": "uniform",
|
||||
"V": "victor",
|
||||
"W": "whisky",
|
||||
"X": "x ray",
|
||||
"Y": "yankee",
|
||||
"Z": "zulu",
|
||||
}
|
||||
try:
|
||||
phon_char = phonetics_dict[curr_char.upper()]
|
||||
@ -130,23 +150,22 @@ def get_phonetic(curr_char):
|
||||
|
||||
|
||||
def present_char_for_review(
|
||||
env,
|
||||
char,
|
||||
interrupt=True,
|
||||
announce_capital=True,
|
||||
flush=False):
|
||||
env, char, interrupt=True, announce_capital=True, flush=False
|
||||
):
|
||||
"""Present a character for explicit review commands only"""
|
||||
if char == ' ':
|
||||
if ' ' in env['punctuation']['PUNCTDICT']:
|
||||
announce_char = env['punctuation']['PUNCTDICT'][' ']
|
||||
if char == " ":
|
||||
if " " in env["punctuation"]["PUNCTDICT"]:
|
||||
announce_char = env["punctuation"]["PUNCTDICT"][" "]
|
||||
else:
|
||||
announce_char = 'space'
|
||||
env['runtime']['OutputManager'].present_text(
|
||||
announce_char, interrupt=interrupt, flush=flush)
|
||||
announce_char = "space"
|
||||
env["runtime"]["OutputManager"].present_text(
|
||||
announce_char, interrupt=interrupt, flush=flush
|
||||
)
|
||||
else:
|
||||
env['runtime']['OutputManager'].present_text(
|
||||
env["runtime"]["OutputManager"].present_text(
|
||||
char,
|
||||
interrupt=interrupt,
|
||||
ignore_punctuation=True,
|
||||
announce_capital=announce_capital,
|
||||
flush=flush)
|
||||
flush=flush,
|
||||
)
|
||||
|
@ -3,9 +3,11 @@
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
from inspect import isfunction
|
||||
from os import listdir
|
||||
from os.path import isfile
|
||||
from os.path import join
|
||||
|
||||
from xdg import BaseDirectory
|
||||
|
||||
# Get configuration directory
|
||||
|
@ -2,16 +2,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def get_prev_line(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if y - 1 >= 0:
|
||||
@ -19,16 +19,16 @@ def get_prev_line(curr_x, curr_y, curr_text):
|
||||
else:
|
||||
end_of_screen = True
|
||||
x = curr_x
|
||||
curr_line = ''
|
||||
curr_line = ""
|
||||
if not end_of_screen:
|
||||
curr_line = wrapped_lines[y]
|
||||
return x, y, curr_line, end_of_screen
|
||||
|
||||
|
||||
def get_current_line(curr_x, curr_y, curr_text):
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, ""
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
x = 0
|
||||
@ -38,9 +38,9 @@ def get_current_line(curr_x, curr_y, curr_text):
|
||||
|
||||
def get_next_line(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if y + 1 < len(wrapped_lines):
|
||||
@ -48,7 +48,7 @@ def get_next_line(curr_x, curr_y, curr_text):
|
||||
else:
|
||||
end_of_screen = True
|
||||
x = curr_x
|
||||
curr_line = ''
|
||||
curr_line = ""
|
||||
if not end_of_screen:
|
||||
curr_line = wrapped_lines[y]
|
||||
return x, y, curr_line, end_of_screen
|
||||
|
@ -2,66 +2,68 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def get_text_between_marks(firstMark, secondMark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
return ""
|
||||
if not isinstance(in_text, list):
|
||||
in_text = in_text.split('\n')
|
||||
in_text = in_text.split("\n")
|
||||
if len(in_text) < 1:
|
||||
return ''
|
||||
return ""
|
||||
if firstMark is None:
|
||||
return ''
|
||||
return ""
|
||||
if secondMark is None:
|
||||
return ''
|
||||
if (firstMark['y'] + 1) * (firstMark['x'] +
|
||||
1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1):
|
||||
return ""
|
||||
if (firstMark["y"] + 1) * (firstMark["x"] + 1) <= (secondMark["y"] + 1) * (
|
||||
secondMark["x"] + 1
|
||||
):
|
||||
start_mark = firstMark.copy()
|
||||
end_mark = secondMark.copy()
|
||||
else:
|
||||
end_mark = firstMark.copy()
|
||||
start_mark = secondMark.copy()
|
||||
text_part = ''
|
||||
if start_mark['y'] == end_mark['y']:
|
||||
text_part += in_text[start_mark['y']][start_mark['x']:end_mark['x'] + 1]
|
||||
text_part = ""
|
||||
if start_mark["y"] == end_mark["y"]:
|
||||
text_part += in_text[start_mark["y"]][
|
||||
start_mark["x"] : end_mark["x"] + 1
|
||||
]
|
||||
else:
|
||||
curr_y = start_mark['y']
|
||||
while curr_y <= end_mark['y']:
|
||||
if curr_y < end_mark['y']:
|
||||
if curr_y == start_mark['y']:
|
||||
text_part += in_text[curr_y][start_mark['x']:]
|
||||
curr_y = start_mark["y"]
|
||||
while curr_y <= end_mark["y"]:
|
||||
if curr_y < end_mark["y"]:
|
||||
if curr_y == start_mark["y"]:
|
||||
text_part += in_text[curr_y][start_mark["x"] :]
|
||||
else:
|
||||
text_part += in_text[curr_y]
|
||||
if len(in_text[curr_y].strip()) != 0:
|
||||
if len(text_part) - len(text_part.rstrip()) > 0:
|
||||
text_part = text_part[:len(text_part.rstrip())] + "\n"
|
||||
text_part = text_part[: len(text_part.rstrip())] + "\n"
|
||||
else:
|
||||
text_part += '\n'
|
||||
text_part += "\n"
|
||||
else:
|
||||
text_part += in_text[curr_y][:end_mark['x'] + 1]
|
||||
text_part += in_text[curr_y][: end_mark["x"] + 1]
|
||||
curr_y += 1
|
||||
return text_part
|
||||
|
||||
|
||||
def get_text_before_mark(mark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
return ""
|
||||
if mark is None:
|
||||
return ''
|
||||
return get_text_between_marks({'x': 0, 'y': 0}, mark, in_text)
|
||||
return ""
|
||||
return get_text_between_marks({"x": 0, "y": 0}, mark, in_text)
|
||||
|
||||
|
||||
def get_text_after_mark(mark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
return ""
|
||||
if mark is None:
|
||||
return ''
|
||||
in_text = in_text.split('\n')
|
||||
return ""
|
||||
in_text = in_text.split("\n")
|
||||
return get_text_between_marks(
|
||||
mark, {
|
||||
'x': len(
|
||||
in_text[0]) - 1, 'y': len(in_text) - 1}, in_text)
|
||||
mark, {"x": len(in_text[0]) - 1, "y": len(in_text) - 1}, in_text
|
||||
)
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
import sys
|
||||
|
||||
version = sys.version[:3] # we only need major.minor version.
|
||||
if version in ["3.3", "3.4"]:
|
||||
from importlib.machinery import SourceFileLoader
|
||||
@ -15,7 +16,8 @@ def import_module(moduleName, moduleLocation):
|
||||
return SourceFileLoader(moduleName, moduleLocation).load_module()
|
||||
else:
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
moduleName, moduleLocation)
|
||||
moduleName, moduleLocation
|
||||
)
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
return driver_mod
|
||||
|
@ -2,6 +2,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
@ -2,54 +2,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
import getpass
|
||||
import os
|
||||
import string
|
||||
import time
|
||||
from select import select
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
import getpass
|
||||
import time
|
||||
import string
|
||||
import os
|
||||
from select import select
|
||||
|
||||
|
||||
def remove_nonprintable(text):
|
||||
# Get the difference of all ASCII characters from the set of printable
|
||||
# characters
|
||||
nonprintable = set([chr(i) for i in range(128)]
|
||||
).difference(string.printable)
|
||||
nonprintable = set([chr(i) for i in range(128)]).difference(
|
||||
string.printable
|
||||
)
|
||||
# Use translate to remove all non-printable characters
|
||||
return text.translate({ord(character): None for character in nonprintable})
|
||||
|
||||
|
||||
def insert_newlines(string, every=64):
|
||||
return '\n'.join(string[i:i + every] for i in range(0, len(string), every))
|
||||
return "\n".join(
|
||||
string[i : i + every] for i in range(0, len(string), every)
|
||||
)
|
||||
|
||||
|
||||
def split_every(toSplit, every=64):
|
||||
return list(toSplit[i:i + every] for i in range(0, len(toSplit), every))
|
||||
return list(toSplit[i : i + every] for i in range(0, len(toSplit), every))
|
||||
|
||||
|
||||
def create_screen_event_data(content):
|
||||
event_data = {
|
||||
'bytes': content,
|
||||
'lines': content['lines'],
|
||||
'columns': content['columns'],
|
||||
'textCursor':
|
||||
{
|
||||
'x': int(content['cursor'][0]),
|
||||
'y': int(content['cursor'][1])
|
||||
"bytes": content,
|
||||
"lines": content["lines"],
|
||||
"columns": content["columns"],
|
||||
"textCursor": {
|
||||
"x": int(content["cursor"][0]),
|
||||
"y": int(content["cursor"][1]),
|
||||
},
|
||||
'screen': content['screen'],
|
||||
'text': content['text'],
|
||||
'attributes': content['attributes'],
|
||||
'screenUpdateTime': time.time(),
|
||||
"screen": content["screen"],
|
||||
"text": content["text"],
|
||||
"attributes": content["attributes"],
|
||||
"screenUpdateTime": time.time(),
|
||||
}
|
||||
return event_data.copy()
|
||||
|
||||
|
||||
def has_more(fd, timetout=0.05):
|
||||
r, _, _ = select([fd], [], [], timetout)
|
||||
return (fd in r)
|
||||
return fd in r
|
||||
|
||||
|
||||
def has_more_what(fd_list, timetout=0.05):
|
||||
@ -61,10 +64,10 @@ def has_more_what(fd_list, timetout=0.05):
|
||||
return r
|
||||
|
||||
|
||||
def is_valid_shell(shell=''):
|
||||
def is_valid_shell(shell=""):
|
||||
if not isinstance(shell, str):
|
||||
return False
|
||||
if shell == '':
|
||||
if shell == "":
|
||||
return False
|
||||
try:
|
||||
if not os.path.isfile(shell):
|
||||
@ -73,7 +76,9 @@ def is_valid_shell(shell=''):
|
||||
return False
|
||||
except Exception as e:
|
||||
# Utility function, no env access - use fallback logging
|
||||
print(f'screen_utils is_valid_shell: Error checking shell {shell}: {e}')
|
||||
print(
|
||||
f"screen_utils is_valid_shell: Error checking shell {shell}: {e}"
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
@ -94,19 +99,20 @@ def get_shell():
|
||||
# Utility function, no env access - continue silently
|
||||
pass
|
||||
try:
|
||||
if os.access('/etc/passwd', os.R_OK):
|
||||
with open('/etc/passwd') as f:
|
||||
if os.access("/etc/passwd", os.R_OK):
|
||||
with open("/etc/passwd") as f:
|
||||
users = f.readlines()
|
||||
for user in users:
|
||||
(username, encrypwd, uid, gid, gecos,
|
||||
homedir, shell) = user.split(':')
|
||||
shell = shell.replace('\n', '')
|
||||
(username, encrypwd, uid, gid, gecos, homedir, shell) = (
|
||||
user.split(":")
|
||||
)
|
||||
shell = shell.replace("\n", "")
|
||||
if username == getpass.getuser():
|
||||
if is_valid_shell(shell):
|
||||
return shell
|
||||
except Exception as e:
|
||||
# Utility function, no env access - continue silently
|
||||
pass
|
||||
if is_valid_shell('/bin/bash'):
|
||||
return '/bin/bash'
|
||||
return '/bin/sh'
|
||||
if is_valid_shell("/bin/bash"):
|
||||
return "/bin/bash"
|
||||
return "/bin/sh"
|
||||
|
@ -2,26 +2,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
import string
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
import string
|
||||
|
||||
|
||||
def get_current_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == "":
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
curr_word = ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_word = ""
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_line = wrapped_lines[y]
|
||||
found = False
|
||||
while (not found):
|
||||
while not found:
|
||||
if not curr_line[x] in string.whitespace:
|
||||
if x == 0:
|
||||
found = True
|
||||
@ -33,7 +34,7 @@ def get_current_word(curr_x, curr_y, curr_text):
|
||||
if y - 1 < 0:
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
else:
|
||||
y -= 1
|
||||
curr_line = wrapped_lines[y]
|
||||
@ -48,27 +49,28 @@ def get_current_word(curr_x, curr_y, curr_text):
|
||||
if delimiter_pos != -1:
|
||||
curr_word = curr_word[:delimiter_pos]
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
return curr_x, curr_y, '', False, False
|
||||
return curr_x, curr_y, "", False, False
|
||||
|
||||
|
||||
def get_prev_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == "":
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
x, y, curr_word, end_of_screen, line_break_curr_word = get_current_word(
|
||||
curr_x, curr_y, curr_text)
|
||||
curr_x, curr_y, curr_text
|
||||
)
|
||||
if end_of_screen:
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_line = wrapped_lines[y]
|
||||
if x - 1 < 0:
|
||||
if y - 1 < 0:
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
else:
|
||||
y -= 1
|
||||
curr_line = wrapped_lines[y]
|
||||
@ -77,7 +79,9 @@ def get_prev_word(curr_x, curr_y, curr_text):
|
||||
else:
|
||||
x -= 1
|
||||
line_break_curr_word = line_break or line_break_curr_word
|
||||
x, y, curr_word, end_of_screen, line_break = get_current_word(x, y, curr_text)
|
||||
x, y, curr_word, end_of_screen, line_break = get_current_word(
|
||||
x, y, curr_text
|
||||
)
|
||||
line_break = line_break or line_break_curr_word
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
|
||||
@ -85,23 +89,23 @@ def get_prev_word(curr_x, curr_y, curr_text):
|
||||
def get_next_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
if curr_text == "":
|
||||
return -1, -1, "", end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == "":
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
curr_word = ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_word = ""
|
||||
wrapped_lines = curr_text.split("\n")
|
||||
curr_line = wrapped_lines[y]
|
||||
found = False
|
||||
while (not found):
|
||||
while not found:
|
||||
if not found:
|
||||
if x + 1 > len(curr_line) - 1:
|
||||
if y + 1 > len(wrapped_lines) - 1:
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
return curr_x, curr_y, "", end_of_screen, line_break
|
||||
else:
|
||||
y += 1
|
||||
curr_line = wrapped_lines[y]
|
||||
@ -122,4 +126,4 @@ def get_next_word(curr_x, curr_y, curr_text):
|
||||
if delimiter_pos != -1:
|
||||
curr_word = curr_word[:delimiter_pos]
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
return curr_x, curr_y, '', False, False
|
||||
return curr_x, curr_y, "", False, False
|
||||
|
Reference in New Issue
Block a user