From 29ea05f5bb332fdb9bd660e85877d96bc8b8104b Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sat, 4 Nov 2017 15:20:58 -0400 Subject: [PATCH] Adding support for emacs terminals --- rtv/page.py | 4 +++- tests/test_subreddit.py | 5 +++++ tests/test_terminal.py | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rtv/page.py b/rtv/page.py index 134774c..712cbd6 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -367,7 +367,9 @@ class Page(object): else: title = sub_name - if os.getenv('DISPLAY'): + # Setting the terminal title will break emacs or systems without + # X window. + if os.getenv('DISPLAY') and not os.getenv('INSIDE_EMACS'): title += ' - rtv {0}'.format(__version__) title = self.term.clean(title) if six.PY3: diff --git a/tests/test_subreddit.py b/tests/test_subreddit.py index 8d74ac9..f9f1352 100644 --- a/tests/test_subreddit.py +++ b/tests/test_subreddit.py @@ -108,6 +108,11 @@ def test_subreddit_title(subreddit_page, terminal, capsys): out, _ = capsys.readouterr() assert not out + with mock.patch.dict('os.environ', {'INSIDE_EMACS': '25.3.1,term:0.96'}): + subreddit_page.draw() + out, _ = capsys.readouterr() + assert not out + def test_subreddit_search(subreddit_page, terminal): window = terminal.stdscr.subwin diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 52950e7..935535b 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -600,6 +600,7 @@ def test_set_theme(terminal, stdscr): def test_set_theme_no_colors(terminal, stdscr): + # Monochrome should be forced if the terminal doesn't support color with mock.patch('curses.has_colors') as has_colors: has_colors.return_value = False