lib/standard: Stdin/out/err now part of Sys.
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 2 May 2014 19:00:10 +0000 (15:00 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 2 May 2014 19:05:39 +0000 (15:05 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

examples/leapfrog/leapfrog_curses.nit
lib/a_star.nit
lib/nitcc_runtime.nit
lib/standard/file.nit
src/naive_interpreter.nit
src/nitx.nit
src/parser_util.nit
src/toolcontext.nit

index 0420277..da05bf8 100644 (file)
@@ -121,9 +121,9 @@ redef class PlayScene
                sys.nanosleep(0, 48000000)
 
                # Keyboard input
-               while stdin.poll_in do
-                       if stdin.eof then return
-                       var c = stdin.read_char
+               while sys.stdin.poll_in do
+                       if sys.stdin.eof then return
+                       var c = sys.stdin.read_char
                        if c == 'q'.ascii then
                                self.exists = false
                                return
index 2f18583..c6f6329 100644 (file)
@@ -58,7 +58,7 @@ module a_star
 redef class Object
        protected fun debug_a_star: Bool do return false
        private fun debug(msg: String) do if debug_a_star then
-               stderr.write "a_star debug: {msg}\n"
+               sys.stderr.write "a_star debug: {msg}\n"
        end
 end
 
index 5f05815..3e77c20 100644 (file)
@@ -550,7 +550,7 @@ abstract class TestParser
                var filepath = args.shift
                var text
                if filepath == "-" then
-                       text = stdin.read_all
+                       text = sys.stdin.read_all
                else if filepath == "-e" then
                        if args.is_empty then
                                print "Error: -e need a text"
index ebe06c2..27b2626 100644 (file)
@@ -34,26 +34,26 @@ redef class Object
        # Print `objects` on the standard output (`stdout`).
        protected fun printn(objects: Object...)
        do
-               stdout.write(objects.to_s)
+               sys.stdout.write(objects.to_s)
        end
 
        # Print an `object` on the standard output (`stdout`) and add a newline.
        protected fun print(object: Object)
        do
-               stdout.write(object.to_s)
-               stdout.write("\n")
+               sys.stdout.write(object.to_s)
+               sys.stdout.write("\n")
        end
 
        # Read a character from the standard input (`stdin`).
        protected fun getc: Char
        do
-               return stdin.read_char.ascii
+               return sys.stdin.read_char.ascii
        end
 
        # Read a line from the standard input (`stdin`).
        protected fun gets: String
        do
-               return stdin.read_line
+               return sys.stdin.read_line
        end
 
        # Return the working (current) directory
@@ -524,11 +524,15 @@ private extern class NativeFile `{ FILE* `}
        new native_stderr is extern "file_NativeFileCapable_NativeFileCapable_native_stderr_0"
 end
 
-# Standard input.
-fun stdin: Stdin do return once new Stdin
+redef class Sys
 
-# Standard output.
-fun stdout: OFStream do return once new Stdout
+       # Standard input
+       var stdin: PollableIStream protected writable = new Stdin
 
-# Standard output for error.
-fun stderr: OFStream do return once new Stderr
+       # Standard output
+       var stdout: OStream protected writable = new Stdout
+
+       # Standard output for errors
+       var stderr: OStream protected writable = new Stderr
+
+end
index 8f2d95b..3df0cce 100644 (file)
@@ -572,11 +572,11 @@ redef class ANode
        private fun fatal(v: NaiveInterpreter, message: String)
        do
                if v.modelbuilder.toolcontext.opt_no_color.value == true then
-                       stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
+                       sys.stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
                else
-                       stderr.write("{location}: Runtime error: {message}\n{location.colored_line("0;31")}\n")
-                       stderr.write(v.stack_trace)
-                       stderr.write("\n")
+                       sys.stderr.write("{location}: Runtime error: {message}\n{location.colored_line("0;31")}\n")
+                       sys.stderr.write(v.stack_trace)
+                       sys.stderr.write("\n")
                end
                exit(1)
        end
@@ -833,11 +833,11 @@ redef class AExternInitPropdef
                var pname = mpropdef.mproperty.name
                var cname = mpropdef.mclassdef.mclass.name
                if pname == "native_stdout" then
-                       return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, stdout)
+                       return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, sys.stdout)
                else if pname == "native_stdin" then
-                       return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, stdin)
+                       return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, sys.stdin)
                else if pname == "native_stderr" then
-                       return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, stderr)
+                       return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, sys.stderr)
                else if pname == "io_open_read" then
                        var a1 = args[1].val.as(Buffer)
                        return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, new IFStream.open(a1.to_s))
index 532914c..134d02a 100644 (file)
@@ -101,7 +101,7 @@ class NitIndex
 
        fun prompt do
                printn ">> "
-               search(stdin.read_line)
+               search(sys.stdin.read_line)
        end
 
        fun search(entry: String) do
index 32fe720..9a6eec0 100644 (file)
@@ -180,7 +180,7 @@ redef class ToolContext
                loop
                        printn prompt
                        printn " "
-                       var s = stdin.read_line
+                       var s = sys.stdin.read_line
                        if s == "" then continue
                        if s.chars.first == ':' then
                                var res = new TString
index a7d17ce..b2ae21a 100644 (file)
@@ -90,9 +90,9 @@ class ToolContext
 
                        for m in messages do
                                if opt_no_color.value then
-                                       stderr.write("{m}\n")
+                                       sys.stderr.write("{m}\n")
                                else
-                                       stderr.write("{m.to_color_string}\n")
+                                       sys.stderr.write("{m.to_color_string}\n")
                                end
                        end