Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor globalAliases #218

Merged
merged 6 commits into from
Dec 19, 2024
Merged

Refactor globalAliases #218

merged 6 commits into from
Dec 19, 2024

Conversation

natemoo-re
Copy link
Member

Follow-up to #147 and #125!

The original request in #125 was to map the Escape key to cancellation (Ctrl+C). This was implemented by adding alias support in #147, but I agree that it's an extremely reasonable default. This PR adds esc as a default keybinding.

alias action
k up
l right
j down
h left
esc cancel

Additionally, #147 introduced setGlobalAliases as a one-off function. Because there are many potential use cases for custom settings (themes / colors – see #212), this PR centralizes all global configuration in a more generic updateSettings function.

As of now, updateSettings() only accepts an aliases object that maps custom keys to an action (up | down | left | right | space | enter | cancel). This can be expanded in the future.

import { updateSettings } from "@clack/prompts";

// Support custom keybindings
updateSettings({
  aliases: {
    w: "up",
    a: "left",
    s: "down",
    d: "right",
  },
});

Warning

In order to enforce consistent, user-friendly defaults across the ecosystem, updateSettings does not support disabling Clack's default keybindings.

I firmly believe that having opinions about the right usability defaults is a good thing. Flexibility for flexibility's sake is a recipe for inconsistency and user frustration.

Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: bcfd1d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Minor
@clack/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Dec 19, 2024

Open in Stackblitz

npm i https://pkg.pr.new/bombshell-dev/clack/@clack/core@218
npm i https://pkg.pr.new/bombshell-dev/clack/@clack/prompts@218

commit: bcfd1d4

@natemoo-re natemoo-re merged commit a83d2f8 into main Dec 19, 2024
6 checks passed
@natemoo-re natemoo-re deleted the refactor/global-settings branch December 19, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant