bakkeby / st-flexipatch

An st build with preprocessor directives to decide which patches to include during build time
MIT License
362 stars 108 forks source link

Reflow patch: Scrollback buffer contents are lost when clearing screen with `Ctrl+l` #123

Closed UtkarshVerma closed 8 months ago

UtkarshVerma commented 8 months ago

This issue is similar to #46 where the scrollback buffer contents are lost when Ctrl+l is pressed.

Here are the patches I have enabled.

#define ALPHA_PATCH 1
#define ANYSIZE_SIMPLE_PATCH 1
#define BLINKING_CURSOR_PATCH 1
#define BOXDRAW_PATCH 1
#define CSI_22_23_PATCH 1
#define DEFAULT_CURSOR_PATCH 1
#define EXTERNALPIPE_PATCH 1
#define FIXKEYBOARDINPUT_PATCH 1
#define LIGATURES_PATCH 1
#define NETWMICON_LEGACY_PATCH 1
#define NEWTERM_PATCH 1
#define REFLOW_PATCH 1
#define SIXEL_PATCH 1
#define SYNC_PATCH 1
#define VERTCENTER_PATCH 1
#define WIDE_GLYPHS_PATCH 1
#define WORKINGDIR_PATCH 1
#define XRESOURCES_PATCH 1
#define XRESOURCES_RELOAD_PATCH 1

Important thing is I have enabled the reflow patch without the scrollback patch.

Steps to reproduce

  1. Get the source: https://github.com/UtkarshVerma/st-flexipatch
  2. Compile and run st.
  3. Run any command to get output.
  4. Press Ctrl+l and see that the output is lost from the scrollback history.

Here's a video of the issue: https://github.com/bakkeby/st-flexipatch/assets/31820255/b92ef36a-494c-4f99-ae1c-472f4def1f5f

I have also noticed that while scrolling, the prompt is always shown at the top. Is there any way to avoid this behavior? Is this an intentional feature or is it a bug? https://github.com/bakkeby/st-flexipatch/assets/31820255/6c9bbbdb-007f-4613-a344-7ec0ccba032e

bakkeby commented 8 months ago

I have enabled the reflow patch without the scrollback patch.

Yes that is the intended way.

Both of these issues looks to have been addressed in https://github.com/veltza/st-sx so I'll have a closer look and get back to you.

The history buffer is not cut when you do ctrl+l - presumably it just scrolls all the way down rather than clearing what is in view.

As for the prompt and cursor - it looks like the cursor there is hidden when you start scrolling and it is only revealed again when focus is on the line where the cursor is.

Thanks for reporting.

veltza commented 8 months ago

The code that looks for the last line was accidentally placed inside a conditional compilation block. Move it out of that block and ctrl+l should work.

            #if KEYBOARDSELECT_PATCH
            for (n = term.row-1; n >= 0 && tlinelen(term.line[n]) == 0; n--)
                ;
            #endif // KEYBOARDSELECT_PATCH
UtkarshVerma commented 8 months ago

veltza is right. It works if I move it outside the KEYBOARDSELECT conditional. However, the prompt issue still persists.

https://github.com/bakkeby/st-flexipatch/assets/31820255/1ef449d6-9111-40a3-990b-85a6dbbbfd0e

veltza commented 8 months ago

This should fix both issues. I haven't fully tested it yet though.

diff --git a/st.c b/st.c
index bc1abf7..5932a3f 100644
--- a/st.c
+++ b/st.c
@@ -2227,10 +2227,8 @@ csihandle(void)
            /* vte does this:
            tscrollup(0, term.row-1, term.row, SCROLL_SAVEHIST); */
            /* alacritty does this: */
-           #if KEYBOARDSELECT_PATCH
            for (n = term.row-1; n >= 0 && tlinelen(term.line[n]) == 0; n--)
                ;
-           #endif // KEYBOARDSELECT_PATCH
            #if SIXEL_PATCH
            for (im = term.images; im; im = im->next)
                n = MAX(im->y - term.scr, n);
@@ -3695,11 +3693,9 @@ draw(void)

    #if KEYBOARDSELECT_PATCH && REFLOW_PATCH
    if (!kbds_drawcursor()) {
-   #endif // KEYBOARDSELECT_PATCH
-
-   #if SCROLLBACK_PATCH
+   #elif REFLOW_PATCH || SCROLLBACK_PATCH
    if (term.scr == 0)
-   #endif // SCROLLBACK_PATCH
+   #endif // REFLOW_PATCH || SCROLLBACK_PATCH
    #if LIGATURES_PATCH
    xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
            term.ocx, term.ocy, term.line[term.ocy][term.ocx],
UtkarshVerma commented 8 months ago

Thanks for the changes, veltzo. I tried them out and they work fine. However, I noticed one minor detail. After clearing the screen, an additional line is appended for the prompt, when scrolling back. Do you have an idea of what this could be?

Here's a video:

https://github.com/bakkeby/st-flexipatch/assets/31820255/3e7001a5-f004-41d8-8edb-2245d3ce5e5b

UtkarshVerma commented 8 months ago

The new prompt line is normal behavior. Please ignore it. Everything works fine.

bakkeby commented 8 months ago

Thanks again for the assist @veltza