Menu

Building a K Command Palette (and a Fake Terminal) for My Portfolio
📰

Building a K Command Palette (and a Fake Terminal) for My Portfolio

DEV Community: react·Amine Amine·about 4 hours ago
#1sH4TZ6Q
#devtoreact#devto#dev#match#press
Reading 0:00
15s threshold

Press ⌘K (or Ctrl+K) anywhere on my site and you get a search box that jumps to any page, case study, game, blog post or Dota 2 hero. Press ~ and you get a terminal. Neither is essential. Both are the kind of detail that makes a developer's site feel like it was made by a developer.

Here's how they're built, and the few decisions that kept them simple.

Logic first, UI second

Both features are mostly logic, so I wrote the logic as pure functions with no React involved:

buildItems(posts, heroes, work) returns a flat list of { group, label, url, keywords } ;

filterItems(items, query) ranks them;

runCommand(input) returns { lines, action } for the terminal, where action is "navigate", "clear" or "exit";

complete(input) does tab completion.

The React components only render state and call these.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.