init: basic tools

This commit is contained in:
2025-08-30 22:00:31 +03:00
commit ec5db88f97
13 changed files with 467 additions and 0 deletions

37
input_stdin.go Normal file
View File

@@ -0,0 +1,37 @@
package script
import (
"bufio"
"context"
"io"
"os"
"strings"
)
// StdinReader reads from stdin
type StdinReader struct {
scanner bufio.Scanner
}
func NewStdinReader() *StdinReader {
return &StdinReader{
scanner: *bufio.NewScanner(os.Stdin),
}
}
// Read reads from stdin until \n character
// then splits result at "," separator and returns
// the resulting slice.
// It returns EOF when nothing left to read.
func (s *StdinReader) Read(_ context.Context) ([]string, error) {
if !s.scanner.Scan() {
err := s.scanner.Err()
if err == nil {
return nil, io.EOF
}
return nil, err
}
return strings.Split(s.scanner.Text(), ","), nil
}