-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (41 loc) · 997 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"os"
"moul.io/ansicat/ansicat"
)
const (
defaultRateLimit = 7000 // bytes per second
defaultChunkSize = 1024 // bytes
)
func main() {
// Define command-line flags
rateLimit := flag.Int("rate-limit", defaultRateLimit, "Rate limit in bytes per second (0 for no limit)")
chunkSize := flag.Int("chunk-size", defaultChunkSize, "Chunk size in bytes")
flag.Parse()
if flag.NArg() < 1 {
fmt.Println("Usage: go run main.go [--rate-limit=<bytes per second>] [--chunk-size=<bytes>] <filename>")
return
}
filename := flag.Arg(0)
var file *os.File
var err error
if filename == "-" {
// Read from stdin
file = os.Stdin
} else {
// Open file
file, err = os.Open(filename)
if err != nil {
fmt.Printf("Error opening file: %v\n", err)
return
}
defer file.Close()
}
// Process the ANSI file
err = ansicat.ProcessFile(file, os.Stdout, *rateLimit, *chunkSize)
if err != nil {
fmt.Printf("Error processing file: %v\n", err)
}
}