All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- PR#18 - fix the
http-prompt
example and refactor the example building script (make it fail when an example doesn't compile) - PR#17 - correctly restore terminal parameters
- PR#16 - propagate
getOriginalTermios
error when called multiple times
func (*prompt.Document).PreviousLineIndentSpaces() int
func (*prompt.Document).PreviousLineIndentLevel(indentSize int) int
func (*prompt.Document).PreviousLine() (s string, ok bool)
func (*prompt.Document).IndentSpaces(input string) int
func (*prompt.Document).IndentLevel(input string, indentSize int) int
func (*prompt.Document).CurrentLineIndentSpaces() int
func (*prompt.Document).CurrentLineIndentLevel(indentSize int) int
func (*prompt.Prompt).DeleteBeforeCursor(count strings.GraphemeNumber) string
func (*prompt.Prompt).DeleteBeforeCursorRunes(count strings.RuneNumber) string
func (*prompt.Prompt).Delete(count strings.GraphemeNumber) string
func (*prompt.Prompt).DeleteRunes(count strings.RuneNumber) string
func (*prompt.Prompt).InsertText(text string, overwrite bool)
func (*prompt.Prompt).InsertTextMoveCursor(text string, overwrite bool)
func (*prompt.Prompt).UserInputColumns() strings.Width
func (*prompt.Prompt).TerminalColumns() strings.Width
func (*prompt.Prompt).TerminalRows() int
- Change signatures:
prompt.ExecuteOnEnterCallback
- from
func(buffer *prompt.Buffer, indentSize int) (indent int, execute bool)
- to
func(p *prompt.Prompt, indentSize int) (indent int, execute bool)
- from
- Change
(*Prompt).Buffer
from a public field to a public getter method
- Fix cursor movement for text with grapheme clusters like 🇵🇱, 🙆🏿♂️
- Add
strings.GraphemeNumber
, a type that represents the amount of grapheme clusters in a string (or an offset of a grapheme cluster in a string)type strings.GraphemeNumber int
func strings.GraphemeCountInString(text string) strings.GraphemeNumber
func strings.RuneCountInString(s string) strings.RuneNumber
func strings.RuneIndexNthGrapheme(text string, n strings.GraphemeNumber) strings.RuneNumber
func strings.RuneIndexNthColumn(text string, n strings.Width) strings.RuneNumber
func (*prompt.Document).GetCursorLeftPositionRunes(count strings.RuneNumber) strings.RuneNumber
func (*prompt.Document).GetCursorRightPositionRunes(count strings.RuneNumber) strings.RuneNumber
func (*prompt.Document).LastLineIndentLevel(indentSize int) int
func (*prompt.Document).LastLineIndentSpaces() int
func (*prompt.Buffer).DeleteRunes(count strings.RuneNumber, col strings.Width, row int) string
func (*prompt.Buffer).DeleteBeforeCursorRunes(count strings.RuneNumber, col strings.Width, row int) string
- Change signatures:
strings.RuneCount
- from
func strings.RuneCount(s string) strings.RuneNumber
- to
func strings.RuneCount(b []byte) strings.RuneNumber
- from
prompt.ExecuteOnEnterCallback
- from
func(input string, indentSize int) (indent int, execute bool)
- to
func(buffer *prompt.Buffer, indentSize int) (indent int, execute bool)
- from
(*prompt.Document).CursorPositionCol
- from
func (*prompt.Document).CursorPositionCol() (col strings.RuneNumber)
- to
func (*prompt.Document).CursorPositionCol() (col strings.Width)
- from
(*prompt.Document).GetCursorRightPosition
- from
func (*prompt.Document).GetCursorRightPosition(count strings.RuneNumber) strings.RuneNumber
- to
func (*prompt.Document).GetCursorRightPosition(count strings.Width) strings.RuneNumber
- from
(*prompt.Document).GetCursorLeftPosition
- from
func (*prompt.Document).GetCursorLeftPosition(count strings.RuneNumber) strings.RuneNumber
- to
func (*prompt.Document).GetCursorLeftPosition(count strings.Width) strings.RuneNumber
- from
(*prompt.Document).GetCursorUpPosition
- from
func (*prompt.Document).GetCursorUpPosition(count int, preferredColumn strings.RuneNumber) strings.RuneNumber
- to
func (*prompt.Document).GetCursorUpPosition(count int, preferredColumn strings.Width) strings.RuneNumber
- from
(*prompt.Document).GetCursorDownPosition
- from
func (*prompt.Document).GetCursorDownPosition(count int, preferredColumn strings.RuneNumber) strings.RuneNumber
- to
func (*prompt.Document).GetCursorDownPosition(count int, preferredColumn strings.Width) strings.RuneNumber
- from
(*prompt.Document).TranslateRowColToIndex
- from
func (*prompt.Document).TranslateRowColToIndex(row int, column strings.RuneNumber) strings.RuneNumber
- to
func (*prompt.Document).TranslateRowColToIndex(row int, column strings.Width) strings.RuneNumber
- from
(*prompt.Buffer).Delete
- from
func (*Buffer).Delete(count istrings.RuneNumber, col istrings.Width, row int) string
- to
func (*Buffer).Delete(count istrings.GraphemeNumber, col istrings.Width, row int) string
- from
(*prompt.Buffer).DeleteBeforeCursor
- from
func (*Buffer).DeleteBeforeCursor(count istrings.RuneNumber, col istrings.Width, row int) string
- to
func (*Buffer).DeleteBeforeCursor(count istrings.GraphemeNumber, col istrings.Width, row int) string
- from
- Reset formatting after rendering a styled token
- Fix unit tests
prompt.Token
has new methods:BackgroundColor() prompt.Color
- define the background color for the tokenDisplayAttributes() []prompt.DisplayAttribute
- define the font eg. bold, italic, underline
prompt.NewSimpleToken
has new options:prompt.SimpleTokenWithColor(c Color) SimpleTokenOption
prompt.SimpleTokenWithBackgroundColor(c Color) SimpleTokenOption
prompt.SimpleTokenWithDisplayAttributes(attrs ...DisplayAttribute) SimpleTokenOption
prompt.Writer
has new methods:prompt.SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribute)
- change the signature of
prompt.NewSimpleToken
fromfunc NewSimpleToken(color Color, firstIndex, lastIndex istrings.ByteNumber) *SimpleToken
tofunc NewSimpleToken(firstIndex, lastIndex istrings.ByteNumber, opts ...SimpleTokenOption) *SimpleToken
prompt.Token
has a new methodFirstByteIndex() strings.ByteNumber
This release contains a major refactoring of the codebase. It's the first release of the elk-language/go-prompt fork.
The original library has been abandoned for at least 2 years now (although serious development has stopped 5 years ago).
This release aims to make the code a bit cleaner, fix a couple of bugs and provide new, essential functionality such as syntax highlighting, dynamic Enter and multiline edit support.
-
prompt.New
constructor options:prompt.WithLexer
let's you set a custom lexer for providing syntax highlightingprompt.WithCompleter
for setting a customCompleter
(completer is no longer a required argument inprompt.New
)prompt.WithIndentSize
let's you customise how many spaces should constitute a single indentation levelprompt.WithExecuteOnEnterCallback
-
prompt.Position
-- represents the cursor's position in 2D -
prompt.Lexer
,prompt.Token
,prompt.SimpleToken
,prompt.EagerLexer
,prompt.LexerFunc
-- new syntax highlighting functionality -
prompt.ExecuteOnEnterCallback
-- new dynamic Enter functionality (decide whether to insert a newline and indent or execute the input) -
examples:
_example/bang-executor
-- a sample program which uses the newExecuteOnEnterCallback
. Pressing Enter will insert a newline unless the input ends with an exclamation point!
(then it gets executed)._example/even-lexer
-- a sample program which shows how to use the new lexer feature. It implements a simple lexer which colours every character with an even index green.
- Update Go from 1.16 to 1.19
- The cursor can move in 2D (left-right, up-down)
- The Up arrow key will jump to the line above if the cursor is beyond the first line, but it will replace the input with the previous history entry if it's on the first line (like in Ruby's irb)
- The Down arrow key will jump to the line below if the cursor is before the last line, but it will replace the input with the next history entry if it's on the last line (like in Ruby's irb)
- Tab will insert a single indentation level when there are no suggestions
- Shift + Tab will delete a single indentation level when there are no suggestions and the line before the cursor consists only of indentation (spaces)
- Make
Completer
optional when creating a newprompt.Prompt
. Change the signature ofprompt.New
fromfunc New(Executor, Completer, ...Option) *Prompt
tofunc New(Executor, ...Option) *Prompt
- Make
prefix
andcompleter
optional inprompt.Input
. Change the signature ofprompt.Input
fromfunc Input(string, Completer, ...Option) string
tofunc Input(...Option) string
. - Rename
prompt.ConsoleParser
toprompt.Reader
and make it embedio.ReadCloser
- Rename
prompt.ConsoleWriter
toprompt.Writer
and make it embedio.Writer
andio.StringWriter
- Rename
prompt.Render
toprompt.Renderer
- Rename
prompt.OptionTitle
toprompt.WithTitle
- Rename
prompt.OptionPrefix
toprompt.WithPrefix
- Rename
prompt.OptionInitialBufferText
toprompt.WithInitialText
- Rename
prompt.OptionCompletionWordSeparator
toprompt.WithCompletionWordSeparator
- Replace
prompt.OptionLivePrefix
withprompt.WithPrefixCallback
--func() string
. The prefix is always determined by a callback function which should always return astring
. - Rename
prompt.OptionPrefixTextColor
toprompt.WithPrefixTextColor
- Rename
prompt.OptionPrefixBackgroundColor
toprompt.WithPrefixBackgroundColor
- Rename
prompt.OptionInputTextColor
toprompt.WithInputTextColor
- Rename
prompt.OptionInputBGColor
toprompt.WithInputBGColor
- Rename
prompt.OptionSuggestionTextColor
toprompt.WithSuggestionTextColor
- Rename
prompt.OptionSuggestionBGColor
toprompt.WithSuggestionBGColor
- Rename
prompt.OptionSelectedSuggestionTextColor
toprompt.WithSelectedSuggestionTextColor
- Rename
prompt.OptionSelectedSuggestionBGColor
toprompt.WithSelectedSuggestionBGColor
- Rename
prompt.OptionDescriptionTextColor
toprompt.WithDescriptionTextColor
- Rename
prompt.OptionDescriptionBGColor
toprompt.WithDescriptionBGColor
- Rename
prompt.OptionSelectedDescriptionTextColor
toprompt.WithSelectedDescriptionTextColor
- Rename
prompt.OptionSelectedDescriptionBGColor
toprompt.WithSelectedDescriptionBGColor
- Rename
prompt.OptionScrollbarThumbColor
toprompt.WithScrollbarThumbColor
- Rename
prompt.OptionScrollbarBGColor
toprompt.WithScrollbarBGColor
- Rename
prompt.OptionMaxSuggestion
toprompt.WithMaxSuggestion
- Rename
prompt.OptionHistory
toprompt.WithHistory
- Rename
prompt.OptionSwitchKeyBindMode
toprompt.WithKeyBindMode
- Rename
prompt.OptionCompletionOnDown
toprompt.WithCompletionOnDown
- Rename
prompt.OptionAddKeyBind
toprompt.WithKeyBind
- Rename
prompt.OptionAddASCIICodeBind
toprompt.WithASCIICodeBind
- Rename
prompt.OptionShowCompletionAtStart
toprompt.WithShowCompletionAtStart
- Rename
prompt.OptionBreakLineCallback
toprompt.WithBreakLineCallback
- Rename
prompt.OptionExitChecker
toprompt.WithExitChecker
- Change the signature of
Completer
fromfunc(Document) []Suggest
tofunc(Document) (suggestions []Suggest, startChar, endChar istrings.RuneNumber)
- Change the signature of
KeyBindFunc
fromfunc(*Buffer)
tofunc(p *Prompt) (rerender bool)
- Make pasting multiline text work properly
- Make pasting text with tabs work properly (tabs get replaced with indentation -- spaces)
- Introduce
strings.ByteNumber
,strings.RuneNumber
,strings.Width
to reduce the ambiguity of when to use which of the three main units used by this library to measure string length and index parts of strings. Several subtle bugs (using the wrong unit) causing panics have been fixed this way. - Remove a
/dev/tty
leak inprompt.PosixReader
(oldprompt.PosixParser
)
prompt.SwitchKeyBindMode
prompt.OptionPreviewSuggestionTextColor
prompt.OptionPreviewSuggestionBGColor
- Update pkg/term to 1.2.0
- Upgrade all dependencies to latest
- Update pkg/term module to latest and use unix.Termios
prompt.FuzzyFilter
for fuzzy matching at #92.OptionShowCompletionAtStart
to show completion at start at #100.prompt.NewStderrWriter
at #102.
- reset display attributes (please see pull #104 for more details).
- handle errors of Flush function in ConsoleWriter (please see pull #97 for more details).
- don't panic problem when reading from stdin before starting the prompt (please see issue #88 for more details).
prompt.NewStandardOutputWriter
-- please useprompt.NewStdoutWriter
.
- Support CJK (Chinese, Japanese and Korean) and Cyrillic characters.
OptionCompletionWordSeparator(x string)
to customize insertion points for completions.- To support this, text query functions by arbitrary word separator are added in
Document
(please see here for more details).
- To support this, text query functions by arbitrary word separator are added in
FilePathCompleter
to complete file path on your system.option
to customize ascii code key bindings.GetWordAfterCursor
method inDocument
.
prompt.Choose
shortcut function is deprecated.
It seems that windows support is almost perfect.- A critical bug is found :( When you change a terminal window size, the layout will be broken because current implementation cannot catch signal for updating window size on Windows.
- Shift + Tab handling on Windows.
- 4-dimension arrow keys handling on Windows.
- Support scrollbar when there are too many matched suggestions
- Support Windows (but please caution because this is still not perfect).
OptionLivePrefix
to update the prefix dynamically- Clear screen by Ctrl + L.
- Improve the Ctrl + W keybind.
- Don't panic because when running in a docker container (please see here for details).
- Don't panic when making terminal window small size after input 2 lines of texts. See here for details).
- Get rid of many bugs that layout is broken when using Terminal.app, GNU Terminal and a Goland(IntelliJ).
Initial Release