Source File
bc.go
Belonging Package
src.elv.sh/cmd/examples/e3bc/bc
package bcimport ()type Bc interface {Exec(string) errorQuit()}type bc struct {cmd *exec.Cmdstdin io.WriteCloserstdout io.ReadCloser}func () Bc {:= exec.Command("bc"), := .StdinPipe()if != nil {log.Fatal()}, := .StdoutPipe()if != nil {log.Fatal()}.Stderr = os.Stderr.Start()return &bc{, , }}// TODO: Use a more robust markervar inputSuffix = []byte("\n\"\x04\"\n")func ( *bc) ( string) error {.stdin.Write([]byte()).stdin.Write(inputSuffix)for {, := readByte(.stdout)if != nil {return}if == 0x04 {break}os.Stdout.Write([]byte{})}return nil}func ( io.Reader) (byte, error) {var [1]byte, := .Read([:])if != nil {return 0,}return [0], nil}func ( *bc) () {.stdin.Close().cmd.Wait().stdout.Close()}
The pages are generated with Golds v0.2.8-preview. (GOOS=darwin GOARCH=arm64)