Skip to content

Commit

Permalink
Make toot post prompt for input if no text is given
Browse files Browse the repository at this point in the history
fixes #82
  • Loading branch information
ihabunek committed Jan 2, 2019
1 parent 62385ac commit 14a580b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog

* Enable interaction with instances using http instead of https (#56)
* Enable proxy usage via environment variables (#47)
* Make `toot post` prompt for input if no text is given (#82)

**0.19.0 (2018-06-27)**

Expand Down
6 changes: 5 additions & 1 deletion toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from toot.auth import login_interactive, login_browser_interactive, create_app_interactive
from toot.exceptions import ConsoleError, NotFoundError
from toot.output import print_out, print_instance, print_account, print_search_results, print_timeline
from toot.utils import assert_domain_exists
from toot.utils import assert_domain_exists, multiline_input, EOF_KEY


def timeline(app, user, args):
Expand Down Expand Up @@ -56,6 +56,10 @@ def post(app, user, args):
if media and not args.text:
args.text = media['text_url']

if not args.text:
print_out("Write or paste your toot. Press <yellow>{}</yellow> to post it.".format(EOF_KEY))
args.text = multiline_input()

if not args.text:
raise ConsoleError("You must specify either text or media to post.")

Expand Down
16 changes: 16 additions & 0 deletions toot/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os
import re
import socket
import unicodedata
Expand Down Expand Up @@ -68,3 +69,18 @@ def trunc(text, length):
return text

return text[:length - 1] + '…'


EOF_KEY = "Ctrl-Z" if os.name == 'nt' else "Ctrl-D"


def multiline_input():
"""Lets user input multiple lines of text, terminated by EOF."""
lines = []
while True:
try:
lines.append(input())
except EOFError:
break

return "\n".join(lines).strip()

0 comments on commit 14a580b

Please sign in to comment.