blink/internal/file/pipe.go

36 lines
549 B
Go
Raw Permalink Normal View History

2024-07-08 01:04:54 +00:00
package file
import (
"bufio"
"os"
"strings"
)
// Get the pipe
func Pipe() []string {
// Store lines
var lines []string
// Get pipe
pipe, _ := os.Stdin.Stat()
2024-07-08 01:06:55 +00:00
// Pipe found
2024-07-08 01:04:54 +00:00
if (pipe.Mode() & os.ModeCharDevice) == 0 {
// Create scanner
scanner := bufio.NewScanner(os.Stdin)
// Go through scanner
for scanner.Scan() {
// Store line
line := scanner.Text()
// Ignore empty & commented lines
if line != "" && !strings.HasPrefix(line, "#") {
2024-07-09 15:51:56 +00:00
lines = append(lines, strings.ToLower(line))
2024-07-08 01:04:54 +00:00
}
}
}
return lines
}