ollama/readline/buffer.go

564 lines
12 KiB
Go
Raw Normal View History

2023-10-25 23:41:18 +00:00
package readline
import (
"fmt"
"os"
2023-10-25 23:41:18 +00:00
"github.com/emirpasic/gods/lists/arraylist"
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
"github.com/mattn/go-runewidth"
2023-10-25 23:41:18 +00:00
"golang.org/x/term"
)
type Buffer struct {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
DisplayPos int
Pos int
Buf *arraylist.List
//LineHasSpace is an arraylist of bools to keep track of whether a line has a space at the end
LineHasSpace *arraylist.List
Prompt *Prompt
LineWidth int
Width int
Height int
2023-10-25 23:41:18 +00:00
}
func NewBuffer(prompt *Prompt) (*Buffer, error) {
fd := int(os.Stdout.Fd())
2024-03-07 19:28:41 +00:00
width, height := 80, 24
if termWidth, termHeight, err := term.GetSize(fd); err == nil {
width, height = termWidth, termHeight
2023-10-25 23:41:18 +00:00
}
2024-01-06 00:19:37 +00:00
lwidth := width - len(prompt.prompt())
2023-10-25 23:41:18 +00:00
b := &Buffer{
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
DisplayPos: 0,
Pos: 0,
Buf: arraylist.New(),
LineHasSpace: arraylist.New(),
Prompt: prompt,
Width: width,
Height: height,
LineWidth: lwidth,
2023-10-25 23:41:18 +00:00
}
return b, nil
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
func (b *Buffer) GetLineSpacing(line int) bool {
hasSpace, _ := b.LineHasSpace.Get(line)
if hasSpace == nil {
return false
}
return hasSpace.(bool)
}
2023-10-25 23:41:18 +00:00
func (b *Buffer) MoveLeft() {
if b.Pos > 0 {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
//asserts that we retrieve a rune
if e, ok := b.Buf.Get(b.Pos - 1); ok {
if r, ok := e.(rune); ok {
rLength := runewidth.RuneWidth(r)
if b.DisplayPos%b.LineWidth == 0 {
fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
if rLength == 2 {
fmt.Print(CursorLeft)
}
line := b.DisplayPos/b.LineWidth - 1
hasSpace := b.GetLineSpacing(line)
if hasSpace {
b.DisplayPos -= 1
fmt.Print(CursorLeft)
}
} else {
fmt.Print(cursorLeftN(rLength))
}
b.Pos -= 1
b.DisplayPos -= rLength
}
2023-10-25 23:41:18 +00:00
}
}
}
func (b *Buffer) MoveLeftWord() {
if b.Pos > 0 {
var foundNonspace bool
for {
v, _ := b.Buf.Get(b.Pos - 1)
if v == ' ' {
if foundNonspace {
break
}
} else {
foundNonspace = true
}
b.MoveLeft()
if b.Pos == 0 {
break
}
}
}
}
func (b *Buffer) MoveRight() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.Pos < b.Buf.Size() {
if e, ok := b.Buf.Get(b.Pos); ok {
if r, ok := e.(rune); ok {
rLength := runewidth.RuneWidth(r)
b.Pos += 1
hasSpace := b.GetLineSpacing(b.DisplayPos / b.LineWidth)
b.DisplayPos += rLength
if b.DisplayPos%b.LineWidth == 0 {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
} else if (b.DisplayPos-rLength)%b.LineWidth == b.LineWidth-1 && hasSpace {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())+rLength))
b.DisplayPos += 1
} else if b.LineHasSpace.Size() > 0 && b.DisplayPos%b.LineWidth == b.LineWidth-1 && hasSpace {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
b.DisplayPos += 1
} else {
fmt.Print(cursorRightN(rLength))
}
}
2023-10-25 23:41:18 +00:00
}
}
}
func (b *Buffer) MoveRightWord() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.Pos < b.Buf.Size() {
2023-10-25 23:41:18 +00:00
for {
b.MoveRight()
v, _ := b.Buf.Get(b.Pos)
if v == ' ' {
break
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.Pos == b.Buf.Size() {
2023-10-25 23:41:18 +00:00
break
}
}
}
}
func (b *Buffer) MoveToStart() {
if b.Pos > 0 {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
currLine := b.DisplayPos / b.LineWidth
2023-10-25 23:41:18 +00:00
if currLine > 0 {
2024-05-22 05:21:04 +00:00
for range currLine {
fmt.Print(CursorUp)
2023-10-25 23:41:18 +00:00
}
}
2024-01-06 00:19:37 +00:00
fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())))
2023-10-25 23:41:18 +00:00
b.Pos = 0
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.DisplayPos = 0
2023-10-25 23:41:18 +00:00
}
}
func (b *Buffer) MoveToEnd() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.Pos < b.Buf.Size() {
currLine := b.DisplayPos / b.LineWidth
totalLines := b.DisplaySize() / b.LineWidth
2023-10-25 23:41:18 +00:00
if currLine < totalLines {
2024-05-22 05:21:04 +00:00
for range totalLines - currLine {
fmt.Print(CursorDown)
2023-10-25 23:41:18 +00:00
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
remainder := b.DisplaySize() % b.LineWidth
2024-01-06 00:19:37 +00:00
fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())+remainder))
2023-10-25 23:41:18 +00:00
} else {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Print(cursorRightN(b.DisplaySize() - b.DisplayPos))
2023-10-25 23:41:18 +00:00
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.Pos = b.Buf.Size()
b.DisplayPos = b.DisplaySize()
2023-10-25 23:41:18 +00:00
}
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
func (b *Buffer) DisplaySize() int {
sum := 0
2024-05-30 01:22:03 +00:00
for i := range b.Buf.Size() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if e, ok := b.Buf.Get(i); ok {
if r, ok := e.(rune); ok {
sum += runewidth.RuneWidth(r)
}
}
}
return sum
2023-10-25 23:41:18 +00:00
}
func (b *Buffer) Add(r rune) {
if b.Pos == b.Buf.Size() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.AddChar(r, false)
} else {
b.AddChar(r, true)
}
}
func (b *Buffer) AddChar(r rune, insert bool) {
rLength := runewidth.RuneWidth(r)
b.DisplayPos += rLength
if b.Pos > 0 {
if b.DisplayPos%b.LineWidth == 0 {
fmt.Printf("%c", r)
2023-10-25 23:41:18 +00:00
fmt.Printf("\n%s", b.Prompt.AltPrompt)
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if insert {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth-1, false)
} else {
b.LineHasSpace.Add(false)
}
// this case occurs when a double-width rune crosses the line boundary
} else if b.DisplayPos%b.LineWidth < (b.DisplayPos-rLength)%b.LineWidth {
if insert {
fmt.Print(ClearToEOL)
}
fmt.Printf("\n%s", b.Prompt.AltPrompt)
b.DisplayPos += 1
fmt.Printf("%c", r)
if insert {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth-1, true)
} else {
b.LineHasSpace.Add(true)
}
} else {
fmt.Printf("%c", r)
2023-10-25 23:41:18 +00:00
}
} else {
fmt.Printf("%c", r)
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
}
if insert {
2023-10-25 23:41:18 +00:00
b.Buf.Insert(b.Pos, r)
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
} else {
b.Buf.Add(r)
}
b.Pos += 1
if insert {
2023-10-25 23:41:18 +00:00
b.drawRemaining()
}
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
func (b *Buffer) countRemainingLineWidth(place int) int {
var sum int
counter := -1
var prevLen int
for place <= b.LineWidth {
counter += 1
sum += prevLen
if e, ok := b.Buf.Get(b.Pos + counter); ok {
if r, ok := e.(rune); ok {
place += runewidth.RuneWidth(r)
prevLen = len(string(r))
}
} else {
break
}
}
return sum
}
2023-10-25 23:41:18 +00:00
func (b *Buffer) drawRemaining() {
var place int
remainingText := b.StringN(b.Pos)
if b.Pos > 0 {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
place = b.DisplayPos % b.LineWidth
2023-10-25 23:41:18 +00:00
}
fmt.Print(CursorHide)
2023-10-25 23:41:18 +00:00
// render the rest of the current line
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
currLineLength := b.countRemainingLineWidth(place)
currLine := remainingText[:min(currLineLength, len(remainingText))]
currLineSpace := runewidth.StringWidth(currLine)
remLength := runewidth.StringWidth(remainingText)
2023-10-25 23:41:18 +00:00
if len(currLine) > 0 {
fmt.Printf(ClearToEOL + currLine)
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Print(cursorLeftN(currLineSpace))
2023-10-25 23:41:18 +00:00
} else {
fmt.Print(ClearToEOL)
2023-10-25 23:41:18 +00:00
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if currLineSpace != b.LineWidth-place && currLineSpace != remLength {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth, true)
} else if currLineSpace != b.LineWidth-place {
b.LineHasSpace.Remove(b.DisplayPos / b.LineWidth)
} else {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth, false)
}
if (b.DisplayPos+currLineSpace)%b.LineWidth == 0 && currLine == remainingText {
fmt.Print(cursorRightN(currLineSpace))
fmt.Printf("\n%s", b.Prompt.AltPrompt)
fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width-currLineSpace))
}
2023-10-25 23:41:18 +00:00
// render the other lines
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if remLength > currLineSpace {
remaining := (remainingText[len(currLine):])
2023-10-25 23:41:18 +00:00
var totalLines int
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
var displayLength int
var lineLength int = currLineSpace
for _, c := range remaining {
if displayLength == 0 || (displayLength+runewidth.RuneWidth(c))%b.LineWidth < displayLength%b.LineWidth {
2023-10-25 23:41:18 +00:00
fmt.Printf("\n%s", b.Prompt.AltPrompt)
totalLines += 1
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if displayLength != 0 {
if lineLength == b.LineWidth {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth+totalLines-1, false)
} else {
b.LineHasSpace.Set(b.DisplayPos/b.LineWidth+totalLines-1, true)
}
}
lineLength = 0
2023-10-25 23:41:18 +00:00
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
displayLength += runewidth.RuneWidth(c)
lineLength += runewidth.RuneWidth(c)
2023-10-25 23:41:18 +00:00
fmt.Printf("%c", c)
}
fmt.Print(ClearToEOL)
fmt.Print(cursorUpN(totalLines))
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Printf(CursorBOL + cursorRightN(b.Width-currLineSpace))
hasSpace := b.GetLineSpacing(b.DisplayPos / b.LineWidth)
if hasSpace && b.DisplayPos%b.LineWidth != b.LineWidth-1 {
fmt.Print(CursorLeft)
}
2023-10-25 23:41:18 +00:00
}
fmt.Print(CursorShow)
2023-10-25 23:41:18 +00:00
}
func (b *Buffer) Remove() {
if b.Buf.Size() > 0 && b.Pos > 0 {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if e, ok := b.Buf.Get(b.Pos - 1); ok {
if r, ok := e.(rune); ok {
rLength := runewidth.RuneWidth(r)
hasSpace := b.GetLineSpacing(b.DisplayPos/b.LineWidth - 1)
if b.DisplayPos%b.LineWidth == 0 {
// if the user backspaces over the word boundary, do this magic to clear the line
// and move to the end of the previous line
fmt.Printf(CursorBOL + ClearToEOL)
fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
if b.DisplaySize()%b.LineWidth < (b.DisplaySize()-rLength)%b.LineWidth {
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
}
if hasSpace {
b.DisplayPos -= 1
fmt.Print(CursorLeft)
}
if rLength == 2 {
fmt.Print(CursorLeft + " " + cursorLeftN(2))
} else {
fmt.Print(" " + CursorLeft)
}
} else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace {
fmt.Printf(CursorBOL + ClearToEOL)
fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
if b.Pos == b.Buf.Size() {
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
}
b.DisplayPos -= 1
} else {
fmt.Print(cursorLeftN(rLength))
2024-05-30 01:22:03 +00:00
for range rLength {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Print(" ")
}
fmt.Print(cursorLeftN(rLength))
}
var eraseExtraLine bool
if (b.DisplaySize()-1)%b.LineWidth == 0 || (rLength == 2 && ((b.DisplaySize()-2)%b.LineWidth == 0)) || b.DisplaySize()%b.LineWidth == 0 {
eraseExtraLine = true
}
2023-10-25 23:41:18 +00:00
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.Pos -= 1
b.DisplayPos -= rLength
b.Buf.Remove(b.Pos)
if b.Pos < b.Buf.Size() {
b.drawRemaining()
// this erases a line which is left over when backspacing in the middle of a line and there
// are trailing characters which go over the line width boundary
if eraseExtraLine {
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
fmt.Printf(cursorDownN(remainingLines+1) + CursorBOL + ClearToEOL)
place := b.DisplayPos % b.LineWidth
fmt.Printf(cursorUpN(remainingLines+1) + cursorRightN(place+len(b.Prompt.prompt())))
}
}
2023-10-25 23:41:18 +00:00
}
}
}
}
func (b *Buffer) Delete() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.Buf.Size() > 0 && b.Pos < b.Buf.Size() {
2023-10-25 23:41:18 +00:00
b.Buf.Remove(b.Pos)
b.drawRemaining()
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.DisplaySize()%b.LineWidth == 0 {
if b.DisplayPos != b.DisplaySize() {
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
2023-10-25 23:41:18 +00:00
fmt.Printf(cursorDownN(remainingLines) + CursorBOL + ClearToEOL)
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
place := b.DisplayPos % b.LineWidth
2024-01-06 00:19:37 +00:00
fmt.Printf(cursorUpN(remainingLines) + cursorRightN(place+len(b.Prompt.prompt())))
2023-10-25 23:41:18 +00:00
}
}
}
}
func (b *Buffer) DeleteBefore() {
if b.Pos > 0 {
for cnt := b.Pos - 1; cnt >= 0; cnt-- {
b.Remove()
}
}
}
func (b *Buffer) DeleteRemaining() {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
if b.DisplaySize() > 0 && b.Pos < b.DisplaySize() {
charsToDel := b.Buf.Size() - b.Pos
2024-05-22 05:21:04 +00:00
for range charsToDel {
2023-10-25 23:41:18 +00:00
b.Delete()
}
}
}
func (b *Buffer) DeleteWord() {
if b.Buf.Size() > 0 && b.Pos > 0 {
var foundNonspace bool
for {
v, _ := b.Buf.Get(b.Pos - 1)
if v == ' ' {
if !foundNonspace {
b.Remove()
} else {
break
}
} else {
foundNonspace = true
b.Remove()
}
if b.Pos == 0 {
break
}
}
}
}
func (b *Buffer) ClearScreen() {
2024-01-06 00:19:37 +00:00
fmt.Printf(ClearScreen + CursorReset + b.Prompt.prompt())
2023-10-25 23:41:18 +00:00
if b.IsEmpty() {
2024-01-06 00:19:37 +00:00
ph := b.Prompt.placeholder()
2023-10-25 23:41:18 +00:00
fmt.Printf(ColorGrey + ph + cursorLeftN(len(ph)) + ColorDefault)
} else {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
currPos := b.DisplayPos
currIndex := b.Pos
2023-10-25 23:41:18 +00:00
b.Pos = 0
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.DisplayPos = 0
2023-10-25 23:41:18 +00:00
b.drawRemaining()
2024-01-06 00:19:37 +00:00
fmt.Printf(CursorReset + cursorRightN(len(b.Prompt.prompt())))
2023-10-25 23:41:18 +00:00
if currPos > 0 {
targetLine := currPos / b.LineWidth
if targetLine > 0 {
2024-05-22 05:21:04 +00:00
for range targetLine {
fmt.Print(CursorDown)
2023-10-25 23:41:18 +00:00
}
}
remainder := currPos % b.LineWidth
if remainder > 0 {
fmt.Print(cursorRightN(remainder))
2023-10-25 23:41:18 +00:00
}
if currPos%b.LineWidth == 0 {
fmt.Printf(CursorBOL + b.Prompt.AltPrompt)
}
}
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.Pos = currIndex
b.DisplayPos = currPos
2023-10-25 23:41:18 +00:00
}
}
func (b *Buffer) IsEmpty() bool {
return b.Buf.Empty()
}
func (b *Buffer) Replace(r []rune) {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
b.DisplayPos = 0
2023-10-25 23:41:18 +00:00
b.Pos = 0
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
lineNums := b.DisplaySize() / b.LineWidth
2023-10-25 23:41:18 +00:00
b.Buf.Clear()
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Printf(CursorBOL + ClearToEOL)
2024-05-30 01:22:03 +00:00
for range lineNums {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
fmt.Print(CursorUp + CursorBOL + ClearToEOL)
}
fmt.Printf(CursorBOL + b.Prompt.prompt())
2023-10-25 23:41:18 +00:00
for _, c := range r {
b.Add(c)
}
}
func (b *Buffer) String() string {
return b.StringN(0)
}
func (b *Buffer) StringN(n int) string {
return b.StringNM(n, 0)
}
func (b *Buffer) StringNM(n, m int) string {
var s string
if m == 0 {
working on integration of multi-byte and multi-width runes (#4549) * integrated runewidth for display management - fixed cursor movement for mutli-width char * updated input and deletion of multi-byte chars * fixed line history with some exceptions * improved insert and add * fixed issues with moving across lines * end of line extra space tracking' * saved changes * fixed end of line issues with empty spaces * worked some more * worked on end of line * fixed failed test * fixed minor inserting bug * fixed movement hotkeys * adjusted hotkeys * removed comments * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * Update readline/buffer.go Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com> * deleted comments and duplicate code * removed duplicate code * added comments, refactored add function to use addChar * added helper to retrieve lineSpacing, renamed lineFlags for clarity * fixed remove() --------- Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
2024-05-28 19:04:03 +00:00
m = b.Buf.Size()
2023-10-25 23:41:18 +00:00
}
for cnt := n; cnt < m; cnt++ {
c, _ := b.Buf.Get(cnt)
s += string(c.(rune))
}
return s
}
func cursorLeftN(n int) string {
return fmt.Sprintf(CursorLeftN, n)
}
func cursorRightN(n int) string {
return fmt.Sprintf(CursorRightN, n)
}
func cursorUpN(n int) string {
return fmt.Sprintf(CursorUpN, n)
}
func cursorDownN(n int) string {
return fmt.Sprintf(CursorDownN, n)
}