Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
ink-fuzzysearch
Advanced tools
QuickSearch Component for Ink 2, demo on repl.it
Forked from @aicioara's original ink-quicksearch
component to upgrade it to Ink 2. Big thanks to him for laying out the original logic in v1! If you are looking for a component that works with Ink v1, that's where to go. This re-write uses modern React (e.g. function components and hooks), and it is also in Typescript, improving the developer experience. The only behavioral difference is that this component always filters out items which do not match the query. Note that the demo runs a good bit slower than it does in an actual terminal; there's some uncanny-valley lag which is not present during normal use.
$ npm install ink-quicksearch-input
If you'd like to get a feel for how the component works, you can see the examples in action by running:
npm install
npm start
import React, { useState } from 'react';
import { render, Text } from 'ink';
import { QuickSearchInput } from 'ink-quicksearch-input';
const Demo = (props) => {
const [result, setResult] = useState('');
return (
<>
<Text>The user selected {result}.</Text>
{'\n'}
<QuickSearchInput
items={[
{value: 1, label: 'Animal'},
{value: 3, label: 'Antilope'},
{value: 2, label: 'Animation'},
{value: 0, label: 'Animate'},
{value: 4, label: 'Arizona'},
{value: 5, label: 'Aria'},
{value: 6, label: 'Arid'},
// ...
]}
onSelect={(item) => setResult(item.label)} />
</>
)
}
render(<Demo/>);
Parameter | Type | Default | Description |
---|---|---|---|
items | Array(object) | [] | Items to display in a list. Each item must be an object and have at least a label prop. |
onSelect | function | Function to call when user selects an item. Item object is passed to that function as an argument. | |
focus | boolean | true | Listen to user's input. Useful in case there are multiple input components at the same time and input must be "routed" to a specific component. |
caseSensitive | boolean | false | Whether or not quicksearch matching will be case sensitive. |
limit | int | 0 | Limit the number of rows to display. 0 is unlimited Use in conjunction with https://www.npmjs.com/package/term-size. |
forceMatchingQuery | bool | false | If set to true, queries that return no results are not allowed. In particular, if previous query X returns at least one result and X + new_character would not, query will not update to X + new_character . |
clearQueryChars | Array(char) | ['\u0015', '\u0017'] (Ctrl + u, Ctrl + w) | Key Combinations that will clear the query. ch follows the keypress API process.stdin.on('keypress', (ch, key) => {}) . |
initialSelectionIndex | int | 0 | Selection index when the component is initially rendered or when props.items changes. Can be set together with new props.items to automatically select an option. |
label | string | Optionally provide a label which will appear before the current query. | |
indicatorComponent | Component | Custom component to override the default indicator component (default - arrow). | |
itemComponent | Component | Custom component to override the default item style (default - selection coloring). | |
highlightComponent | Component | Custom component to override the default highlight style (default - background highlight). | |
statusComponent | Component | Custom component to override the status component (default - current query, optional value label). |
Type: Component
Props:
isSelected
: boolean
isHighlighted
: boolean
item
: Object
- The corresponding object inside props.items
Type: Component
Props:
isSelected
: boolean
isHighlighted
: boolean
item
: Object
- The corresponding object inside props.items
children
: any
Type: Component
Props:
isSelected
: boolean
isHighlighted
: boolean
item
: Object
- The corresponding object inside props.items
children
: any
Type: Component
Props:
hasMatch
: boolean
children
: any
label
: Optional string
// For the following four, whitespace is important
const IndicatorComponent = ({isSelected}) => {
return <Color hex="#00FF00">{isSelected ? '>' : ' '} </Color>;
};
const ItemComponent = ({isSelected, children}) => (
<Color hex={isSelected ? '#00FF00' : ''}>{children}</Color>
);
const HighlightComponent = ({children}) => (
<Color bgHex="#6C71C4">{children}</Color>
);
const StatusComponent = ({hasMatch, children}) => (
<Color hex={hasMatch ? '#00FF00' : '#FF0000'}>{children}</Color>
);
FAQs
FuzzySearch Input Component for Ink 2
We found that ink-fuzzysearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.