Merge branch 'dev'
This commit is contained in:
@@ -5,7 +5,7 @@ Contributor Guidelines
|
||||
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
|
||||
|
||||
Considerations
|
||||
|
||||
5
rtv.1
5
rtv.1
@@ -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
|
||||
RTV - Reddit Terminal Viewer
|
||||
.SH SYNOPSIS
|
||||
@@ -113,7 +113,8 @@ program to be installed.
|
||||
Web browser to use when opening links. Will fallback to \fI$BROWSER\fR.
|
||||
.SH AUTHOR
|
||||
Michael Lazar <lazar.michael22@gmail.com> (2017).
|
||||
John Helmert <jchelmertt3@gmail.com> (2019).
|
||||
.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
|
||||
The MIT License (MIT)
|
||||
|
||||
@@ -264,7 +264,7 @@ def main():
|
||||
debug_text,
|
||||
traceback.format_exc(),
|
||||
'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)
|
||||
return 1 # General error exception code
|
||||
except KeyboardInterrupt:
|
||||
|
||||
@@ -4,48 +4,22 @@ from __future__ import unicode_literals
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
from .exceptions import ProgramError
|
||||
|
||||
|
||||
def _subprocess_copy(text, args_list):
|
||||
p = subprocess.Popen(args_list, stdin=subprocess.PIPE, close_fds=True)
|
||||
p.communicate(input=text.encode('utf-8'))
|
||||
|
||||
|
||||
def copy(text):
|
||||
def copy(text, cmd):
|
||||
"""
|
||||
Copy text to OS clipboard.
|
||||
"""
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
copy_osx(text)
|
||||
else:
|
||||
# For Linux, BSD, cygwin, etc.
|
||||
copy_linux(text)
|
||||
# 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':
|
||||
cmd = 'pbcopy w'
|
||||
else: # For Linux, BSD, cygwin, etc.
|
||||
cmd = 'xclip'
|
||||
|
||||
|
||||
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))
|
||||
_subprocess_copy(text, cmd.split())
|
||||
|
||||
@@ -250,7 +250,7 @@ class Config(object):
|
||||
config = configparser.ConfigParser()
|
||||
if os.path.exists(filename):
|
||||
with codecs.open(filename, encoding='utf-8') as fp:
|
||||
config.readfp(fp)
|
||||
config.read_file(fp)
|
||||
|
||||
return cls._parse_rtv_file(config)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
AGENT = """\
|
||||
desktop:https://github.com/michael-lazar/rtv:{version}\
|
||||
desktop:https://github.com/ajak/rtv:{version}\
|
||||
(by /u/civilization_phaze_3)\
|
||||
"""
|
||||
|
||||
@@ -26,7 +26,7 @@ HELP = """\
|
||||
====================================
|
||||
Reddit Terminal Viewer
|
||||
|
||||
https://github.com/michael-lazar/rtv
|
||||
https://github.com/ajak/rtv
|
||||
====================================
|
||||
|
||||
[Basic Commands]
|
||||
|
||||
@@ -236,6 +236,12 @@ class Page(object):
|
||||
"""
|
||||
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.cursor_index = 0
|
||||
self.nav.inverted = True
|
||||
@@ -536,7 +542,7 @@ class Page(object):
|
||||
return
|
||||
|
||||
try:
|
||||
clipboard_copy(url)
|
||||
clipboard_copy(url, self.config['clipboard_cmd'])
|
||||
except (ProgramError, OSError) as e:
|
||||
_logger.exception(e)
|
||||
self.term.show_notification(
|
||||
|
||||
@@ -26,6 +26,6 @@
|
||||
</head>
|
||||
<body>
|
||||
${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>
|
||||
</html>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# Then launch RTV using the --enable-media flag. All shell commands defined in
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
; 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
|
||||
; If $XDG_CONFIG is not set, use ~/.config/rtv/rtv.cfg
|
||||
@@ -16,6 +16,12 @@ ascii = False
|
||||
; Turn on monochrome mode to disable color.
|
||||
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 = True
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ class Theme(object):
|
||||
config = configparser.ConfigParser()
|
||||
config.optionxform = six.text_type # Preserve case
|
||||
with codecs.open(filename, encoding='utf-8') as fp:
|
||||
config.readfp(fp)
|
||||
config.read_file(fp)
|
||||
except configparser.ParsingError as e:
|
||||
raise ConfigError(e.message)
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ program to be installed.
|
||||
Web browser to use when opening links. Will fallback to \fI$BROWSER\fR.
|
||||
.SH AUTHOR
|
||||
Michael Lazar <lazar.michael22@gmail.com> (2017).
|
||||
John Helmert <jchelmertt3@gmail.com> (2019).
|
||||
.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
|
||||
{license}
|
||||
|
||||
6
setup.py
6
setup.py
@@ -49,9 +49,9 @@ setuptools.setup(
|
||||
description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)',
|
||||
long_description=long_description(),
|
||||
long_description_content_type='text/markdown',
|
||||
url='https://github.com/michael-lazar/rtv',
|
||||
author='Michael Lazar',
|
||||
author_email='lazar.michael22@gmail.com',
|
||||
url='https://gitlab.com/ajak/rtv',
|
||||
author='John Helmert III',
|
||||
author_email='jchelmertt3@gmail.com',
|
||||
license='MIT',
|
||||
keywords='reddit terminal praw curses',
|
||||
packages=[
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from rtv.clipboard import copy_linux, copy_osx
|
||||
from rtv.clipboard import copy
|
||||
from rtv.exceptions import ProgramError
|
||||
|
||||
|
||||
@@ -23,20 +23,13 @@ def test_copy():
|
||||
p.communicate = mock.Mock()
|
||||
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
|
||||
copy_linux('test')
|
||||
copy('test', 'xsel -b -i')
|
||||
assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
|
||||
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'))
|
||||
|
||||
copy_osx('test')
|
||||
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'))
|
||||
# Need OSX tests, can't simulate sys.platform
|
||||
|
||||
@@ -738,7 +738,7 @@ def test_terminal_get_link_page_text(terminal):
|
||||
{'href': 'https://www.reddit.com', 'text': 'Reddit Homepage'},
|
||||
{'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'
|
||||
}
|
||||
]
|
||||
@@ -747,7 +747,7 @@ def test_terminal_get_link_page_text(terminal):
|
||||
assert text == dedent("""\
|
||||
[0] [Reddit Homepage](https://www.reddit.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)
|
||||
""")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user