textual icon indicating copy to clipboard operation
textual copied to clipboard

F3 Key triggers CursorPosition event, ignores Bindings in some terminals

Open Epse opened this issue 1 month ago • 6 comments

Have you checked closed issues? (https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed) Yes

Have you checked against the most recent version of Textual? (https://pypi.org/search/?q=textual) Yes

The bug

A plain App instance with a binding for the f3 key does not trigger the action bound. The console does not show any Key events, only a CursorPosition event gets logged, contrary to most other keys.

An example app that triggers this below, note that I added two bindings to the test action, to demonstrate the difference. You can remove the f2 binding and the issue will still happen, this just allows easier validation that the action is not malformatted.

from textual.app import App, ComposeResult, SystemCommand

class MyApp(App):
    BINDINGS = [("f3,f2", "test", "Test")] 
    
    def action_test(self):
        self.notify("Test succeeded")


if __name__ == "__main__":
    app = MyApp()
    app.run()

An example of the logged CursorPosition:

[10:55:46] EVENT                                                                       message_pump.py:822
CursorPosition(x=128, y=0) >>> CawApp(title='CAW Client', classes={'-dark-mode'}, pseudo_classes={'focus',
'dark'}) method=None

this log entry has a horizontal entry above and below in the console.

In textual-keys the f3 key shows up normally. This issue has been triggered on the terminals kitty and foot. It works correctly in XTerm, UXterm, GNOME terminal and cool-retro-term.

I found this vim mailing list entry which gives some pointers.

Diagnosis output:

Kitty diagnosis

Textual Diagnostics

Versions

Name Value
Textual 6.5.0
Rich 14.2.0

Python

Name Value
Version 3.12.5
Implementation CPython
Compiler Clang 18.1.8
Executable /home/idlab261/projects/cawclient/.venv/bin/python3

Operating System

Name Value
System Linux
Release 6.8.0-87-generic
Version #88~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Oct 14 14:03:14 UTC 2

Terminal

Name Value
Terminal Application Unknown
TERM xterm-kitty
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=106, height=58
legacy_windows False
min_width 1
max_width 106
is_terminal True
encoding utf-8
max_height 58
justify None
overflow None
no_wrap False
highlight None
markup None
height None

Epse avatar Nov 21 '25 10:11 Epse

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Nov 21 '25 10:11 github-actions[bot]

MRE please

willmcgugan avatar Nov 21 '25 10:11 willmcgugan

MRE please

I have edited the OP to also have imports and shorten it slightly, if that is what you require?

Epse avatar Nov 21 '25 13:11 Epse

This might be relevant: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions

The original version of this specification allowed F3 to be encoded as both CSI R and CSI ~. However, CSI R conflicts with the Cursor Position Report, so it was removed.

TomJGooding avatar Nov 21 '25 13:11 TomJGooding

It's rather confusing that textual-keys reports it correctly in the same terminals especially. Not surprising that some key encoding thing is at fault

Epse avatar Nov 21 '25 14:11 Epse

More confusing is that I can't actually reproduce this in Kitty on my machine. The F3 binding works in the example app.

I had a quick look at the key handling in Textual and seems there's a bit of history with this key. Hopefully Will might remember something about this CSI R encoding!

$ git log --oneline  | grep " f3"
1df4fc432 f3 fix
099b6163f fix for f3
3bd95cc18 can't detect f3
cbc609ad5 f3

TomJGooding avatar Nov 21 '25 16:11 TomJGooding