Merge branch 'dev'

This commit is contained in:
John Helmert
2019-06-09 12:31:17 -05:00
15 changed files with 47 additions and 66 deletions

View File

@@ -5,7 +5,7 @@ Contributor Guidelines
Before you start Before you start
================ ================
- Post an issue on the `tracker <https://github.com/michael-lazar/rtv/issues>`_ describing the bug or feature you would like to add - Post an issue on the `tracker <https://gitlab.com/ajak/rtv/issues>`_ describing the bug or feature you would like to add
- If an issue already exists, leave a comment to let others know that you intend to work on it - If an issue already exists, leave a comment to let others know that you intend to work on it
Considerations Considerations

5
rtv.1
View File

@@ -1,4 +1,4 @@
.TH "RTV" "1" "June 03, 2019" "Version 1.27.0" "Usage and Commands" .TH "RTV" "1" "June 08, 2019" "Version 1.27.0" "Usage and Commands"
.SH NAME .SH NAME
RTV - Reddit Terminal Viewer RTV - Reddit Terminal Viewer
.SH SYNOPSIS .SH SYNOPSIS
@@ -113,7 +113,8 @@ program to be installed.
Web browser to use when opening links. Will fallback to \fI$BROWSER\fR. Web browser to use when opening links. Will fallback to \fI$BROWSER\fR.
.SH AUTHOR .SH AUTHOR
Michael Lazar <lazar.michael22@gmail.com> (2017). Michael Lazar <lazar.michael22@gmail.com> (2017).
John Helmert <jchelmertt3@gmail.com> (2019).
.SH BUGS .SH BUGS
Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR Report bugs to \fIhttps://gitlab.com/ajak/rtv/issues\fR
.SH LICENSE .SH LICENSE
The MIT License (MIT) The MIT License (MIT)

View File

@@ -264,7 +264,7 @@ def main():
debug_text, debug_text,
traceback.format_exc(), traceback.format_exc(),
'rtv has crashed. Please report this traceback at:', 'rtv has crashed. Please report this traceback at:',
'https://github.com/michael-lazar/rtv/issues\n']) 'https://gitlab.com/ajak/rtv/issues\n'])
sys.stderr.write(exit_message) sys.stderr.write(exit_message)
return 1 # General error exception code return 1 # General error exception code
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@@ -4,48 +4,22 @@ from __future__ import unicode_literals
import sys import sys
import subprocess import subprocess
from .exceptions import ProgramError
def _subprocess_copy(text, args_list): def _subprocess_copy(text, args_list):
p = subprocess.Popen(args_list, stdin=subprocess.PIPE, close_fds=True) p = subprocess.Popen(args_list, stdin=subprocess.PIPE, close_fds=True)
p.communicate(input=text.encode('utf-8')) p.communicate(input=text.encode('utf-8'))
def copy(text): def copy(text, cmd):
""" """
Copy text to OS clipboard. Copy text to OS clipboard.
""" """
# If no command is specified (i.e. the config option is empty) try
# to find a reasonable default based on the operating system
if cmd is None:
if sys.platform == 'darwin': if sys.platform == 'darwin':
copy_osx(text) cmd = 'pbcopy w'
else: else: # For Linux, BSD, cygwin, etc.
# For Linux, BSD, cygwin, etc. cmd = 'xclip'
copy_linux(text)
_subprocess_copy(text, cmd.split())
def copy_osx(text):
_subprocess_copy(text, ['pbcopy', 'w'])
def copy_linux(text):
def get_command_name():
# Checks for the installation of xsel or xclip
for cmd in ['xsel', 'xclip']:
cmd_exists = subprocess.call(
['which', cmd],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
if cmd_exists:
return cmd
return None
cmd_args = {
'xsel': ['xsel', '-b', '-i'],
'xclip': ['xclip', '-selection', 'c']}
cmd_name = get_command_name()
if cmd_name is None:
raise ProgramError("External copy application not found")
_subprocess_copy(text, cmd_args.get(cmd_name))

View File

@@ -250,7 +250,7 @@ class Config(object):
config = configparser.ConfigParser() config = configparser.ConfigParser()
if os.path.exists(filename): if os.path.exists(filename):
with codecs.open(filename, encoding='utf-8') as fp: with codecs.open(filename, encoding='utf-8') as fp:
config.readfp(fp) config.read_file(fp)
return cls._parse_rtv_file(config) return cls._parse_rtv_file(config)

View File

@@ -2,7 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
AGENT = """\ AGENT = """\
desktop:https://github.com/michael-lazar/rtv:{version}\ desktop:https://github.com/ajak/rtv:{version}\
(by /u/civilization_phaze_3)\ (by /u/civilization_phaze_3)\
""" """
@@ -26,7 +26,7 @@ HELP = """\
==================================== ====================================
Reddit Terminal Viewer Reddit Terminal Viewer
https://github.com/michael-lazar/rtv https://github.com/ajak/rtv
==================================== ====================================
[Basic Commands] [Basic Commands]

View File

@@ -236,6 +236,12 @@ class Page(object):
""" """
Move the cursor to the last item on the page. Move the cursor to the last item on the page.
""" """
# If the page is empty, don't try to go to the bottom, rtv will
# crash when rendering
if self.content.range[1] < 0:
return
self.nav.page_index = self.content.range[1] self.nav.page_index = self.content.range[1]
self.nav.cursor_index = 0 self.nav.cursor_index = 0
self.nav.inverted = True self.nav.inverted = True
@@ -536,7 +542,7 @@ class Page(object):
return return
try: try:
clipboard_copy(url) clipboard_copy(url, self.config['clipboard_cmd'])
except (ProgramError, OSError) as e: except (ProgramError, OSError) as e:
_logger.exception(e) _logger.exception(e)
self.term.show_notification( self.term.show_notification(

View File

@@ -26,6 +26,6 @@
</head> </head>
<body> <body>
${message} ${message}
<div id="footer">View the <a href="http://www.github.com/michael-lazar/rtv">Documentation</a></div> <div id="footer">View the <a href="http://www.gitlab.com/ajak/rtv">Documentation</a></div>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,5 @@
# Example mailcap file for Reddit Terminal Viewer # Example mailcap file for Reddit Terminal Viewer
# https://github.com/michael-lazar/rtv/ # https://gitlab.com/ajak/rtv/
# #
# Copy the contents of this file to {HOME}/.mailcap, or point to it using $MAILCAPS # Copy the contents of this file to {HOME}/.mailcap, or point to it using $MAILCAPS
# Then launch RTV using the --enable-media flag. All shell commands defined in # Then launch RTV using the --enable-media flag. All shell commands defined in

View File

@@ -1,5 +1,5 @@
; Reddit Terminal Viewer Configuration File ; Reddit Terminal Viewer Configuration File
; https://github.com/michael-lazar/rtv ; https://gitlab.com/ajak/rtv
; ;
; This file should be placed in $XDG_CONFIG/rtv/rtv.cfg ; This file should be placed in $XDG_CONFIG/rtv/rtv.cfg
; If $XDG_CONFIG is not set, use ~/.config/rtv/rtv.cfg ; If $XDG_CONFIG is not set, use ~/.config/rtv/rtv.cfg
@@ -16,6 +16,12 @@ ascii = False
; Turn on monochrome mode to disable color. ; Turn on monochrome mode to disable color.
monochrome = False monochrome = False
; Data being copied is piped into this command
;clipboard_cmd = xclip
;clipboard_cmd = xsel -b -i
;clipboard_cmd = wl-copy
;clipboard_cmd = pbcopy w
; Flash when an invalid action is executed. ; Flash when an invalid action is executed.
flash = True flash = True

View File

@@ -399,7 +399,7 @@ class Theme(object):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.optionxform = six.text_type # Preserve case config.optionxform = six.text_type # Preserve case
with codecs.open(filename, encoding='utf-8') as fp: with codecs.open(filename, encoding='utf-8') as fp:
config.readfp(fp) config.read_file(fp)
except configparser.ParsingError as e: except configparser.ParsingError as e:
raise ConfigError(e.message) raise ConfigError(e.message)

View File

@@ -41,7 +41,8 @@ program to be installed.
Web browser to use when opening links. Will fallback to \fI$BROWSER\fR. Web browser to use when opening links. Will fallback to \fI$BROWSER\fR.
.SH AUTHOR .SH AUTHOR
Michael Lazar <lazar.michael22@gmail.com> (2017). Michael Lazar <lazar.michael22@gmail.com> (2017).
John Helmert <jchelmertt3@gmail.com> (2019).
.SH BUGS .SH BUGS
Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR Report bugs to \fIhttps://gitlab.com/ajak/rtv/issues\fR
.SH LICENSE .SH LICENSE
{license} {license}

View File

@@ -49,9 +49,9 @@ setuptools.setup(
description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)', description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)',
long_description=long_description(), long_description=long_description(),
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
url='https://github.com/michael-lazar/rtv', url='https://gitlab.com/ajak/rtv',
author='Michael Lazar', author='John Helmert III',
author_email='lazar.michael22@gmail.com', author_email='jchelmertt3@gmail.com',
license='MIT', license='MIT',
keywords='reddit terminal praw curses', keywords='reddit terminal praw curses',
packages=[ packages=[

View File

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import pytest import pytest
from rtv.clipboard import copy_linux, copy_osx from rtv.clipboard import copy
from rtv.exceptions import ProgramError from rtv.exceptions import ProgramError
@@ -23,20 +23,13 @@ def test_copy():
p.communicate = mock.Mock() p.communicate = mock.Mock()
Popen.return_value = p Popen.return_value = p
# If the `which` command can't find a program to use
call.return_value = 1 # Returns an error code
with pytest.raises(ProgramError):
copy_linux('test')
call.return_value = 0 call.return_value = 0
copy_linux('test') copy('test', 'xsel -b -i')
assert Popen.call_args[0][0] == ['xsel', '-b', '-i'] assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
p.communicate.assert_called_with(input='test'.encode('utf-8')) p.communicate.assert_called_with(input='test'.encode('utf-8'))
copy_linux('test ❤')
copy('test ❤', 'xclip')
assert Popen.call_args[0][0] == ['xclip']
p.communicate.assert_called_with(input='test ❤'.encode('utf-8')) p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
copy_osx('test') # Need OSX tests, can't simulate sys.platform
assert Popen.call_args[0][0] == ['pbcopy', 'w']
p.communicate.assert_called_with(input='test'.encode('utf-8'))
copy_osx('test ❤')
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))

View File

@@ -738,7 +738,7 @@ def test_terminal_get_link_page_text(terminal):
{'href': 'https://www.reddit.com', 'text': 'Reddit Homepage'}, {'href': 'https://www.reddit.com', 'text': 'Reddit Homepage'},
{'href': 'https://www.duckduckgo.com', 'text': 'Search Engine'}, {'href': 'https://www.duckduckgo.com', 'text': 'Search Engine'},
{ {
'href': 'https://github.com/michael-lazar/rtv', 'href': 'https://gitlab.com/ajak/rtv',
'text': 'This project\'s homepage' 'text': 'This project\'s homepage'
} }
] ]
@@ -747,7 +747,7 @@ def test_terminal_get_link_page_text(terminal):
assert text == dedent("""\ assert text == dedent("""\
[0] [Reddit Homepage](https://www.reddit.com) [0] [Reddit Homepage](https://www.reddit.com)
[1] [Search Engine](https://www.duckduckgo.com) [1] [Search Engine](https://www.duckduckgo.com)
[2] [This project's home…](https://github.com/michael-lazar/rtv) [2] [This project's home…](https://gitlab.com/ajak/rtv)
""") """)