Add instructions to the comment file.

This commit is contained in:
noah morrison
2015-03-23 18:59:08 -04:00
parent 96a9b34a26
commit 08c78c54ec
2 changed files with 34 additions and 7 deletions

View File

@@ -43,3 +43,17 @@ Submission Mode
`LEFT` or `h` : Return to subreddit mode
`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}
"""

View File

@@ -3,6 +3,7 @@ import sys
import time
import tempfile
import os
import uuid
import praw.errors
@@ -11,6 +12,7 @@ from .page import BasePage
from .helpers import clean, open_browser
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
show_help, show_notification, text_input)
from .docs import COMMENT_FILE
__all__ = ['SubmissionPage']
@@ -247,16 +249,27 @@ class SubmissionPage(BasePage):
curses.endwin()
fd, filename = tempfile.mkstemp(prefix="rtv_comment-");
fd, filename = tempfile.mkstemp(prefix="rtv-comment-", suffix=".txt")
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'])
comment_info = COMMENT_FILE.format(cid, *info)
comment_file.write(comment_info)
os.system('%s %s' % (os.getenv('EDITOR'), filename))
with os.fdopen(fd, 'r') as comment_file:
comment_text = comment_file.read()
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:
if comment_text is None or comment_text.isspace():
return
try: