Skip to content

Commit 0a2d18a

Browse files
committed
Report the correct EOF key
$ stty eof ^F $ ./main.py shell grommunio-admin shell. Type `exit` or press CTRL+D to exit. This should print CTRL+F.
1 parent 021a23c commit 0a2d18a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cli/misc.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from . import Cli, CliError, ArgumentParser
66
from .common import proptagCompleter
7+
import locale
8+
import termios
79

810

911
def _runParserSetup(subp: ArgumentParser):
@@ -135,6 +137,16 @@ def _loadHistory(args):
135137
.format(filePath, type(err).__name__ + " - ".join(str(arg) for arg in err.args)),
136138
attrs=["dark"]))
137139

140+
def eof_instructions(fd):
141+
try:
142+
key = termios.tcgetattr(fd)[6][termios.VEOF]
143+
if ord(key) == 0:
144+
return ""
145+
if ord(key) < 32:
146+
return " or press CTRL+" + chr(ord(key) + ord('@'))
147+
return " or press '" + key.decode(locale.getpreferredencoding()) + "'"
148+
except:
149+
return ""
138150

139151
@Cli.command("shell", _setupCliShell, help="Start interactive shell")
140152
def cliShell(args):
@@ -157,9 +169,9 @@ def rlEnable(state):
157169
if interactive:
158170
cli.print("\x1b]2;grommunio-admin\x07", end="")
159171
if cli.host is None:
160-
cli.print("grommunio-admin shell. Type exit or press CTRL+D to exit.")
172+
cli.print("grommunio-admin shell. Type `exit`" + eof_instructions(cli.stdin) + " to exit.")
161173
else:
162-
cli.print("Starting remote admin shell. Type exit or press CTRL+D to exit.")
174+
cli.print("Starting remote admin shell. Type `exit`" + eof_instructions(cli.stdin) + " to exit.")
163175
try:
164176
import readline
165177
readline.set_completer_delims("")

0 commit comments

Comments
 (0)