-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "--position" argument? #146
Comments
Hum... Actually I think a |
There are potentially two ways this can be solved without adding a new argument:
I think the second approach would be preferable, since we're already using relative cursor movement. Would this work for your use case? I assume you're splitting symbol rows on Also see #140 with regards to positioning. |
I'm also open to adding an argument to make it use cursor movement instead of |
Thanks for your insight. About my use case, actually I just want to display a Sixel image with a margin of one space on the left. I'm not even using the C API. Typing I wasn't aware of the |
@hpjansson So I made tests regarding the Layout is:
Basically, among the six tested terminals, only What do you suggest to implement? Do you think that if |
It could be a Another question is which defaults terminals are using. I still have to think about this a little and run some tests (what happens when the image extends all the way to the right? Do terminals wrap the cursor to the next line like kitty does, or is it more common to defer logical position wrapping until a character is printed, as most terminals do with regular symbols?). |
Looking at this now. May be easier to do than I first thought, without causing any regressions. |
Hi @hpjansson, thanks for the update! I made some tests using Unfortunately, I noticed a regression even without the new Regarding the new So I guess we'll have to find out whether it's a bug on the Foot or Chafa side? |
Sorry to intrude...
If I understand the problem correctly, I think the above solution might be less complex and would probably yield less surprises. Basically, prepending every line of output with the given number of spaces or a I may not be seeing all the angles involved though, so I can't say for sure that this will be a viable solution for chafa.
Most terminal emulators write |
If you issue Anyway. There's the drawback of relative positioning; the image or animation will appear where the cursor was placed, but if you inject anything in the stream, it will perturb the positioning. We could work around it by save/restoring the cursor position, but we're already using the register to return to the beginning of the next relative line in symbols mode. So for symbols we're currently doing this for each row:
We could instead do:
Then we could store the position at the start of the animation and restore it before each frame, which would be more robust against injected text. The only thing I'm not sure about is how fullwidth characters (occupying two columns) would impact this. When moving the cursor over fullwidth symbols, normally only one step is required to move over it instead of two. But when testing this in VTE, doing e.g.
That's odd. I don't have a working Wayland server at the moment, but I'll look into it once that's solved. If you have the time to investigate, you could cat the Chafa output to a file and edit the esc sequences to get a feel for what's going on. Maybe
Yeah... It seems to work fine in |
No such thing -- it's nice to have your input :-)
That's definitely more robust. It'd be nice to have the cake and eat it too, though. What I've been thinking (and trying to implement) is two modes selectable with the The first mode uses spaces and newlines for formatting ( The second mode ( Regarding
|
I made a comparison, and it turns out that after I haven't been able to test with
So it sounds like it agrees with I'm inclined to side with @dnkl Do you know of any reference or testing that verifies that the cursor should advance to the beginning-of-line and not below the bottom-left corner of sixels? |
I'd say most terminals are converging towards wezterms(?s) behavior; the cursor is positioned on the last row of the sixel, at the first sixel column. Or will converge, once XTerm's updated cursor placement logic has caught on... This is xterm-382 (the weird looking prompt after the sixel is a color issue, not a placement issue): There's a PR for foot (not quite functional yet): https://codeberg.org/dnkl/foot/pulls/1373 There's a code comment in latest xterm on this:
The most obvious advantage with this cursor placement is it allows you to print a sixel to the bottom row (without enabling private mode 8452). But does mean you have to emit an explicit newline to prevent e.g. the shell from overwriting the last row of the sixel. |
Yeah, this should overcome the issue of injected text... though, I guess you meant "restore it before each line of each frame".
Hmm... that's actually quite concerning. 🤔
Note the use of "character positions", not "columns" 🥲... though I don't think there was the concept of Unicode or fullwidth symbols back when it was written. Anyway, this indicates there are chances some terminal emulators implement horizontal cursor movement otherwise. |
I believe the work done by @j4james and @hackerb9 is what have ultimately led to the changes in cursor positioning. See for example hackerb9/vt340test#25, and hackerb9/vt340test#11 |
Thanks, that's great information and some superb analysis there. The consensus -- leaving the cursor on the last row to avoid scrolling -- sounds like a good approach. I guess we'll keep using cursor save/restore (CSI s and CSI u) while reserving a parking row as implementations (hopefully) converge. Oh, and let me know if I can help with testing and such. |
If you mean "save, print row, restore, down, print row, restore, down down, etc", I think it might not be the best idea because the rate of growth in downwards movement would be superlinear. Instead I'd be willing to accept that an entire frame gets mangled if the subsequent frame corrects the offset. And you'd always mangle at least one row anyway... Edit: Actually this would not be a big problem as we'd emit a single cursor movement sequence each time, and the number of digits in the offset wouldn't grow that fast :-)
VTE does this: $ echo -e 'a¥b¥c\e[DX'
a¥b¥X
$ echo -e 'a¥b¥c\e[D\e[DX'
a¥b Xc
$ echo -e 'a¥b¥c\e[D\e[D\e[DX'
a¥bX c Which seems fine for our purposes. But when moving the cursor interactively in readline, it highlights the entire fullwidth character, and replaces both cells on overwrite (effectively deleting a column instead of replacing it with a space). So there's likely more going on under the hood in that case. |
Yes. At the end of receiving sixel data, a VT340's text cursor is positioned on the last row of that data at the same column position as when the sixel data started. This is both the documented behavior and what tests on my hardware VT340 has shown. |
To be honest, I'm not sure I completely understand what you mean here. :-/
I see, that's good. I tested Konsole earlier and it was pretty much the same. It has the same replacement behaviour described above (even without readline, not sure if you meant with or without above). Wezterm on the other hand, has a different replacement behaviour. It only overwrites the cell at the cursor position... though it has the same cursor highlight behaviour with readline as you described above. Anyways, cursor movement was always column-by-column, not character-by-character in the few terminal emulators I tested, which is what matters in this use case IMO... maybe except fullwidth characters on a line would be overwritten by halfwidth characters when drawing animations. |
@hpjansson https://codeberg.org/dnkl/foot/pulls/1373 should now be ready for testing. I'll be doing more testing myself, but mostly focusing on ensuring I haven't introduced any crashes. |
Great, I'll test it and follow up there. |
Just that if you're printing an ANSI art image, and you're returning the cursor to the top-left corner of the image before every row and then moving the cursor down to the row you're about to print, you'll have to move it down zero places for the first row, one for the second, two for the third, etc. So a 10-row image would have 0+1+2+3+4+5+6+7+8+9=45 cursor movement escape sequences if you're using index ( So this was mostly me thinking out loud -- feel free to ignore.
Ok, thanks for testing. Fortunately what happens with readline doesn't affect us, so I'll assume we're good on that front, while ambiguities in overwriting should only be a problem for whatever ends up being to the right of the ANSI art (if the terminal contracts the line by one column when overwriting fullwidth with halfwidth). |
I realized this approach (restore per line) has a subtle flaw and thought I should point it out since I brought up the idea... It breaks if the image is taller than the terminal screen since it'll cause the terminal to scroll and reserving vertical space as you mentioned earlier can't help. This doesn't affect your original proposition:
except, of course, it's an animation... for which, in my opinion, I wouldn't understand what the user's expectation was trying to draw an animation taller than the terminal screen. |
Yeah. I think I'd just file that under "don't do that then", or "I guess you're tee'ing it to a file to cat back out in a bigger window later. Maybe?" |
This discussion has run its course, and afaict everything that came up has been addressed, so I'm closing it.
|
Hi.
I'm in a situation where I'd like to display a Sixel image at some specific position of the terminal. It works fine if I move the cursor and then call the
chafa
command. However, in the case of animated images such as GIFs, this does not work well. The 1st frame is in the right position, but subsequent frames are displayed from the beginning of the line, and are therefore incorrectly positioned on the horizontal axis:I don't know how if we can fix it "by default" because as far as I know:
Consequently, after a frame has been displayed, there's no way to reposition the cursor at the origin of the image, either absolutely or relatively.
That leads me to the suggestion of adding a new
--position
argument with the idea of callingchafa_term_info_emit_cursor_to_pos()
before displaying each frame.Would you accept such PR, or do you have maybe another workaround in mind?
The text was updated successfully, but these errors were encountered: