MCPcopy
hub / github.com/c-bata/go-prompt

github.com/c-bata/go-prompt @v0.2.6 sqlite

repository ↗ · DeepWiki ↗ · release v0.2.6 ↗
384 symbols 1,051 edges 50 files 245 documented · 64%
README

go-prompt

Go Report Card Software License GoDoc tests

A library for building powerful interactive prompts inspired by python-prompt-toolkit, making it easier to build cross-platform command line tools using Go.

package main

import (
    "fmt"
    "github.com/c-bata/go-prompt"
)

func completer(d prompt.Document) []prompt.Suggest {
    s := []prompt.Suggest{
        {Text: "users", Description: "Store the username and age"},
        {Text: "articles", Description: "Store the article text posted by user"},
        {Text: "comments", Description: "Store the text commented to articles"},
    }
    return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

func main() {
    fmt.Println("Please select table.")
    t := prompt.Input("> ", completer)
    fmt.Println("You selected " + t)
}

Projects using go-prompt

Features

Powerful auto-completion

demo

(This is a GIF animation of kube-prompt.)

Flexible options

go-prompt provides many options. Please check option section of GoDoc for more details.

options

Keyboard Shortcuts

Emacs-like keyboard shortcuts are available by default (these also are the default shortcuts in Bash shell). You can customize and expand these shortcuts.

keyboard shortcuts

Key Binding Description
Ctrl + A Go to the beginning of the line (Home)
Ctrl + E Go to the end of the line (End)
Ctrl + P Previous command (Up arrow)
Ctrl + N Next command (Down arrow)
Ctrl + F Forward one character
Ctrl + B Backward one character
Ctrl + D Delete character under the cursor
Ctrl + H Delete character before the cursor (Backspace)
Ctrl + W Cut the word before the cursor to the clipboard
Ctrl + K Cut the line after the cursor to the clipboard
Ctrl + U Cut the line before the cursor to the clipboard
Ctrl + L Clear the screen

History

You can use Up arrow and Down arrow to walk through the history of commands executed.

History

Multiple platform support

We have confirmed go-prompt works fine in the following terminals:

  • iTerm2 (macOS)
  • Terminal.app (macOS)
  • Command Prompt (Windows)
  • gnome-terminal (Ubuntu)

Links

Author

Masashi Shibata

License

This software is licensed under the MIT license, see LICENSE for more information.

Extension points exported contracts — how you extend this code

ConsoleParser (Interface)
ConsoleParser is an interface to abstract input layer. [2 implementers]
input.go
Filter (FuncType)
Filter is the type to filter the prompt.Suggestion array.
filter.go
Executor (FuncType)
Executor is called when user input something text.
prompt.go
ConsoleWriter (Interface)
ConsoleWriter is an interface to abstract output layer.
output.go
KeyBindFunc (FuncType)
KeyBindFunc receives buffer and processed it.
key_bind.go
Option (FuncType)
Option is the type to replace default parameters. prompt.New accepts any number of options (this is functional option pa
option.go
ExitChecker (FuncType)
ExitChecker is called after user input to check if prompt must stop and exit go-prompt Run loop. User input means: selec
prompt.go
Completer (FuncType)
Completer should return the suggest item from Document.
prompt.go

Core symbols most depended-on inside this repo

Document
called by 48
buffer.go
WriteRaw
called by 44
output_vt100.go
Text
called by 35
buffer.go
InsertText
called by 25
buffer.go
NewBuffer
called by 22
buffer.go
TextBeforeCursor
called by 19
document.go
TextAfterCursor
called by 18
document.go
SetColor
called by 18
output.go

Shape

Function 187
Method 162
Struct 20
FuncType 6
TypeAlias 5
Interface 2
Route 2

Languages

Go99%
Python1%

Modules by API surface

document_test.go43 symbols
document.go41 symbols
option.go34 symbols
output.go30 symbols
output_vt100.go27 symbols
buffer.go18 symbols
render.go17 symbols
prompt.go14 symbols
completion.go14 symbols
buffer_test.go10 symbols
key_bind_func.go9 symbols
internal/strings/strings.go7 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

github.com/mattn/go-colorablev0.1.7 · 1×
github.com/mattn/go-runewidthv0.0.9 · 1×
github.com/mattn/go-ttyv0.0.3 · 1×
github.com/pkg/termv1.2.0-beta.2 · 1×
golang.org/x/sysv0.0.0-2020091817442 · 1×

For agents

$ claude mcp add go-prompt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact