aboutsummaryrefslogtreecommitdiff
path: root/console.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-07 00:43:28 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-07 00:43:28 +0100
commit6fe6679b816cedbe1f007a1f036cc55ae9214492 (patch)
tree968241eaa55ef17f923d428ac26d7153bf392220 /console.go
parente995ee3c0b77708aa2b6f04a7c86a4ed4684d96a (diff)
...
Diffstat (limited to 'console.go')
-rw-r--r--console.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/console.go b/console.go
new file mode 100644
index 0000000..a29c4ad
--- /dev/null
+++ b/console.go
@@ -0,0 +1,30 @@
+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) {
+ return c.r.Read(p)
+}
+
+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()
+}