From 7d5bb8e016a8cb09516a3878a2dc4c2978416aba Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 16 Sep 2021 19:54:32 +0200 Subject: [PATCH] User interface enhancements --- nomadnet/NomadNetworkApp.py | 16 ++++++++- nomadnet/ui/TextUI.py | 51 ++++++++++++++++++----------- nomadnet/ui/textui/Browser.py | 5 +-- nomadnet/ui/textui/Conversations.py | 4 +-- nomadnet/ui/textui/Network.py | 8 ++--- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index acaecc4..79597ae 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -58,6 +58,8 @@ class NomadNetworkApp: self.firstrun = False + self.peer_announce_at_start = True + if not os.path.isdir(self.storagepath): os.makedirs(self.storagepath) @@ -170,6 +172,9 @@ class NomadNetworkApp: RNS.Transport.register_announce_handler(nomadnet.Conversation) RNS.Transport.register_announce_handler(nomadnet.Directory) + if self.peer_announce_at_start: + self.announce_now() + nomadnet.ui.spawn(self.uimode) def set_display_name(self, display_name): @@ -262,6 +267,10 @@ class NomadNetworkApp: value = self.config["client"]["downloads_path"] self.downloads_path = os.path.expanduser(value) + if option == "announce_at_start": + value = self.config["client"].as_bool(option) + self.peer_announce_at_start = value + if option == "user_interface": value = value.lower() if value == "none": @@ -347,7 +356,8 @@ class NomadNetworkApp: if not "announce_at_start" in self.config["node"]: self.node_announce_at_start = False else: - self.node_announce_at_start = self.config["node"]["announce_at_start"] + value = self.config["node"].as_bool("announce_at_start") + self.node_announce_at_start = value if not "announce_interval" in self.config["node"]: self.node_announce_interval = 720 @@ -401,6 +411,10 @@ enable_client = yes user_interface = text downloads_path = ~/Downloads +# By default, the peer is announced at startup +# to let other peers reach it immediately. +announce_at_start = yes + [textui] # Amount of time to show intro screen diff --git a/nomadnet/ui/TextUI.py b/nomadnet/ui/TextUI.py index b53ddf9..9e8f4db 100644 --- a/nomadnet/ui/TextUI.py +++ b/nomadnet/ui/TextUI.py @@ -1,6 +1,7 @@ import RNS -import importlib +import urwid import time +import os import nomadnet from nomadnet.ui.textui import * @@ -61,21 +62,22 @@ GLYPHS = { ("check", "=", "\u2713", "\u2713"), ("cross", "X", "\u2715", "\u2715"), ("unknown", "?", "?", "?"), - ("lock", "E", "\U0001f512", "\uf023"), - ("unlock", "!", "\U0001f513", "\uf09c"), + ("encrypted", "", "\u26BF", "\uf023"), + ("plaintext", "!", "!", "\uf06e "), ("arrow_r", "->", "\u2192", "\u2192"), ("arrow_l", "<-", "\u2190", "\u2190"), ("arrow_u", "/\\", "\u2191", "\u2191"), ("arrow_d", "\\/", "\u2193", "\u2193"), ("warning", "!", "\u26a0", "\uf12a"), ("info", "i", "\u2139", "\ufb4d"), - ("unread", "N", "\u2709", "\uf003 "), + ("unread", "[U]", "\u2709", "\uf003 "), ("divider1", "-", "\u2504", "\u2504"), - ("peer", "P", "\U0001F464", "\uf415"), - ("node", "N", "\U0001F5A5", "\uf502"), - ("page", "", "\U0001F5B9", "\uf719 "), - ("speed", "", "\U0001F5B9", "\uf9c4"), + ("peer", "[P]", "\u24c5 ", "\uf415"), + ("node", "[N]", "\u24c3 ", "\uf502"), + ("page", "", "\u25a4", "\uf719 "), + ("speed", "", "\u25F7", "\uf9c4"), ("decoration_menu", "", "", " \uf93a"), + ("globe", "", "", "\uf484"), } class TextUI: @@ -85,12 +87,13 @@ class TextUI: self.app.ui = self self.loop = None - if importlib.util.find_spec("urwid") != None: - import urwid - else: - RNS.log("The text-mode user interface requires Urwid to be installed on your system.", RNS.LOG_ERROR) - RNS.log("You can install it with the command: pip3 install urwid", RNS.LOG_ERROR) - nomadnet.panic() + # TODO: Remove + # if importlib.util.find_spec("urwid") != None: + # import urwid + # else: + # RNS.log("The text-mode user interface requires Urwid to be installed on your system.", RNS.LOG_ERROR) + # RNS.log("You can install it with the command: pip3 install urwid", RNS.LOG_ERROR) + # nomadnet.panic() urwid.set_encoding("UTF-8") @@ -130,11 +133,21 @@ class TextUI: if intro_timeout > 0: self.loop.set_alarm_in(intro_timeout, self.display_main) - # TODO: Probably remove this at some point when better terminal - # color capability detection has been implemented - if colormode > 16: - RNS.log("Starting Text UI in "+str(colormode)+" color mode. If no UI appears, try adjusting your color settings in "+str(self.app.configdir)+"/config", RNS.LOG_INFO, _override_destination = True) - + if "KONSOLE_VERSION" in os.environ: + if colormode > 16: + RNS.log("", RNS.LOG_WARNING, _override_destination = True) + RNS.log("", RNS.LOG_WARNING, _override_destination = True) + RNS.log("You are using the terminal emulator Konsole.", RNS.LOG_WARNING, _override_destination = True) + RNS.log("If you are not seeing the user interface, it is due to a bug in Konsole/urwid.", RNS.LOG_WARNING, _override_destination = True) + RNS.log("", RNS.LOG_WARNING, _override_destination = True) + + RNS.log("To circumvent this, use another terminal emulator, or launch nomadnet within a", RNS.LOG_WARNING, _override_destination = True) + RNS.log("screen session, using a command like the following:", RNS.LOG_WARNING, _override_destination = True) + RNS.log("", RNS.LOG_WARNING, _override_destination = True) + RNS.log("screen nomadnet", RNS.LOG_WARNING, _override_destination = True) + RNS.log("", RNS.LOG_WARNING, _override_destination = True) + RNS.log("Press ctrl-c to exit now and try again.", RNS.LOG_WARNING, _override_destination = True) + self.set_colormode(colormode) self.loop.run() diff --git a/nomadnet/ui/textui/Browser.py b/nomadnet/ui/textui/Browser.py index 2fdb5b9..2d157d6 100644 --- a/nomadnet/ui/textui/Browser.py +++ b/nomadnet/ui/textui/Browser.py @@ -84,8 +84,9 @@ class Browser: def marked_link(self, link_target): - self.link_target = link_target - self.app.ui.loop.set_alarm_in(0.1, self.marked_link_job) + if self.status == Browser.DONE: + self.link_target = link_target + self.app.ui.loop.set_alarm_in(0.1, self.marked_link_job) def marked_link_job(self, sender, event): link_target = self.link_target diff --git a/nomadnet/ui/textui/Conversations.py b/nomadnet/ui/textui/Conversations.py index 2b4165d..b99cec3 100644 --- a/nomadnet/ui/textui/Conversations.py +++ b/nomadnet/ui/textui/Conversations.py @@ -702,9 +702,9 @@ class LXMessageWidget(urwid.WidgetWrap): message_time = datetime.fromtimestamp(self.timestamp) encryption_string = "" if message.get_transport_encrypted(): - encryption_string = " ["+g["lock"]+" "+str(message.get_transport_encryption())+"]" + encryption_string = " ["+g["encrypted"]+" "+str(message.get_transport_encryption())+"]" else: - encryption_string = " ["+g["unlock"]+" "+str(message.get_transport_encryption())+"]" + encryption_string = " ["+g["plaintext"]+" "+str(message.get_transport_encryption())+"]" title_string = message_time.strftime(time_format)+encryption_string diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py index 5dd965c..e6b0694 100644 --- a/nomadnet/ui/textui/Network.py +++ b/nomadnet/ui/textui/Network.py @@ -67,9 +67,9 @@ class AnnounceInfo(urwid.WidgetWrap): is_node = announce[3] if is_node: - type_string = g["node"] + " Node" + type_string = "Node " + g["node"] else: - type_string = g["peer"] + " Peer" + type_string = "Peer " + g["peer"] try: data_str = announce[2].decode("utf-8") @@ -461,8 +461,6 @@ class KnownNodes(urwid.WidgetWrap): # TODO: Sort list return widget_list - - class NodeEntry(urwid.WidgetWrap): def __init__(self, app, node, delegate): source_hash = node.source_hash @@ -712,8 +710,6 @@ class NetworkStats(urwid.WidgetWrap): self.w_heard_peers.start() self.w_known_nodes.start() - - class NetworkLeftPile(urwid.Pile): def keypress(self, size, key): if key == "ctrl l":