Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Multiline overlay text #325

Open
frolovia opened this issue Mar 23, 2021 · 3 comments
Open

Multiline overlay text #325

frolovia opened this issue Mar 23, 2021 · 3 comments

Comments

@frolovia
Copy link

frolovia commented Mar 23, 2021

It would be convenient to keep external tools' formatting in overlay_text option. So that overlay_text = $(jhead $imv_current_file) gives multiline output as jhead does itself. Or to add support of some "formatting characters" such as "\n". Translation 0xA into '0x5C6E' of jhead's output I would do by an external program.

Thanks for great software!

@eXeC64
Copy link
Owner

eXeC64 commented Apr 14, 2021

Should be an easy enough change to the imv_canvas_printf function. I don't have the same coding time to devote to imv that I used to, but I'm happy to accept a patch for this.

@gnull
Copy link
Contributor

gnull commented Jul 26, 2021

It's actually wordexp that splits the overlay text according to shell input-field-separator (IFS) rules, not Pango.

Doing putenv("IFS="); right before the line

imv/src/imv.c

Line 1947 in eeaf5e3

if (wordexp(format, &word, 0) == 0) {

preserves the newlines in overlay text.

The manual for wordexp says that setting IFS is the only way to control this behavior. This seems like a dirty solution to me: setting IFS to an empty string will break many user shell commands. For example:

$ echo $(echo 'a    b') # prints 1 space, “a” and “b” are distinct arguments
a b
$ export IFS=
$ echo $(echo 'a    b') # prints 4 spaces, “a    b” is treated as one argument
a    b

So setting IFS doesn't seem acceptable to me, and I don't see a cleaner way to keep newlines while still using wordexp.

@gnull
Copy link
Contributor

gnull commented Jul 26, 2021

@eXeC64, would it make sense to add another shell expansion mechanism for overlay_text? We can keep it compatible with the current wordexp-based one or not.

One thing we could do is let the user run a shell command and use its output as overlay text. Interface-wise, we could trigger this by a special prefix in overlay_text parameter. For example, overlay_text = hello $(echo world) will trigger the current wordexp expansion, while overlay_text = sh:echo hello world will run echo hello world and use its output as overlay.

We could also use some library that implements wordexp functionality in a cleaner way. Quick googling didin't give me any though.

Let me know what you think.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants