-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra.go
46 lines (40 loc) · 949 Bytes
/
extra.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package remote_cli
func (c *Cli) handleExtraChars(output string) string {
bytes := []byte(output)
newBytes := []byte{}
for i := range bytes {
// remove '\r''s
if bytes[i] == 13 {
continue
}
// find ^@ (\0 char) ; remove whole string before up to prev. \n
//fmt.Printf("%d | %s\n", bytes[i], string(bytes[i]))
if bytes[i] == 0 {
//fmt.Printf("-- GOT CHAR ZERO --\n")
if i == 1 {
continue
}
upToLineBreak:
for j := i-1; j > 0; j-- {
//fmt.Printf("-- PREV CHAR = %d (%s)", bytes[j], string(bytes[j]))
if bytes[j] != '\n' && bytes[j] != 0 {
//remove 'j' byte
newBytes = newBytes[:len(newBytes)-1]
} else {
break upToLineBreak
}
}
continue
}
// find backspaces, remove them and prev.chars
if bytes[i] == 8 {
if i == 1 {
continue
}
newBytes = newBytes[:len(newBytes)-1]
continue
}
newBytes = append(newBytes, bytes[i])
}
return string(newBytes)
}