Skip to content

Commit

Permalink
translate tabs into double spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed Jul 11, 2023
1 parent facef81 commit aaad8c4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,20 @@ func (p *Prompt) readBuffer(bufCh chan []byte, stopCh chan struct{}) {
}
bytes = bytes[:n]
if len(bytes) != 1 || bytes[0] != 0 {
newBytes := make([]byte, len(bytes))
for i, byt := range bytes {
newBytes := make([]byte, 0, len(bytes))
for _, byt := range bytes {
switch byt {
// translate raw mode \r into \n
// to make pasting multiline text
// work properly
switch byt {
case '\r':
newBytes[i] = '\n'
newBytes = append(newBytes, '\n')
// translate \t into two spaces
// to avoid problems with cursor positions
case '\t':
newBytes = append(newBytes, ' ', ' ')
default:
newBytes[i] = byt
newBytes = append(newBytes, byt)
}
}
bufCh <- newBytes
Expand Down

0 comments on commit aaad8c4

Please sign in to comment.