Skip to content

Keybinding Help

Auto-formatted keybinding reference overlay for Ink 5. Renders a bordered help panel from a config object, similar to pressing ? in vim or htop.

Install

Terminal window
npm install @matthesketh/ink-keybinding-help

Usage

import React, { useState } from 'react';
import { render, useInput } from 'ink';
import { KeyBindingHelp } from '@matthesketh/ink-keybinding-help';
function App() {
const [showHelp, setShowHelp] = useState(false);
useInput((input) => {
if (input === '?') setShowHelp((v) => !v);
});
return (
<KeyBindingHelp
visible={showHelp}
title="Keyboard Shortcuts"
columns={2}
groups={[
{
title: 'Navigation',
bindings: [
{ key: 'j/k', description: 'navigate list' },
{ key: 'Tab', description: 'switch view' },
],
},
{
title: 'Actions',
bindings: [
{ key: 'Enter', description: 'confirm selection' },
{ key: 'q', description: 'quit' },
],
},
]}
/>
);
}
render(<App />);

Props

PropTypeDefaultDescription
groupsKeyBindingGroup[]requiredArray of keybinding groups to display
titlestring"Keyboard Shortcuts"Title shown at the top of the panel
columnsnumber2Number of columns to arrange groups in
visiblebooleantrueWhether the panel is rendered; set to false to hide

KeyBindingGroup

FieldTypeDescription
titlestringSection header (e.g. “Navigation”)
bindingsKeyBinding[]List of key-description pairs

KeyBinding

FieldTypeDescription
keystringKey or key combination (e.g. “j/k”, “Ctrl+c”)
descriptionstringWhat the key does

Requirements

  • Node.js >= 18
  • ink >= 5.0.0
  • react >= 18.0.0