summaryrefslogtreecommitdiffstats
path: root/deluge/ui/console/main.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2021-07-24 14:11:58 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2021-08-01 08:48:27 +0100
commitb89b2c45b145c33c41115a9aac6e46b085ce668a (patch)
tree8c373cdb925284b6915061659efb2444bfa0b89c /deluge/ui/console/main.py
parente38f1173cf470f2f8373f2fa4edbb726c932c980 (diff)
downloaddeluge-b89b2c45b145c33c41115a9aac6e46b085ce668a.tar.gz
deluge-b89b2c45b145c33c41115a9aac6e46b085ce668a.tar.bz2
deluge-b89b2c45b145c33c41115a9aac6e46b085ce668a.zip
[Console] Fix using windows-curses on Windows
The console tests are still failing on Windows due to an issue where the sys args are not being correctly replaced in the tests so the pytest args are being passed to console.
Diffstat (limited to 'deluge/ui/console/main.py')
-rw-r--r--deluge/ui/console/main.py63
1 files changed, 34 insertions, 29 deletions
diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
index 23965bbb2..c74d9022f 100644
--- a/deluge/ui/console/main.py
+++ b/deluge/ui/console/main.py
@@ -67,6 +67,14 @@ DEFAULT_CONSOLE_PREFS = {
}
+class MockConsoleLog(object):
+ def write(self, data):
+ pass
+
+ def flush(self):
+ pass
+
+
class ConsoleUI(component.Component, TermResizeHandler):
def __init__(self, options, cmds, log_stream):
component.Component.__init__(self, 'ConsoleUI')
@@ -114,6 +122,7 @@ class ConsoleUI(component.Component, TermResizeHandler):
all commands are executed. Else None is returned.
"""
if self.options.parsed_cmds:
+ # Non-Interactive mode
self.interactive = False
if not self._commands:
print('No valid console commands found')
@@ -122,41 +131,37 @@ class ConsoleUI(component.Component, TermResizeHandler):
deferred = self.exec_args(self.options)
reactor.run()
return deferred
- else:
- # Interactive
- if deluge.common.windows_check():
- print(
- """\nDeluge-console does not run in interactive mode on Windows. \n
-Please use commands from the command line, e.g.:\n
- deluge-console.exe help
- deluge-console.exe info
- deluge-console.exe "add --help"
- deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent"
-"""
- )
- else:
- class ConsoleLog(object):
- def write(self, data):
- pass
+ # Interactive
- def flush(self):
- pass
+ # We use the curses.wrapper function to prevent the console from getting
+ # messed up if an uncaught exception is experienced.
+ try:
+ from curses import wrapper
+ except ImportError:
+ wrapper = None
- # We don't ever want log output to terminal when running in
- # interactive mode, so insert a dummy here
- self.log_stream.out = ConsoleLog()
+ if deluge.common.windows_check() and not wrapper:
+ print(
+ """\nDeluge-console does not run in interactive mode on Windows. \n
+Please use commands from the command line, e.g.:\n
+deluge-console.exe help
+deluge-console.exe info
+deluge-console.exe "add --help"
+deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent"
+"""
+ )
- # Set Esc key delay to 0 to avoid a very annoying delay
- # due to curses waiting in case of other key are pressed
- # after ESC is pressed
- os.environ.setdefault('ESCDELAY', '0')
+ # We don't ever want log output to terminal when running in
+ # interactive mode, so insert a dummy here
+ self.log_stream.out = MockConsoleLog()
- # We use the curses.wrapper function to prevent the console from getting
- # messed up if an uncaught exception is experienced.
- from curses import wrapper
+ # Set Esc key delay to 0 to avoid a very annoying delay
+ # due to curses waiting in case of other key are pressed
+ # after ESC is pressed
+ os.environ.setdefault('ESCDELAY', '0')
- wrapper(self.run)
+ wrapper(self.run)
def quit(self):
if client.connected():