diff --git a/README.md b/README.md index 9dd532c..2544b62 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ A simple line-oriented text editor and page-oriented text viewer for MicroPython Exports the following functions: - `edit(filename)`: start an `ed`-like text editor (see below) +- `edbuf()`: create an empty buffer, run the editor interface on it and return the result as a string (without creating any files) - `view(filename, lno=False)`: start a `more`-like pager for viewing a text file (pass an additional parameter to view it with line numbers) The editor mode supports the following subset of POSIX ed commands in the standard `[range][command][param]` syntax: @@ -261,8 +262,9 @@ Requires the following environment variables to be configured (for T-Deck, use t Exports the following functions: -- `blogpost()`: wait for a (multiline) input and send the post, -- `blogpost_str(content)`: post the content in a non-interactive manner. +- `blogpost()`: wait for a (multiline) input and send the post +- `bloged()`: same as `blogpost()` but with a full-featured `app.ed` interface +- `blogpost_str(content)`: post the content in a non-interactive manner ## FAQ diff --git a/app/blog.py b/app/blog.py index 25828d0..62fdf22 100644 --- a/app/blog.py +++ b/app/blog.py @@ -36,3 +36,7 @@ def blogpost(content=None): content = input_multi('> ') print('Sending the post...') return blogpost_str(content) + +def bloged(): + from app.ed import edbuf + return blogpost(edbuf()) diff --git a/app/ed.py b/app/ed.py index c01dfac..b389991 100644 --- a/app/ed.py +++ b/app/ed.py @@ -201,6 +201,11 @@ def edit(fname): editor = Ed(fname) editor.run() +def edbuf(): + editor = Ed() + editor.run() + return '\n'.join(editor.buffer) + def view(fname, lno=False): try: with open(fname, 'r') as f: diff --git a/tdeckboot.py b/tdeckboot.py index 6f6e460..6628a95 100644 --- a/tdeckboot.py +++ b/tdeckboot.py @@ -12,8 +12,8 @@ from deck.hwinfo import board_id, battery_v, cpu_f, REAL_HW from deck.http import wget, wput, http_fetch, http_set_ua from deck.http import auth_header, url_escape, form_encode from deck import xlat -from app.ed import edit, view -from app.blog import blogpost, blogpost_str +from app.ed import edit, view, edbuf +from app.blog import blogpost, blogpost_str, bloged try: from deck import net requests = net.init_requests()