github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/types/csv-bad/index.go (about) 1 package csvbad 2 3 import ( 4 "github.com/lmorg/murex/lang" 5 ) 6 7 func readIndex(p *lang.Process, params []string) error { 8 cRecords := make(chan []string, 1) 9 10 csvParser, err := NewParser(p.Stdin, p.Config) 11 if err != nil { 12 return err 13 } 14 15 go func() { 16 var headingsPrinted bool 17 err := csvParser.ReadLine(func(recs []string, headings []string) { 18 if !headingsPrinted { 19 cRecords <- headings 20 headingsPrinted = true 21 } 22 cRecords <- recs 23 }) 24 if err != nil { 25 //ansi.Stderrln(p, ansi.FgRed, err.Error()) 26 p.Stderr.Writeln([]byte(err.Error())) 27 } 28 close(cRecords) 29 }() 30 31 return lang.IndexTemplateTable(p, params, cRecords, csvParser.ArrayToCsv) 32 }