From 5d77e48b7b194122449d1edc986c6705eb785f2b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 24 Jan 2018 02:15:19 +0100 Subject: simplify --- console/console.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/console/console.go b/console/console.go index 577e021..dde2b3b 100644 --- a/console/console.go +++ b/console/console.go @@ -7,29 +7,25 @@ import ( ) type Console struct { - r io.Reader - w io.Writer ich, och chan uint16 done chan struct{} } func New() *Console { c := &Console{ - r: os.Stdin, - w: os.Stdout, ich: make(chan uint16, 1), och: make(chan uint16, 1), done: make(chan struct{}), } - go c.read() - go c.write() + go c.read(os.Stdin) + go c.write(os.Stdout) return c } -func (c *Console) read() { +func (c *Console) read(r io.Reader) { var v uint16 for { - fmt.Fscanf(c.r, "%c", &v) + fmt.Fscanf(r, "%c", &v) select { case <-c.done: return @@ -38,13 +34,13 @@ func (c *Console) read() { } } -func (c *Console) write() { +func (c *Console) write(w io.Writer) { for { select { case <-c.done: return case v := <-c.och: - fmt.Fprintf(c.w, "%c", v) + fmt.Fprintf(w, "%c", v) } } } -- cgit v1.2.3