Code Monkey home page Code Monkey logo

bun-promptx's Introduction

bun-promptx

bun-promptx is a terminal prompt library based on bubbles via bun:ffi.

Install

bun add bun-promptx

Usage

createSelection

The createSelection function lets you create a terminal single-selection list prompt. It provides the functions of page up and down and key movement, and supports custom rendering methods.

import { createSelection } from 'bun-promptx'

const result = createSelection([
  { text: 'feat', description: 'Introducing new features' },
  { text: 'fix', description: 'Bug fix' },
  { text: 'docs', description: 'Writing docs' },
  { text: 'style', description: 'Improving structure/format of the code' },
  { text: 'refactor', description: 'Refactoring code' },
  { text: 'test', description: 'Refactoring code' },
  { text: 'chore', description: 'When adding missing tests' },
  { text: 'perf', description: 'Improving performance' }
], {
  headerText: 'Select Commit Type: ',
  perPage: 5,
  footerText: 'Footer here'
})

console.log(result)
// { selectedIndex: 2, error: null }

promptx demo

createPrompt

The createPrompt function is a terminal input prompt library. It provides CJK character support and standard terminal shortcut keys (such as ctrl+a, ctrl+e), password input echo and other functions.

import { createPrompt } from 'bun-promptx'

const username = createPrompt("Enter username: ")
// { value: "wobsoriano", error: null }

const password = createPrompt("Enter password: ", {
  echoMode: 'password'
})
// { value: "123456", error: null }

promptx demo

License

MIT

bun-promptx's People

Contributors

wobsoriano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

svallory

bun-promptx's Issues

How to exit out of a selection process?

const responses = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((item) => {
  return createSelection(
    [
      {
        text: 'skip',
      },
      {
        text: 'higher',
      },
      {
        text: 'lower',
      },
    ],
    {
      headerText: `What should be done with number: ${item}?`,
    }
  )
})

console.log(responses)

If I enter the command [CTRL] + [C], it doesn't exit the running process as expected.
Instead, it continues throughout the list of items.

Failed to open library. This is usually caused by a missing library or an invalid library path.

I got an error:

 9 |   filename = `../release/promptx-${platform}-amd64.${suffix}`;
10 | } else {
11 |   filename = `../release/promptx-${platform}-${arch}.${suffix}`;
12 | }
13 | var location = new URL(filename, import.meta.url).pathname;
14 | var { symbols } = dlopen(location, {
                       ^
ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path.
 syscall: "dlopen"

      at bun:ffi:61:41
      at D:\Code\Whatever\example.com\node_modules\bun-promptx\dist\index.mjs:14:19

On Windows 11 with Powershell 7.

My script was simple:

import { mkdir } from "node:fs/promises";
import { createPrompt } from 'bun-promptx'

const title = createPrompt("Enter title: ")
const tags = createPrompt("Enter tags: ")

const metadata = `---
title: '${title}'
date: '${new Date()}'
tags: [${tags}]
draft: true
---
`

const dir = "path/to/dir"
await mkdir(dir, { recursive: true });
await Bun.write(`${dir}/index.md`, metadata);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.