aboutsummaryrefslogtreecommitdiff
path: root/console/console.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-24 01:59:13 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-24 01:59:13 +0100
commit565751db4e5b8370c0a05d1998a91e6e20a19bb4 (patch)
tree59ab8649b3e01da4c61a6f70269aaddacdf2eba9 /console/console.go
parent07584da73461b69043451ebe48fcac226202492a (diff)
remove context
Diffstat (limited to 'console/console.go')
-rw-r--r--console/console.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/console/console.go b/console/console.go
index 4fe9680..577e021 100644
--- a/console/console.go
+++ b/console/console.go
@@ -1,7 +1,6 @@
package console
import (
- "context"
"fmt"
"io"
"os"
@@ -11,36 +10,38 @@ type Console struct {
r io.Reader
w io.Writer
ich, och chan uint16
+ done chan struct{}
}
-func New(ctx context.Context) *Console {
+func New() *Console {
c := &Console{
- r: os.Stdin,
- w: os.Stdout,
- ich: make(chan uint16, 1),
- och: make(chan uint16, 1),
+ r: os.Stdin,
+ w: os.Stdout,
+ ich: make(chan uint16, 1),
+ och: make(chan uint16, 1),
+ done: make(chan struct{}),
}
- go c.read(ctx)
- go c.write(ctx)
+ go c.read()
+ go c.write()
return c
}
-func (c *Console) read(ctx context.Context) {
+func (c *Console) read() {
var v uint16
for {
fmt.Fscanf(c.r, "%c", &v)
select {
- case <-ctx.Done():
+ case <-c.done:
return
case c.ich <- v:
}
}
}
-func (c *Console) write(ctx context.Context) {
+func (c *Console) write() {
for {
select {
- case <-ctx.Done():
+ case <-c.done:
return
case v := <-c.och:
fmt.Fprintf(c.w, "%c", v)
@@ -51,3 +52,4 @@ func (c *Console) write(ctx context.Context) {
func (c *Console) Read() uint16 { return <-c.ich }
func (c *Console) Write(v uint16) { c.och <- v }
func (c *Console) Len() uint16 { return uint16(len(c.ich)) }
+func (c *Console) Stop() { close(c.done) }