Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ offline against the Fairy-Stockfish engine. All Lichess variants are supported.
1. Open your terminal and run `pip install cli-chess`
2. Type `cli-chess` to start
3. Use your keyboard arrows, tab, or click to navigate the menus. Multi-value menu options
(e.g. changing the variant) can be cycled by pressing the spacebar, enter, or by clicking
(e.g. changing the variant) can be cycled by pressing page up/down, or by clicking
on the value.

## Playing Online
Expand Down
13 changes: 9 additions & 4 deletions src/cli_chess/core/game/game_view_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def _base_function_bar_fragments(self) -> StyleAndTextTuples:
def _flip_board_fb_fragments(self) -> Tuple:
"""Returns the function bar fragments for flipping the board"""
return (
("class:function-bar.key", "F1", handle_mouse_click(self.presenter.flip_board)),
("class:function-bar.key", "F1/Ctrl+Q", handle_mouse_click(self.presenter.flip_board)),
("class:function-bar.label", f"{'Flip board':<11}", handle_mouse_click(self.presenter.flip_board)),
("class:function-bar.spacer", " "),
)

def _exit_fb_fragments(self) -> Tuple:
"""Returns the function bar fragments for exiting the game view"""
return (
("class:function-bar.key", "F8", handle_mouse_click(self.presenter.exit)),
("class:function-bar.key", "F8/Ctrl+R", handle_mouse_click(self.presenter.exit)),
("class:function-bar.label", f"{'Exit':<11}", handle_mouse_click(self.presenter.exit)),
("class:function-bar.spacer", " "),
)
Expand All @@ -68,10 +68,12 @@ def get_key_bindings(self) -> "_MergedKeyBindings": # noqa: F821:
bindings = KeyBindings()

@bindings.add(Keys.F1, eager=True)
@bindings.add(Keys.ControlQ, eager=True)
def _(event): # noqa
self.presenter.flip_board()

@bindings.add(Keys.F8, eager=True)
@bindings.add(Keys.ControlR, eager=True)
def _(event): # noqa
self.presenter.exit()

Expand Down Expand Up @@ -102,7 +104,7 @@ def _create_container(self) -> Container:
def _takeback_fb_fragments(self) -> Tuple:
"""Returns the function bar fragments for propsing a takeback"""
return (
("class:function-bar.key", "F2", handle_mouse_click(self.presenter.propose_takeback)),
("class:function-bar.key", "F2/Ctrl+W", handle_mouse_click(self.presenter.propose_takeback)),
("class:function-bar.label", f"{'Takeback':<11}", handle_mouse_click(self.presenter.propose_takeback)),
("class:function-bar.spacer", " "),
)
Expand All @@ -118,7 +120,7 @@ def _draw_fb_fragments(self) -> Tuple:
def _resign_fb_fragments(self) -> Tuple:
"""Returns the function bar fragments for resigning"""
return (
("class:function-bar.key", "F4", handle_mouse_click(self.presenter.resign)),
("class:function-bar.key", "F4/Ctrl+E", handle_mouse_click(self.presenter.resign)),
("class:function-bar.label", f"{'Resign':<11}", handle_mouse_click(self.presenter.resign)),
("class:function-bar.spacer", " "),
)
Expand Down Expand Up @@ -158,6 +160,7 @@ def get_key_bindings(self) -> "_MergedKeyBindings": # noqa: F821:
"""Returns the key bindings for this container"""
bindings = KeyBindings()

@bindings.add(Keys.ControlW, filter=Condition(self.presenter.is_game_in_progress), eager=True)
@bindings.add(Keys.F2, filter=Condition(self.presenter.is_game_in_progress), eager=True)
def _(event): # noqa
self.presenter.propose_takeback()
Expand All @@ -168,11 +171,13 @@ def _(event):
if not event.is_repeat:
self.presenter.offer_draw()

@bindings.add(Keys.ControlE, filter=Condition(self.presenter.is_game_in_progress), eager=True)
@bindings.add(Keys.F4, filter=Condition(self.presenter.is_game_in_progress), eager=True)
def _(event):
if not event.is_repeat:
self.presenter.resign()

@bindings.add(Keys.ControlR, filter=Condition(self.presenter.is_game_in_progress), eager=True)
@bindings.add(Keys.F8, filter=~Condition(self.presenter.is_game_in_progress), eager=True)
def _(event): # noqa
self.presenter.exit()
Expand Down
6 changes: 3 additions & 3 deletions src/cli_chess/core/main/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _create_main_container(self):
@staticmethod
def _create_navigation_hint() -> Box:
"""Creates the navigation hint container"""
message = "Use [ARROWS] to navigate the menus. Use [SPACEBAR] or [ENTER] to modify values."
message = "Use [ARROWS] to navigate the menus. Use [PAGE UP/DOWN/SPACE/ENTER] to modify values."
return Box(
Window(FormattedTextControl(HTML(f"<i>{message}</i>"), style="class:label.dim"), align=WindowAlign.CENTER),
padding=0, padding_bottom=1, height=D(max=2)
Expand All @@ -80,7 +80,7 @@ def _get_function_bar_fragments() -> StyleAndTextTuples:
fragments.append(("class:function-bar.spacer", " "))

fragments.extend([
("class:function-bar.key", "F8", handle_mouse_click(exit_app)),
("class:function-bar.key", "F8/Ctrl+R", handle_mouse_click(exit_app)),
("class:function-bar.label", f"{'Quit':<14}", handle_mouse_click(exit_app))
])

Expand All @@ -96,7 +96,7 @@ def _create_function_bar_key_bindings(self) -> "_MergedKeyBindings": # noqa: F8
main_menu_fb_key_bindings = self.presenter.main_menu_presenter.view.get_function_bar_key_bindings()
main_view_fb_key_bindings = KeyBindings()
main_view_fb_key_bindings.add(Keys.F8)(exit_app)

main_view_fb_key_bindings.add(Keys.ControlC)(exit_app)
return merge_key_bindings([main_view_fb_key_bindings, main_menu_fb_key_bindings])

def get_global_key_bindings(self) -> KeyBindings():
Expand Down
4 changes: 3 additions & 1 deletion src/cli_chess/menus/menu_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ def _create_key_bindings(self) -> KeyBindings:

@bindings.add(Keys.Enter, eager=True)
@bindings.add(" ", eager=True)
@bindings.add(Keys.PageUp, eager=True)
@bindings.add(Keys.PageDown, eager=True)
def _(event): # noqa
"""Handle Enter/Space key press"""
"""Handle PageUp/PageDown key press"""
self.cycle_value(self.selected_option)

return bindings
Expand Down
3 changes: 2 additions & 1 deletion src/cli_chess/menus/versus_menus/versus_menu_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def __init__(self, presenter: VersusMenuPresenter):

def get_function_bar_fragments(self) -> StyleAndTextTuples:
return [
("class:function-bar.key", "F1", handle_mouse_click(self.presenter.handle_start_game)),
("class:function-bar.key", "F1/Ctrl+Q", handle_mouse_click(self.presenter.handle_start_game)),
("class:function-bar.label", f"{'Start game':<14}", handle_mouse_click(self.presenter.handle_start_game)),
]

def get_function_bar_key_bindings(self) -> KeyBindings:
"""Creates the key bindings associated to the function bar fragments"""
kb = KeyBindings()
kb.add(Keys.F1)(handle_bound_key_pressed(self.presenter.handle_start_game))
kb.add(Keys.ControlQ)(handle_bound_key_pressed(self.presenter.handle_start_game))
return kb
Loading