Skip to content

Commit 36e0c30

Browse files
committed
feat(command): open in terminal editor command in composing message
On OPEN_IN_TERMINAL_EDITOR command allow to edit the current message in terminal editor with python tempfile.
1 parent b81f30f commit 36e0c30

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/hotkeys.md

+1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@
9696
|Jump to the previous line|<kbd>up</kbd> / <kbd>ctrl</kbd> + <kbd>p</kbd>|
9797
|Jump to the next line|<kbd>down</kbd> / <kbd>ctrl</kbd> + <kbd>n</kbd>|
9898
|Clear compose box|<kbd>ctrl</kbd> + <kbd>l</kbd>|
99+
|Edit the current raw message in terminal editor ($EDITOR)|<kbd>ctrl</kbd> + <kbd>o</kbd>|
99100

zulipterminal/config/keys.py

+5
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ class KeyBinding(TypedDict):
385385
'help_text': 'Clear compose box',
386386
'key_category': 'msg_compose',
387387
},
388+
'OPEN_IN_TERMINAL_EDITOR': {
389+
'keys': ['ctrl o'],
390+
'help_text': 'Edit the current raw message in terminal editor ($EDITOR)',
391+
'key_category': 'msg_compose',
392+
},
388393
'FULL_RENDERED_MESSAGE': {
389394
'keys': ['f'],
390395
'help_text': 'Show/hide full rendered message (from message information)',

zulipterminal/ui_tools/boxes.py

+13
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44

55
import re
6+
import subprocess
67
import unicodedata
78
from collections import Counter
89
from datetime import datetime, timedelta
10+
from tempfile import NamedTemporaryFile
911
from time import sleep
1012
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple
1113

@@ -810,6 +812,17 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
810812
elif is_command_key("MARKDOWN_HELP", key):
811813
self.view.controller.show_markdown_help()
812814
return key
815+
elif is_command_key("OPEN_IN_TERMINAL_EDITOR", key):
816+
edit_tempfile = NamedTemporaryFile(suffix=".md")
817+
with open(edit_tempfile.name, mode="w") as edit_writer:
818+
edit_writer.write(self.msg_write_box.edit_text)
819+
self.view.controller.loop.screen.stop()
820+
subprocess.call([f"$EDITOR {edit_tempfile.name}"], shell=True)
821+
with open(edit_tempfile.name, mode="r") as edit_reader:
822+
self.msg_write_box.edit_text = edit_reader.read()
823+
edit_tempfile.close()
824+
self.view.controller.loop.screen.start()
825+
return key
813826
elif is_command_key("SAVE_AS_DRAFT", key):
814827
if self.msg_edit_state is None:
815828
if self.compose_box_status == "open_with_private":

0 commit comments

Comments
 (0)