gokcehan / lf

Terminal file manager
MIT License
7.8k stars 330 forks source link

Issue with scrolling using alt key #1773

Closed yousef8192 closed 4 months ago

yousef8192 commented 4 months ago

Hello, first of all I would like to thank all the maintainers and contributors for this amazing tool, I use it daily and find it really useful so thanks a lot!

Now regarding my issue, I have my lfrc to only contain the following four lines (the two latter remapings are because some terminals interpret alt+k/j as ë/ê respectively) :

map <a-k> scroll-up
map <a-j> scroll-down 
map ë scroll-up
map ê scroll-down 

Now when I press alt+j/k to scroll down/up it works perfectly, however the problem appears when alt key is released while j/k are still being pressed. When that happens the cursor scrolls in the background but lf doesn't update the display and the cursor appears to be standing still at its place, and only then when I either stop holding j/k or press alt once again while j/k are still being hold, only then lf instantly updates the display and displays the new cursor position. This issue seems to be present in some terminals only while the others work fine. For an instance, the issue is present in gnome-terminal and lxterminal while in xterm it works fine. This issue seems to happen with the alt key only, if we replace the alt+j/k remaps with ctrl+j/k everything works fine in all terminals.

Tested on the latest stable release as of the time of writing this issue (which is r32)

The following is an illustration of what I mean. The keys which are being pressed are displayed at the bottom.

This is for xterm which doesn't contain the issue:

xterm-lf

This is for terminator which has the issue:

terminator-lf

If there are further information needed that I didn't provide please let me know. Thanks a lot in advance for your time and help!

joelim-work commented 4 months ago

Actually, lf doesn't handle key events directly, it uses the tcell TUI library to read key events from the terminal.

What happens is that when you press and hold alt+j, the key events are sent to lf as expected, but then when you release alt, the j key events are somehow being held back instead, so lf isn't even aware of this and therefore can't move the cursor down in response.

I suggest you report the issue to tcell, and see if they can do anything about this.

joelim-work commented 4 months ago

BTW I wrote a very quick and dirty test program to print key events as they are pressed, might be helpful in debugging:

package main

import (
    "fmt"
    "github.com/gdamore/tcell/v2"
    "log"
)

func emit(screen tcell.Screen, x, y int, str string) {
    for i, c := range str {
        screen.SetContent(x+i, y, c, nil, tcell.StyleDefault)
    }
}

func draw(screen tcell.Screen, key *tcell.EventKey, counter int) {
    screen.Clear()
    emit(screen, 0, 0, fmt.Sprintf("key: %#v", key))
    emit(screen, 0, 1, fmt.Sprintf("counter: %v", counter))
    screen.Show()
}

func main() {
    screen, err := tcell.NewScreen()
    if err != nil {
        log.Fatalf("failed to create screen %v", err)
    }

    if err := screen.Init(); err != nil {
        log.Fatalf("failed to initialize screen %v", err)
    }
    defer screen.Fini()

    counter := 0

    for {
        ev := screen.PollEvent()

        switch ev := ev.(type) {
        case *tcell.EventKey:
            if ev.Key() == tcell.KeyEscape {
                return
            }

            counter++
            draw(screen, ev, counter)
        }
    }
}
yousef8192 commented 4 months ago

Thanks a lot for your response, I did open an issue in the tcell library github page, here is the link : https://github.com/gdamore/tcell/issues/740

And regarding the test program you provided would you please confirm that the link used in the tcell library import is still valid? It seems to be outdated when I try out the program (correct me if I am missing something).

joelim-work commented 4 months ago

Importing "github.com/gdamore/tcell/v2" is correct, this is what is used in their tutorial. How are you building the program, the following steps should work:

go mod init <name>
go mod tidy
go build
yousef8192 commented 4 months ago

Apologies, indeed I didn't use these steps. Thanks for providing them and mentioning the tutorial.

joelim-work commented 4 months ago

Closing as the root cause is not from lf.