Merge pull request 'Adds a fix to the readline issues we've been seeing' (#96) from readline-escape-fix into master
Reviewed-on: #96
This commit is contained in:
commit
e408c3e1aa
|
@ -58,7 +58,7 @@ def print_category_details(view_cat):
|
|||
# unread mark width
|
||||
|
||||
header = "\n{}\n\n {:>3s} {:>10s} {:<{namelen}s} {:<5} {:<s}".format(
|
||||
style_text(view_cat["name"].upper(), "bold"),
|
||||
style_text(view_cat["name"].upper(), False, "bold"),
|
||||
"ID#",
|
||||
"DATE",
|
||||
"AUTHOR",
|
||||
|
@ -125,15 +125,15 @@ def print_thread_details(post_id) -> tuple:
|
|||
)
|
||||
|
||||
# post detail view
|
||||
print("\n\n{:<17}: {}".format(style_text("Title", "bold"), post_title))
|
||||
print("{:<17}: {}".format(style_text("Link", "bold"), post_url))
|
||||
print("{:<17}: {}".format(style_text("Category", "bold"), post_category))
|
||||
print("{:<17}: {}".format(style_text("User", "bold"), post_username))
|
||||
print("{:<17}: {}".format(style_text("Date", "bold"), post_datetime))
|
||||
print("\n\n{:<17}: {}".format(style_text("Title", False, "bold"), post_title))
|
||||
print("{:<17}: {}".format(style_text("Link", False, "bold"), post_url))
|
||||
print("{:<17}: {}".format(style_text("Category", flase, "bold"), post_category))
|
||||
print("{:<17}: {}".format(style_text("User", False, "bold"), post_username))
|
||||
print("{:<17}: {}".format(style_text("Date", False, "bold"), post_datetime))
|
||||
|
||||
# post reply view
|
||||
if replies:
|
||||
print("\n{}:\n".format(style_text("Replies", "underline")))
|
||||
print("\n{}:\n".format(style_text("Replies", False, "underline")))
|
||||
for line in replies:
|
||||
comment_author = line[1]
|
||||
comment_date = datetime.fromtimestamp(float(line[2])).isoformat(
|
||||
|
@ -189,9 +189,9 @@ def search():
|
|||
print_search_results(keyword, search_results)
|
||||
option = input(
|
||||
"Enter a post ID to see its thread, {} to start a new search, {} to go back, or {} to quit: ".format(
|
||||
style_text("s", "underline"),
|
||||
style_text("m", "underline"),
|
||||
style_text("q", "underline"),
|
||||
style_text("s", False, "underline"),
|
||||
style_text("m", False, "underline"),
|
||||
style_text("q", False, "underline"),
|
||||
)
|
||||
).lower()
|
||||
if option == "q":
|
||||
|
@ -207,7 +207,7 @@ def search():
|
|||
raise IndexError("Invalid post ID")
|
||||
except (KeyError, ValueError, IndexError):
|
||||
# Catch a Post ID that is not in the thread list or is not a number
|
||||
print("{}".format(style_text("Invalid entry", "bold")))
|
||||
print("{}".format(style_text("Invalid entry", False, "bold")))
|
||||
|
||||
|
||||
def view_link_in_browser(url):
|
||||
|
@ -278,7 +278,7 @@ def get_input(item: str) -> str:
|
|||
"""Get user input with the specified prompt, validate and return it, or
|
||||
break if invalid"""
|
||||
while True:
|
||||
i: str = input("{}: ".format(style_text(item, "underline")))
|
||||
i: str = input("{}: ".format(style_text(item, True, "underline")))
|
||||
if i == "":
|
||||
raise ValueError("Empty field")
|
||||
if i == "?":
|
||||
|
@ -305,7 +305,7 @@ def post_link() -> int:
|
|||
print("\nPost a link by entering the details below.")
|
||||
print(
|
||||
"Enter {} for a list of categories. Enter an empty field to cancel.\n".format(
|
||||
style_text("?", "underline")
|
||||
style_text("?", False, "underline")
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -336,9 +336,9 @@ def menu_view_categories():
|
|||
|
||||
option = input(
|
||||
"Enter a category ID, {} to post a link, {} to search, or {} to quit: ".format(
|
||||
style_text("p", "underline"),
|
||||
style_text("s", "underline"),
|
||||
style_text("q", "underline"),
|
||||
style_text("p", True, "underline"),
|
||||
style_text("s", True, "underline"),
|
||||
style_text("q", True, "underline"),
|
||||
)
|
||||
).lower()
|
||||
|
||||
|
@ -369,10 +369,10 @@ def menu_view_category_details(cat_index):
|
|||
option = input(
|
||||
"Enter a post ID to see its thread, {} to go back, {} to "
|
||||
"search, {} to post a link, or {} to quit: ".format(
|
||||
style_text("m", "underline"),
|
||||
style_text("s", "underline"),
|
||||
style_text("p", "underline"),
|
||||
style_text("q", "underline"),
|
||||
style_text("m", True, "underline"),
|
||||
style_text("s", True, "underline"),
|
||||
style_text("p", True, "underline"),
|
||||
style_text("q", True, "underline"),
|
||||
)
|
||||
).lower()
|
||||
|
||||
|
@ -393,19 +393,19 @@ def menu_view_category_details(cat_index):
|
|||
menu_view_thread_details(post_id)
|
||||
except (KeyError, ValueError):
|
||||
# Catch a Post ID that is not in the thread list or is not a number
|
||||
print("{}\n\n".format(style_text("Invalid category ID/entry", "bold")))
|
||||
print("{}\n\n".format(style_text("Invalid category ID/entry", False, "bold")))
|
||||
|
||||
|
||||
def menu_view_thread_details(post_id):
|
||||
"""Displays thread details, handles related navigation menu"""
|
||||
option_text = "Type {} to reply, {} to view in {}, {} to search, {} to post a new link, {} to go back, or {} to quit: ".format(
|
||||
style_text("r", "underline"),
|
||||
style_text("b", "underline"),
|
||||
style_text("r", True, "underline"),
|
||||
style_text("b", True, "underline"),
|
||||
config.USER.browser,
|
||||
style_text("s", "underline"),
|
||||
style_text("p", "underline"),
|
||||
style_text("m", "underline"),
|
||||
style_text("q", "underline"),
|
||||
style_text("s", True, "underline"),
|
||||
style_text("p", True, "underline"),
|
||||
style_text("m", True, "underline"),
|
||||
style_text("q", True, "underline"),
|
||||
)
|
||||
|
||||
while True:
|
||||
|
@ -429,13 +429,13 @@ def menu_view_thread_details(post_id):
|
|||
break
|
||||
if option == "q":
|
||||
graceful_exit()
|
||||
print("{}\n\n".format(style_text("Invalid entry", "bold")))
|
||||
print("{}\n\n".format(style_text("Invalid entry", False, "bold")))
|
||||
|
||||
|
||||
## GENERAL
|
||||
|
||||
|
||||
def style_text(text: str, *args) -> str:
|
||||
def style_text(text: str, is_input: bool, *args) -> str:
|
||||
"""Style input strings as specified using terminal escape sequences. Returns a styled string"""
|
||||
styles = {
|
||||
"bold": "\033[1m",
|
||||
|
@ -444,15 +444,17 @@ def style_text(text: str, *args) -> str:
|
|||
"blink": "\033[5m", # This is here if you REALLY need it...dont use it.
|
||||
# (ctrl+shift+esc+E to enable evil mode.)
|
||||
"inverse": "\033[7m", # Make fg and bg color swap
|
||||
"rl_left_fix": "\001" if is_input else "",
|
||||
"rl_right_fix": "\002" if is_input else ""
|
||||
}
|
||||
out = ""
|
||||
for arg in args:
|
||||
if arg in styles:
|
||||
out += "\001"
|
||||
out += styles["rl_left_fix"]
|
||||
out += styles[arg]
|
||||
out += "\002"
|
||||
out += styles["rl_right_fix"]
|
||||
out += text
|
||||
out += "\001\033[0m\002"
|
||||
out += "{}\033[0m{}".format(styles["rl_left_fix"], styles["rl_right_fix"])
|
||||
return out
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue