With Textual 0.5.0 I had bindings on the arrow keys that worked fine. Having upgraded to 0.6.0 those bindings no longer seem to work. Isolating the issue I can recreate with this code (some other keys thrown in as control tests)
from textual.app import App, ComposeResult
from textual.widgets import TextLog, Header, Footer
from textual.binding import Binding
from textual.events import Key
class Binder( App[ None ] ):
CSS = """
TextLog {
background: #222200;
color: #BBBB00;
text-style: bold;
}
"""
BINDINGS = [
Binding( "up", "log( 'up' )", "Up" ),
Binding( "down", "log( 'down' )", "Down" ),
Binding( "left", "log( 'left' )", "Left" ),
Binding( "right", "log( 'right' )", "Right" ),
Binding( "a", "log( 'a' )", "a" ),
Binding( "s", "log( 's' )", "s" ),
Binding( "d", "log( 'd' )", "d" ),
Binding( "f", "log( 'f' )", "f" ),
Binding( "left_square_bracket", "log( '[' )", "[" ),
Binding( "right_square_bracket", "log( ']' )", "]" ),
]
def compose( self ) -> ComposeResult:
yield Header()
yield TextLog()
yield Footer()
def on_mount( self ) -> None:
self.query_one( TextLog ).write( "Ready..." )
self.query_one( TextLog ).write( "Key bindings being looked for:" )
self.query_one( TextLog ).write( ", ".join(
[ binding.key for binding in self.BINDINGS ]
) )
def action_log( self, name: str ) -> None:
self.query_one( TextLog ).write( f"Via binding: {name}" )
def on_key( self, event: Key ) -> None:
self.query_one( TextLog ).write( f"Via event: {event!r}" )
if __name__ == "__main__":
Binder().run()
Running the above, pressing the arrow keys vs some of the other keys...
bug