aboutsummaryrefslogtreecommitdiff
path: root/console.go
blob: 69082aeb5729e65f0d13ee6b4ed38fbc660f1dc9 (plain)
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
package j1

import (
	"io"
	"os"
)

type Console struct {
	r io.Reader
	w io.Writer
}

func NewConsole() *Console {
	return &Console{
		r: os.Stdin,
		w: os.Stdout,
	}
}

func (c *Console) Read(p []byte) (int, error) {
	n, err := c.r.Read(p)
	for i, v := range p {
		// replace nl with cr
		if v == 10 {
			p[i] = 13
		}
	}
	return n, err
}

func (c *Console) Write(p []byte) (int, error) {
	return c.w.Write(p)
}