Add instructions to the comment file.
This commit is contained in:
14
rtv/docs.py
14
rtv/docs.py
@@ -43,3 +43,17 @@ Submission Mode
|
|||||||
`LEFT` or `h` : Return to subreddit mode
|
`LEFT` or `h` : Return to subreddit mode
|
||||||
`RIGHT` or `l` : Fold the selected comment, or load additional comments
|
`RIGHT` or `l` : Fold the selected comment, or load additional comments
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
COMMENT_FILE = """
|
||||||
|
--% {0} %--
|
||||||
|
Do not edit the line above.
|
||||||
|
Type your comment above the line.
|
||||||
|
All text below the line will be discarded.
|
||||||
|
|
||||||
|
If there is nothing but whitespace above the line
|
||||||
|
then the comment will be discarded.
|
||||||
|
|
||||||
|
Replying to {1}'s {2}
|
||||||
|
|
||||||
|
{3}
|
||||||
|
"""
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
import praw.errors
|
import praw.errors
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ from .page import BasePage
|
|||||||
from .helpers import clean, open_browser
|
from .helpers import clean, open_browser
|
||||||
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
||||||
show_help, show_notification, text_input)
|
show_help, show_notification, text_input)
|
||||||
|
from .docs import COMMENT_FILE
|
||||||
|
|
||||||
__all__ = ['SubmissionPage']
|
__all__ = ['SubmissionPage']
|
||||||
|
|
||||||
@@ -247,16 +249,27 @@ class SubmissionPage(BasePage):
|
|||||||
|
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
|
||||||
fd, filename = tempfile.mkstemp(prefix="rtv_comment-");
|
fd, filename = tempfile.mkstemp(prefix="rtv-comment-", suffix=".txt")
|
||||||
os.system('%s %s' % (os.getenv('EDITOR'), filename))
|
cid = str(uuid.uuid4())
|
||||||
|
try:
|
||||||
|
with open(filename, 'w') as comment_file:
|
||||||
|
if data['type'] == 'Submission':
|
||||||
|
info = (data['author'], 'submission', data['text'])
|
||||||
|
else:
|
||||||
|
info = (data['author'], 'comment', data['body'])
|
||||||
|
|
||||||
with os.fdopen(fd, 'r') as comment_file:
|
comment_info = COMMENT_FILE.format(cid, *info)
|
||||||
comment_text = comment_file.read()
|
comment_file.write(comment_info)
|
||||||
|
|
||||||
curses.doupdate()
|
os.system('%s %s' % (os.getenv('EDITOR'), filename))
|
||||||
|
with open(filename, 'r') as comment_file:
|
||||||
|
comment_text = (comment_file.read()
|
||||||
|
.split('--% ' + cid + ' %--'))[0]
|
||||||
|
finally:
|
||||||
|
os.remove(filename)
|
||||||
|
curses.doupdate()
|
||||||
|
|
||||||
|
if comment_text is None or comment_text.isspace():
|
||||||
if comment_text is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user