From 5bb8378dc166365b28dbba167cd420873c95bf7b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Jun 2024 13:06:46 +0530 Subject: [PATCH] icat: Add an option to leave the cursor to the right of the image Fixes #7574 --- docs/changelog.rst | 2 ++ kittens/icat/main.go | 2 +- kittens/icat/main.py | 6 ++++++ kittens/icat/transmit.go | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7a61533e1..eccbbdb9a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -76,6 +76,8 @@ Detailed list of changes - Wayland: Fix specifying the output name for the panel kitten not working (:iss:`7573`) +- icat kitten: Add an option :option:`kitty +kitten icat --no-trailing-newline` to leave the cursor to the right of the image (:iss:`7574`) + 0.35.2 [2024-06-22] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/icat/main.go b/kittens/icat/main.go index 85ead219b..b3979ae96 100644 --- a/kittens/icat/main.go +++ b/kittens/icat/main.go @@ -292,7 +292,7 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) { if imgd.err != nil { print_error("Failed to process \x1b[31m%s\x1b[39m: %s\r\n", imgd.source_name, imgd.err) } else { - transmit_image(imgd) + transmit_image(imgd, opts.NoTrailingNewline) if imgd.err != nil { print_error("Failed to transmit \x1b[31m%s\x1b[39m: %s\r\n", imgd.source_name, imgd.err) } diff --git a/kittens/icat/main.py b/kittens/icat/main.py index c8c8f2e0a..168715921 100644 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -155,6 +155,12 @@ The graphics protocol id to use for the created image. Normally, a random id is created if needed. This option allows control of the id. When multiple images are sent, sequential ids starting from the specified id are used. Valid ids are from 1 to 4294967295. Numbers outside this range are automatically wrapped. + + +--no-trailing-newline -n +type=bool-set +By default, the cursor is moved to the next line after displaying an image. This option, prevents that. Should not be used +when catting multiple images. Also has no effect when the :option:`--place` option is used. ''' help_text = ( diff --git a/kittens/icat/transmit.go b/kittens/icat/transmit.go index c847458d0..d4556efff 100644 --- a/kittens/icat/transmit.go +++ b/kittens/icat/transmit.go @@ -278,7 +278,7 @@ func write_unicode_placeholder(imgd *image_data) { var seen_image_ids *utils.Set[uint32] -func transmit_image(imgd *image_data) { +func transmit_image(imgd *image_data, no_trailing_newline bool) { if seen_image_ids == nil { seen_image_ids = utils.NewSet[uint32](32) } @@ -406,7 +406,7 @@ func transmit_image(imgd *image_data) { return } } - if imgd.move_to.x == 0 { + if imgd.move_to.x == 0 && !no_trailing_newline { fmt.Println() // ensure cursor is on new line } }