|
@@ -62,7 +62,7 @@ func (b *Buffer) MoveLeft() {
|
|
rLength := runewidth.RuneWidth(r)
|
|
rLength := runewidth.RuneWidth(r)
|
|
|
|
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
- fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
|
|
|
|
|
|
+ fmt.Print(CursorUp + CursorBOL + CursorRightN(b.Width))
|
|
if rLength == 2 {
|
|
if rLength == 2 {
|
|
fmt.Print(CursorLeft)
|
|
fmt.Print(CursorLeft)
|
|
}
|
|
}
|
|
@@ -74,7 +74,7 @@ func (b *Buffer) MoveLeft() {
|
|
fmt.Print(CursorLeft)
|
|
fmt.Print(CursorLeft)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Print(cursorLeftN(rLength))
|
|
|
|
|
|
+ fmt.Print(CursorLeftN(rLength))
|
|
}
|
|
}
|
|
|
|
|
|
b.Pos -= 1
|
|
b.Pos -= 1
|
|
@@ -115,15 +115,15 @@ func (b *Buffer) MoveRight() {
|
|
b.DisplayPos += rLength
|
|
b.DisplayPos += rLength
|
|
|
|
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
- fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(CursorDown + CursorBOL + CursorRightN(len(b.Prompt.prompt())))
|
|
} else if (b.DisplayPos-rLength)%b.LineWidth == b.LineWidth-1 && hasSpace {
|
|
} else if (b.DisplayPos-rLength)%b.LineWidth == b.LineWidth-1 && hasSpace {
|
|
- fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())+rLength))
|
|
|
|
|
|
+ fmt.Print(CursorDown + CursorBOL + CursorRightN(len(b.Prompt.prompt())+rLength))
|
|
b.DisplayPos += 1
|
|
b.DisplayPos += 1
|
|
} else if b.LineHasSpace.Size() > 0 && b.DisplayPos%b.LineWidth == b.LineWidth-1 && hasSpace {
|
|
} else if b.LineHasSpace.Size() > 0 && b.DisplayPos%b.LineWidth == b.LineWidth-1 && hasSpace {
|
|
- fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(CursorDown + CursorBOL + CursorRightN(len(b.Prompt.prompt())))
|
|
b.DisplayPos += 1
|
|
b.DisplayPos += 1
|
|
} else {
|
|
} else {
|
|
- fmt.Print(cursorRightN(rLength))
|
|
|
|
|
|
+ fmt.Print(CursorRightN(rLength))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -154,7 +154,7 @@ func (b *Buffer) MoveToStart() {
|
|
fmt.Print(CursorUp)
|
|
fmt.Print(CursorUp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(CursorBOL + CursorRightN(len(b.Prompt.prompt())))
|
|
b.Pos = 0
|
|
b.Pos = 0
|
|
b.DisplayPos = 0
|
|
b.DisplayPos = 0
|
|
}
|
|
}
|
|
@@ -169,9 +169,9 @@ func (b *Buffer) MoveToEnd() {
|
|
fmt.Print(CursorDown)
|
|
fmt.Print(CursorDown)
|
|
}
|
|
}
|
|
remainder := b.DisplaySize() % b.LineWidth
|
|
remainder := b.DisplaySize() % b.LineWidth
|
|
- fmt.Printf(CursorBOL + cursorRightN(len(b.Prompt.prompt())+remainder))
|
|
|
|
|
|
+ fmt.Print(CursorBOL + CursorRightN(len(b.Prompt.prompt())+remainder))
|
|
} else {
|
|
} else {
|
|
- fmt.Print(cursorRightN(b.DisplaySize() - b.DisplayPos))
|
|
|
|
|
|
+ fmt.Print(CursorRightN(b.DisplaySize() - b.DisplayPos))
|
|
}
|
|
}
|
|
|
|
|
|
b.Pos = b.Buf.Size()
|
|
b.Pos = b.Buf.Size()
|
|
@@ -286,8 +286,7 @@ func (b *Buffer) drawRemaining() {
|
|
remLength := runewidth.StringWidth(remainingText)
|
|
remLength := runewidth.StringWidth(remainingText)
|
|
|
|
|
|
if len(currLine) > 0 {
|
|
if len(currLine) > 0 {
|
|
- fmt.Printf(ClearToEOL + currLine)
|
|
|
|
- fmt.Print(cursorLeftN(currLineSpace))
|
|
|
|
|
|
+ fmt.Print(ClearToEOL + currLine + CursorLeftN(currLineSpace))
|
|
} else {
|
|
} else {
|
|
fmt.Print(ClearToEOL)
|
|
fmt.Print(ClearToEOL)
|
|
}
|
|
}
|
|
@@ -301,9 +300,9 @@ func (b *Buffer) drawRemaining() {
|
|
}
|
|
}
|
|
|
|
|
|
if (b.DisplayPos+currLineSpace)%b.LineWidth == 0 && currLine == remainingText {
|
|
if (b.DisplayPos+currLineSpace)%b.LineWidth == 0 && currLine == remainingText {
|
|
- fmt.Print(cursorRightN(currLineSpace))
|
|
|
|
|
|
+ fmt.Print(CursorRightN(currLineSpace))
|
|
fmt.Printf("\n%s", b.Prompt.AltPrompt)
|
|
fmt.Printf("\n%s", b.Prompt.AltPrompt)
|
|
- fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width-currLineSpace))
|
|
|
|
|
|
+ fmt.Print(CursorUp + CursorBOL + CursorRightN(b.Width-currLineSpace))
|
|
}
|
|
}
|
|
|
|
|
|
// render the other lines
|
|
// render the other lines
|
|
@@ -333,9 +332,7 @@ func (b *Buffer) drawRemaining() {
|
|
lineLength += runewidth.RuneWidth(c)
|
|
lineLength += runewidth.RuneWidth(c)
|
|
fmt.Printf("%c", c)
|
|
fmt.Printf("%c", c)
|
|
}
|
|
}
|
|
- fmt.Print(ClearToEOL)
|
|
|
|
- fmt.Print(cursorUpN(totalLines))
|
|
|
|
- fmt.Printf(CursorBOL + cursorRightN(b.Width-currLineSpace))
|
|
|
|
|
|
+ fmt.Print(ClearToEOL + CursorUpN(totalLines) + CursorBOL + CursorRightN(b.Width-currLineSpace))
|
|
|
|
|
|
hasSpace := b.GetLineSpacing(b.DisplayPos / b.LineWidth)
|
|
hasSpace := b.GetLineSpacing(b.DisplayPos / b.LineWidth)
|
|
|
|
|
|
@@ -357,8 +354,7 @@ func (b *Buffer) Remove() {
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
if b.DisplayPos%b.LineWidth == 0 {
|
|
// if the user backspaces over the word boundary, do this magic to clear the line
|
|
// if the user backspaces over the word boundary, do this magic to clear the line
|
|
// and move to the end of the previous line
|
|
// and move to the end of the previous line
|
|
- fmt.Printf(CursorBOL + ClearToEOL)
|
|
|
|
- fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
|
|
|
|
|
|
+ fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width))
|
|
|
|
|
|
if b.DisplaySize()%b.LineWidth < (b.DisplaySize()-rLength)%b.LineWidth {
|
|
if b.DisplaySize()%b.LineWidth < (b.DisplaySize()-rLength)%b.LineWidth {
|
|
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
|
|
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
|
|
@@ -370,24 +366,23 @@ func (b *Buffer) Remove() {
|
|
}
|
|
}
|
|
|
|
|
|
if rLength == 2 {
|
|
if rLength == 2 {
|
|
- fmt.Print(CursorLeft + " " + cursorLeftN(2))
|
|
|
|
|
|
+ fmt.Print(CursorLeft + " " + CursorLeftN(2))
|
|
} else {
|
|
} else {
|
|
fmt.Print(" " + CursorLeft)
|
|
fmt.Print(" " + CursorLeft)
|
|
}
|
|
}
|
|
} else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace {
|
|
} else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace {
|
|
- fmt.Printf(CursorBOL + ClearToEOL)
|
|
|
|
- fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
|
|
|
|
|
|
+ fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width))
|
|
|
|
|
|
if b.Pos == b.Buf.Size() {
|
|
if b.Pos == b.Buf.Size() {
|
|
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
|
|
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
|
|
}
|
|
}
|
|
b.DisplayPos -= 1
|
|
b.DisplayPos -= 1
|
|
} else {
|
|
} else {
|
|
- fmt.Print(cursorLeftN(rLength))
|
|
|
|
|
|
+ fmt.Print(CursorLeftN(rLength))
|
|
for range rLength {
|
|
for range rLength {
|
|
fmt.Print(" ")
|
|
fmt.Print(" ")
|
|
}
|
|
}
|
|
- fmt.Print(cursorLeftN(rLength))
|
|
|
|
|
|
+ fmt.Print(CursorLeftN(rLength))
|
|
}
|
|
}
|
|
|
|
|
|
var eraseExtraLine bool
|
|
var eraseExtraLine bool
|
|
@@ -405,9 +400,9 @@ func (b *Buffer) Remove() {
|
|
// are trailing characters which go over the line width boundary
|
|
// are trailing characters which go over the line width boundary
|
|
if eraseExtraLine {
|
|
if eraseExtraLine {
|
|
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
|
|
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
|
|
- fmt.Printf(cursorDownN(remainingLines+1) + CursorBOL + ClearToEOL)
|
|
|
|
|
|
+ fmt.Print(CursorDownN(remainingLines+1) + CursorBOL + ClearToEOL)
|
|
place := b.DisplayPos % b.LineWidth
|
|
place := b.DisplayPos % b.LineWidth
|
|
- fmt.Printf(cursorUpN(remainingLines+1) + cursorRightN(place+len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(CursorUpN(remainingLines+1) + CursorRightN(place+len(b.Prompt.prompt())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -422,9 +417,9 @@ func (b *Buffer) Delete() {
|
|
if b.DisplaySize()%b.LineWidth == 0 {
|
|
if b.DisplaySize()%b.LineWidth == 0 {
|
|
if b.DisplayPos != b.DisplaySize() {
|
|
if b.DisplayPos != b.DisplaySize() {
|
|
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
|
|
remainingLines := (b.DisplaySize() - b.DisplayPos) / b.LineWidth
|
|
- fmt.Printf(cursorDownN(remainingLines) + CursorBOL + ClearToEOL)
|
|
|
|
|
|
+ fmt.Print(CursorDownN(remainingLines) + CursorBOL + ClearToEOL)
|
|
place := b.DisplayPos % b.LineWidth
|
|
place := b.DisplayPos % b.LineWidth
|
|
- fmt.Printf(cursorUpN(remainingLines) + cursorRightN(place+len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(CursorUpN(remainingLines) + CursorRightN(place+len(b.Prompt.prompt())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -471,17 +466,17 @@ func (b *Buffer) DeleteWord() {
|
|
}
|
|
}
|
|
|
|
|
|
func (b *Buffer) ClearScreen() {
|
|
func (b *Buffer) ClearScreen() {
|
|
- fmt.Printf(ClearScreen + CursorReset + b.Prompt.prompt())
|
|
|
|
|
|
+ fmt.Print(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.Print(ColorGrey + ph + CursorLeftN(len(ph)) + ColorDefault)
|
|
} else {
|
|
} else {
|
|
currPos := b.DisplayPos
|
|
currPos := b.DisplayPos
|
|
currIndex := b.Pos
|
|
currIndex := b.Pos
|
|
b.Pos = 0
|
|
b.Pos = 0
|
|
b.DisplayPos = 0
|
|
b.DisplayPos = 0
|
|
b.drawRemaining()
|
|
b.drawRemaining()
|
|
- fmt.Printf(CursorReset + cursorRightN(len(b.Prompt.prompt())))
|
|
|
|
|
|
+ fmt.Print(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 {
|
|
@@ -491,10 +486,10 @@ func (b *Buffer) ClearScreen() {
|
|
}
|
|
}
|
|
remainder := currPos % b.LineWidth
|
|
remainder := currPos % b.LineWidth
|
|
if remainder > 0 {
|
|
if remainder > 0 {
|
|
- fmt.Print(cursorRightN(remainder))
|
|
|
|
|
|
+ fmt.Print(CursorRightN(remainder))
|
|
}
|
|
}
|
|
if currPos%b.LineWidth == 0 {
|
|
if currPos%b.LineWidth == 0 {
|
|
- fmt.Printf(CursorBOL + b.Prompt.AltPrompt)
|
|
|
|
|
|
+ fmt.Print(CursorBOL + b.Prompt.AltPrompt)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
b.Pos = currIndex
|
|
b.Pos = currIndex
|
|
@@ -513,13 +508,13 @@ func (b *Buffer) Replace(r []rune) {
|
|
|
|
|
|
b.Buf.Clear()
|
|
b.Buf.Clear()
|
|
|
|
|
|
- fmt.Printf(CursorBOL + ClearToEOL)
|
|
|
|
|
|
+ fmt.Print(CursorBOL + ClearToEOL)
|
|
|
|
|
|
for range lineNums {
|
|
for range lineNums {
|
|
fmt.Print(CursorUp + CursorBOL + ClearToEOL)
|
|
fmt.Print(CursorUp + CursorBOL + ClearToEOL)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf(CursorBOL + b.Prompt.prompt())
|
|
|
|
|
|
+ fmt.Print(CursorBOL + b.Prompt.prompt())
|
|
|
|
|
|
for _, c := range r {
|
|
for _, c := range r {
|
|
b.Add(c)
|
|
b.Add(c)
|
|
@@ -545,19 +540,3 @@ func (b *Buffer) StringNM(n, m int) string {
|
|
}
|
|
}
|
|
return s
|
|
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)
|
|
|
|
-}
|
|
|