promptkit

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 8 Imported by: 9

README

promptkit

Interactive command line prompts with style!

Release Go Doc
Software License Go Report Card

Promptkit is a collection of common command line prompts for interactive programs. Each prompts comes with sensible defaults, re-mappable key bindings and many opportunities for heavy customization.


Disclaimers:


Selection

Selection with filter and pagination support: Example Code


The selection prompt is highly customizable and also works well with custom types which for example enables filtering only on custom fields: Example Code


Text Input

A text input that supports editable default values: Example Code


Custom validation is also supported: Example Code


The text input can also be used in hidden mode for password prompts: Example Code


Confirmation Prompt

A confirmation prompt for binary questions: Example Code

Widget

The prompts in this library can also be used as bubbletea widgets: Example Code

Acknowledgements

This library is built on top of many great libraries, especially the following:

Documentation

Overview

Package promptkit is a collection of common command line prompts for interactive programs. Each prompts comes with sensible defaults, re-mappable key bindings and many opportunities for heavy customization.

The actual prompt components can be found in the sub directories.

Index

Constants

This section is empty.

Variables

View Source
var ErrAborted = fmt.Errorf("prompt aborted")

ErrAborted is returned when the prompt was aborted.

Functions

func HardWrap added in v0.5.0

func HardWrap(input string, width int) string

HardWrap performs a hard wrap at the given width.

func Truncate added in v0.7.0

func Truncate(input string, width int) string

Truncate cuts the string after the given width.

func UtilFuncMap

func UtilFuncMap() template.FuncMap

UtilFuncMap returns a template.FuncMap with handy utility functions for prompt templates.

  • Repeat(string, int) string: Identical to strings.Repeat.
  • Len(string): reflow/ansi.PrintableRuneWidth, Len works like len but is aware of ansi codes and returns the length of the string as it appears on the screen.
  • Min(int, int) int: The minimum of two ints.
  • Max(int, int) int: The maximum of two ints.
  • Add(int, int) int: The sum of two ints.
  • Sub(int, int) int: The difference of two ints.
  • Mul(int, int) int: The product of two ints.

func WordWrap added in v0.5.0

func WordWrap(input string, width int) string

WordWrap performs a word wrap on the input and forces a wrap at width if a word is still larger that width after soft wrapping. This is known to cause issues with coloring in some terminals depending on the prompt style.

Types

type WrapMode added in v0.5.0

type WrapMode func(string, int) string

WrapMode decides in which way text is wrapped.

Directories

Path Synopsis
Package confirmation implements prompt for a binary confirmation such as a yes/no question.
Package confirmation implements prompt for a binary confirmation such as a yes/no question.
examples
bubbletea_widget
Package main demonstrates how promptkit can be used as a bubbletea widget.
Package main demonstrates how promptkit can be used as a bubbletea widget.
confirmation
Package main demonstrates how promptkit/confirmation is used.
Package main demonstrates how promptkit/confirmation is used.
confirmation_custom
Package main demonstrates how promptkit/confirmation can be customized.
Package main demonstrates how promptkit/confirmation can be customized.
selection
Package main demonstrates how promptkit/selection is used.
Package main demonstrates how promptkit/selection is used.
selection_custom
Package main demonstrates how promptkit/selection can be customized.
Package main demonstrates how promptkit/selection can be customized.
textinput
Package main demonstrates how promptkit/textinput is used.
Package main demonstrates how promptkit/textinput is used.
textinput_custom
Package main demonstrates how promptkit/textinput can be customized.
Package main demonstrates how promptkit/textinput can be customized.
textinput_hidden
Package main demonstrates how promptkit/textinput can be used to ask for passphrases.
Package main demonstrates how promptkit/textinput can be used to ask for passphrases.
Package selection implements a selection prompt that allows users to select one of the pre-defined choices.
Package selection implements a selection prompt that allows users to select one of the pre-defined choices.
Package test contains helper functions for prompt tests.
Package test contains helper functions for prompt tests.
Package textinput implements prompt for a string input that can also be used for secret strings such as passwords.
Package textinput implements prompt for a string input that can also be used for secret strings such as passwords.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL