|
@@ -25,10 +25,7 @@ func NewBuffer(prompt *Prompt) (*Buffer, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- lwidth := width - len(prompt.Prompt)
|
|
|
|
- if prompt.UseAlt {
|
|
|
|
- lwidth = width - len(prompt.AltPrompt)
|
|
|
|
- }
|
|
|
|
|
|
+ lwidth := width - len(prompt.prompt())
|
|
|
|
|
|
b := &Buffer{
|
|
b := &Buffer{
|
|
Pos: 0,
|
|
Pos: 0,
|
|
@@ -78,7 +75,7 @@ func (b *Buffer) MoveRight() {
|
|
if b.Pos < b.Size() {
|
|
if b.Pos < b.Size() {
|
|
b.Pos += 1
|
|
b.Pos += 1
|
|
if b.Pos%b.LineWidth == 0 {
|
|
if b.Pos%b.LineWidth == 0 {
|
|
- fmt.Printf(CursorDown + CursorBOL + cursorRightN(b.PromptSize()))
|
|
|
|
|
|
+ fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
|
|
} else {
|
|
} else {
|
|
fmt.Print(CursorRight)
|
|
fmt.Print(CursorRight)
|
|
}
|
|
}
|
|
@@ -109,7 +106,7 @@ func (b *Buffer) MoveToStart() {
|
|
fmt.Print(CursorUp)
|
|
fmt.Print(CursorUp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- fmt.Printf(CursorBOL + cursorRightN(b.PromptSize()))
|
|
|
|
|
|
+ fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())))
|
|
b.Pos = 0
|
|
b.Pos = 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -123,7 +120,7 @@ func (b *Buffer) MoveToEnd() {
|
|
fmt.Print(CursorDown)
|
|
fmt.Print(CursorDown)
|
|
}
|
|
}
|
|
remainder := b.Size() % b.LineWidth
|
|
remainder := b.Size() % b.LineWidth
|
|
- fmt.Printf(CursorBOL + cursorRightN(b.PromptSize()+remainder))
|
|
|
|
|
|
+ fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())+remainder))
|
|
} else {
|
|
} else {
|
|
fmt.Print(cursorRightN(b.Size() - b.Pos))
|
|
fmt.Print(cursorRightN(b.Size() - b.Pos))
|
|
}
|
|
}
|
|
@@ -143,13 +140,6 @@ func min(n, m int) int {
|
|
return n
|
|
return n
|
|
}
|
|
}
|
|
|
|
|
|
-func (b *Buffer) PromptSize() int {
|
|
|
|
- if b.Prompt.UseAlt {
|
|
|
|
- return len(b.Prompt.AltPrompt)
|
|
|
|
- }
|
|
|
|
- return len(b.Prompt.Prompt)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (b *Buffer) Add(r rune) {
|
|
func (b *Buffer) Add(r rune) {
|
|
if b.Pos == b.Buf.Size() {
|
|
if b.Pos == b.Buf.Size() {
|
|
fmt.Printf("%c", r)
|
|
fmt.Printf("%c", r)
|
|
@@ -232,7 +222,7 @@ func (b *Buffer) Remove() {
|
|
remainingLines := (b.Size() - b.Pos) / b.LineWidth
|
|
remainingLines := (b.Size() - b.Pos) / b.LineWidth
|
|
fmt.Printf(cursorDownN(remainingLines+1) + CursorBOL + ClearToEOL)
|
|
fmt.Printf(cursorDownN(remainingLines+1) + CursorBOL + ClearToEOL)
|
|
place := b.Pos % b.LineWidth
|
|
place := b.Pos % b.LineWidth
|
|
- fmt.Printf(cursorUpN(remainingLines+1) + cursorRightN(place+len(b.Prompt.Prompt)))
|
|
|
|
|
|
+ fmt.Printf(cursorUpN(remainingLines+1) + cursorRightN(place+len(b.Prompt.prompt())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -247,7 +237,7 @@ func (b *Buffer) Delete() {
|
|
remainingLines := (b.Size() - b.Pos) / b.LineWidth
|
|
remainingLines := (b.Size() - b.Pos) / b.LineWidth
|
|
fmt.Printf(cursorDownN(remainingLines) + CursorBOL + ClearToEOL)
|
|
fmt.Printf(cursorDownN(remainingLines) + CursorBOL + ClearToEOL)
|
|
place := b.Pos % b.LineWidth
|
|
place := b.Pos % b.LineWidth
|
|
- fmt.Printf(cursorUpN(remainingLines) + cursorRightN(place+len(b.Prompt.Prompt)))
|
|
|
|
|
|
+ fmt.Printf(cursorUpN(remainingLines) + cursorRightN(place+len(b.Prompt.prompt())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -294,15 +284,15 @@ func (b *Buffer) DeleteWord() {
|
|
}
|
|
}
|
|
|
|
|
|
func (b *Buffer) ClearScreen() {
|
|
func (b *Buffer) ClearScreen() {
|
|
- fmt.Printf(ClearScreen + CursorReset + b.Prompt.Prompt)
|
|
|
|
|
|
+ fmt.Printf(ClearScreen + CursorReset + b.Prompt.prompt())
|
|
if b.IsEmpty() {
|
|
if b.IsEmpty() {
|
|
- ph := b.Prompt.Placeholder
|
|
|
|
|
|
+ ph := b.Prompt.placeholder()
|
|
fmt.Printf(ColorGrey + ph + cursorLeftN(len(ph)) + ColorDefault)
|
|
fmt.Printf(ColorGrey + ph + cursorLeftN(len(ph)) + ColorDefault)
|
|
} else {
|
|
} else {
|
|
currPos := b.Pos
|
|
currPos := b.Pos
|
|
b.Pos = 0
|
|
b.Pos = 0
|
|
b.drawRemaining()
|
|
b.drawRemaining()
|
|
- fmt.Printf(CursorReset + cursorRightN(len(b.Prompt.Prompt)))
|
|
|
|
|
|
+ fmt.Printf(CursorReset + cursorRightN(len(b.Prompt.prompt())))
|
|
if currPos > 0 {
|
|
if currPos > 0 {
|
|
targetLine := currPos / b.LineWidth
|
|
targetLine := currPos / b.LineWidth
|
|
if targetLine > 0 {
|
|
if targetLine > 0 {
|
|
@@ -329,7 +319,7 @@ func (b *Buffer) IsEmpty() bool {
|
|
func (b *Buffer) Replace(r []rune) {
|
|
func (b *Buffer) Replace(r []rune) {
|
|
b.Pos = 0
|
|
b.Pos = 0
|
|
b.Buf.Clear()
|
|
b.Buf.Clear()
|
|
- fmt.Printf(ClearLine + CursorBOL + b.Prompt.Prompt)
|
|
|
|
|
|
+ fmt.Printf(ClearLine + CursorBOL + b.Prompt.prompt())
|
|
for _, c := range r {
|
|
for _, c := range r {
|
|
b.Add(c)
|
|
b.Add(c)
|
|
}
|
|
}
|