Skip to content

ByteLandTechnology/ink-multiline-input

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ink-multiline-input πŸ“

A robust multi-line text input component for Ink applications. πŸš€

Features ✨

  • ↕️ Vertical Scrolling: Automatically scrolls to keep the cursor in view.
  • πŸ–±οΈ Cursor Navigation: Full support for arrow keys (Up, Down, Left, Right).
  • πŸ”™ Editing: Supports Backspace and Delete keys.
  • 🎨 Customization: Style the active line with highlightStyle.
  • 🎭 Mask Support: Hide text with mask characters for password inputs.
  • πŸ“ Flexible Sizing: Control visible rows with rows and maxRows.

Demo 🎬

πŸ“ Typing

Typing Demo

🧭 Navigation

Navigation Demo

βœ‚οΈ Editing

Editing Demo

🎨 Styling & Mask

Styling Demo

πŸ“œ Scrolling

Scrolling Demo

Installation πŸ“¦

npm install ink-multiline-input

Usage πŸ› οΈ

import React, { useState } from "react";
import { render, Box } from "ink";
import { MultilineInput } from "ink-multiline-input";

const App = () => {
  const [value, setValue] = useState("");

  return (
    <Box padding={1}>
      <MultilineInput
        value={value}
        onChange={setValue}
        rows={3}
        maxRows={10}
        placeholder="Type something here..."
        highlightStyle={{ backgroundColor: "blue" }}
        textStyle={{ color: "white" }}
        onSubmit={(val) => console.log("Submitted:", val)}
        keyBindings={{
          submit: (key) => key.ctrl && key.return,
        }}
      />
    </Box>
  );
};

render(<App />);

Props βš™οΈ

MultilineInput (Controlled)

Prop Type Default Description
value string - πŸ“ The current value of the input.
onChange (value: string) => void - πŸ”„ Callback function triggered when the value changes.
onSubmit (value: string) => void - πŸš€ (Optional) Callback triggered when the submit key is pressed.
rows number - πŸ“ (Optional) Minimum number of rows to display.
maxRows number - πŸ“ (Optional) Maximum number of rows to display.
highlightStyle TextProps - 🎨 (Optional) Style to apply to the current line.
textStyle TextProps - πŸ”€ (Optional) Style to apply to the text.
placeholder string "" πŸ“­ (Optional) Text to display when value is empty.
mask string - 🎭 (Optional) Character to mask text (e.g., "*" for passwords).
showCursor boolean true πŸ–±οΈ (Optional) Whether to show the cursor.
focus boolean true 🎯 (Optional) Whether this input should receive keyboard input.
tabSize number 4 ↔️ (Optional) Number of spaces to expand tabs to.
keyBindings object - ⌨️ (Optional) Custom key bindings for submit and newline.
highlightPastedText boolean false 🎨 (Optional) Highlight recently pasted text.
useCustomInput function - πŸ”Œ (Optional) Custom input hook to replace default useInput.

Key Bindings

You can customize which keys trigger specific actions:

keyBindings={{
  submit: (key) => key.ctrl && key.return, // Ctrl+Enter to submit
  newline: (key) => key.return, // Enter for newline (default)
}}

ControlledMultilineInput

For advanced use cases where you want to control the cursor position yourself, use ControlledMultilineInput:

import { ControlledMultilineInput } from "ink-multiline-input";

<ControlledMultilineInput
  value={text}
  cursorIndex={cursorPos}
  maxRows={10}
  showCursor={true}
  focus={true}
/>;

API Documentation πŸ“š

For detailed API documentation, see the API Reference.

License πŸ“„

MIT

About

A robust multi-line text input component for Ink applications. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published