Add -n option to prevent the output of a newline

pull/121/head
Chris LaRose 5 years ago
parent 98f7f48e04
commit e49c391f4a

@ -276,6 +276,9 @@ def parse_args(argv):
parser.add_argument('-l',
action = 'store_true',
help = 'Change to previous window via ":wincmd p".')
parser.add_argument('-n',
action = 'store_true',
help = 'Do not include a trailing newline when printing the output from --remote-expr')
parser.add_argument('-o',
nargs = '+',
metavar = '<file>',
@ -465,7 +468,10 @@ def main(argv=sys.argv, env=os.environ):
elif type(result) is dict:
print({ (k.decode() if type(k) is bytes else k): v for (k,v) in result.items() })
else:
print(result)
end = '\n'
if options.n:
end = ''
print(result, end=end)
if options.o:
if options.d and not nvr.started_new_process:

@ -67,3 +67,21 @@ def test_escape_double_quotes_in_filenames(capsys):
nvim.terminate()
out, err = capsys.readouterr()
assert filename == out.rstrip()
def test_newline_printed_by_default(capsys):
env = setup_env()
nvim = run_nvim(env)
cmd = ['nvr', '--nostart', '--remote-expr', '"hello"']
run_nvr([cmd], env)
nvim.terminate()
out, err = capsys.readouterr()
assert out == 'hello\n'
def test_newline_not_printed_when_disabled(capsys):
env = setup_env()
nvim = run_nvim(env)
cmd = ['nvr', '--nostart', '-n', '--remote-expr', '"hello"']
run_nvr([cmd], env)
nvim.terminate()
out, err = capsys.readouterr()
assert out == 'hello'

Loading…
Cancel
Save