aboutsummaryrefslogtreecommitdiff
path: root/console.go
blob: 388b207f44e3efa035e01705c5483e669c34e49d (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
34
package j1

import (
	"bufio"
	"os"
)

type Console struct {
	r *bufio.Reader
	w *bufio.Writer
}

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

func (c *Console) Read(p []byte) (int, error) {
	n, err := c.r.Read(p)
	if n > 0 && p[0] == 10 {
		p[0] = 13
	}
	return n, err
}

func (c *Console) Write(p []byte) (int, error) {
	n, err := c.w.Write(p)
	if err != nil {
		return 0, err
	}
	return n, c.w.Flush()
}