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
|
||||
`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 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:
|
||||
|
||||
Reference in New Issue
Block a user