choose-files kitten: Output a trailing newline when writing to a tty in text format

Fixes #9982
This commit is contained in:
Kovid Goyal 2026-05-07 08:53:09 +05:30
parent fc8a41c93e
commit 5de8734ce3
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 7 deletions

View file

@ -262,6 +262,8 @@ Detailed list of changes
- Linux: Workaround bug in Nvidia drivers that caused color corruption when resuming after suspend (:iss:`9844`) - Linux: Workaround bug in Nvidia drivers that caused color corruption when resuming after suspend (:iss:`9844`)
- choose-files kitten: Output a trailing newline when writing to a tty in text format (:iss:`9982`)
0.46.2 [2026-03-21] 0.46.2 [2026-03-21]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -903,6 +903,10 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
m = string(b) m = string(b)
} }
os.Stdout.Write(utils.UnsafeStringToBytes(m)) os.Stdout.Write(utils.UnsafeStringToBytes(m))
if tty.IsTerminal(os.Stdout.Fd()) && opts.OutputFormat == "text" {
// Avoid zsh's silly no trailing newline marker
os.Stdout.WriteString("\n")
}
if opts.WriteOutputTo != "" { if opts.WriteOutputTo != "" {
os.WriteFile(opts.WriteOutputTo, utils.UnsafeStringToBytes(m), 0600) os.WriteFile(opts.WriteOutputTo, utils.UnsafeStringToBytes(m), 0600)
} }

View file

@ -211,7 +211,7 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int,
usage = '[directory to start choosing files in]' usage = '[directory to start choosing files in]'
OPTIONS = ''' OPTIONS = """
--mode --mode
type=choices type=choices
choices=file,files,save-file,dir,save-dir,dirs,save-files choices=file,files,save-file,dir,save-dir,dirs,save-files
@ -266,11 +266,12 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int,
--output-format --output-format
choices=text,json,shell,shell-relative choices=text,json,shell,shell-relative
default=text default=text
The format in which to write the output. The :code:`text` format is absolute paths separated by newlines. The format in which to write the output. The :code:`text` format is absolute paths separated by newlines,
The :code:`shell` format is quoted absolute paths separated by spaces, quoting is done only if needed. The with a trailing newline. The :code:`shell` format is quoted absolute paths separated by spaces,
:code:`shell-relative` format is the same as :code:`shell` except it returns paths relative to the starting quoting is done only if needed. The :code:`shell-relative` format is the same as :code:`shell` except that
directory. Note that when invoked from a mapping, this option is ignored, it returns paths relative to the starting directory. Note that when invoked from a mapping,
and either text or shell format is used automatically based on whether the cursor is at a shell prompt or not. this option is ignored, and either text or shell format is used automatically based on whether
the cursor is at a shell prompt or not.
--write-pid-to --write-pid-to
@ -280,7 +281,7 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int,
--clear-cache --clear-cache
type=bool-set type=bool-set
Clear the caches used by this kitten. Clear the caches used by this kitten.
'''.format(config_help=CONFIG_HELP.format(conf_name='choose-files', appname=appname)).format """.format(config_help=CONFIG_HELP.format(conf_name='choose-files', appname=appname)).format
help_text = '''\ help_text = '''\