diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f760321..e0be9012 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2] - 29.07.2023 + +[Diff](https://github.com/elk-language/go-prompt/compare/v1.1.1...elk-language:go-prompt:v1.1.2) + +### Added +- `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` + ## [1.1.1] - 28.07.2023 [Diff](https://github.com/elk-language/go-prompt/compare/v1.1.0...elk-language:go-prompt:v1.1.1) diff --git a/buffer.go b/buffer.go index 5ae48152..e62057e9 100644 --- a/buffer.go +++ b/buffer.go @@ -188,7 +188,7 @@ func (b *Buffer) CursorDown(count int, columns istrings.Width, rows int) bool { return b.recalculateStartLine(columns, rows) } -// DeleteBeforeCursor delete specified number of graphemes before the cursor and returns the deleted text. +// Deletes the specified number of graphemes before the cursor and returns the deleted text. func (b *Buffer) DeleteBeforeCursor(count istrings.GraphemeNumber, columns istrings.Width, rows int) string { debug.Assert(count >= 0, "count should be positive") if b.cursorPosition < 0 { diff --git a/prompt.go b/prompt.go index 683aa7f9..17f214b6 100644 --- a/prompt.go +++ b/prompt.go @@ -152,6 +152,12 @@ func (p *Prompt) IndentSize() int { return p.renderer.indentSize } +// Get the number of columns that are available +// for user input. +func (p *Prompt) UserInputColumns() istrings.Width { + return p.renderer.UserInputColumns() +} + // Returns the current amount of columns that the terminal can display. func (p *Prompt) TerminalColumns() istrings.Width { return p.renderer.col @@ -621,6 +627,36 @@ func (p *Prompt) CursorDown(count int) bool { return false } +// Deletes the specified number of graphemes before the cursor and returns the deleted text. +func (p *Prompt) DeleteBeforeCursor(count istrings.GraphemeNumber) string { + return p.buffer.DeleteBeforeCursor(count, p.UserInputColumns(), p.renderer.row) +} + +// Deletes the specified number of runes before the cursor and returns the deleted text. +func (p *Prompt) DeleteBeforeCursorRunes(count istrings.RuneNumber) string { + return p.buffer.DeleteBeforeCursorRunes(count, p.UserInputColumns(), p.renderer.row) +} + +// Deletes the specified number of graphemes and returns the deleted text. +func (p *Prompt) Delete(count istrings.GraphemeNumber) string { + return p.buffer.Delete(count, p.UserInputColumns(), p.renderer.row) +} + +// Deletes the specified number of runes and returns the deleted text. +func (p *Prompt) DeleteRunes(count istrings.RuneNumber) string { + return p.buffer.DeleteRunes(count, p.UserInputColumns(), p.renderer.row) +} + +// Insert string into the buffer without moving the cursor. +func (p *Prompt) InsertText(text string, overwrite bool) { + p.buffer.InsertText(text, overwrite) +} + +// Insert string into the buffer and move the cursor. +func (p *Prompt) InsertTextMoveCursor(text string, overwrite bool) { + p.buffer.InsertTextMoveCursor(text, p.UserInputColumns(), p.renderer.row, overwrite) +} + func (p *Prompt) Close() { if !p.skipClose { debug.AssertNoError(p.reader.Close())