-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-chunk-reader.go
56 lines (46 loc) · 1.5 KB
/
post-chunk-reader.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
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"io"
"os"
)
func main() {
buffer := make([]byte, 1024) // Adjust buffer size as needed
for {
n, err := os.Stdin.Read(buffer)
if err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "Error reading from stdin: %v\n", err)
os.Exit(1)
}
if n > 0 {
//The inserted color by batcat creates much larger 'words' when colored.
// fmt.Printf("Size: %d",n);
bufferAsString := buffer[:n]
// words := strings.Split(bufferAsString)
// for _, word := range words {
// if (len(word) <= 20) {
// bufferAsString = strings.Replace(bufferAsString,word+"\n",word)
// }
// }
//All received input is new-line ended.
//strip newline from small
lenBuf := len(bufferAsString)
if ( (lenBuf>1 || bufferAsString[0] != '\n') && bufferAsString[lenBuf-1] == '\n' ) {
bufferAsString = bufferAsString[:lenBuf-1]
}
// Write the chunk
os.Stdout.Write(bufferAsString)
os.Stdout.Sync()
// if ( n > 20 ) {
// fmt.Println()
// } else {
// os.Stdout.WriteString("\x03")
// // Ensure it's flushed to stdout
// os.Stdout.Sync()
// }
}
}
}