nitin: use `prompt`
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 14 Feb 2018 13:34:01 +0000 (08:34 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 14 Feb 2018 16:17:37 +0000 (11:17 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/nitin/Makefile
contrib/nitin/nitin.nit
contrib/nitin/nitin_readline.nit [deleted file]

index c505bcd..940cee6 100644 (file)
@@ -1,3 +1,3 @@
 all:
        mkdir -p bin
-       nitc --semi-global nitin_readline.nit -o bin/nitin
+       nitc --semi-global nitin.nit -m readline -o bin/nitin
index 2497411..6651636 100644 (file)
@@ -19,6 +19,8 @@
 # The Nit interactive interpreter
 module nitin
 
+import prompt
+
 import nitc::interpreter
 import nitc::frontend
 import nitc::parser_util
@@ -56,21 +58,6 @@ redef class ToolContext
                return tree.n_base.as(not null)
        end
 
-       # Read an user-line with a given `prompt`
-       #
-       # Return `null` if end of file
-       fun readline(prompt: String): nullable String do
-               printn prompt
-               var res = stdin.read_line
-               if res == "" and stdin.eof then return null
-               return res
-       end
-
-       # Add `text` in the history for `readline`.
-       #
-       # With the default implementation, the history is dropped
-       fun readline_add_history(text: String) do end
-
        # The last line number read by `i_parse`
        var last_line = 0
 
@@ -85,7 +72,7 @@ redef class ToolContext
                                s = stdin.read_line
                                if s == "" and stdin.eof then s = null
                        else
-                               s = readline(prompt)
+                               s = sys.prompt(prompt)
                        end
                        if s == null then return null
                        if s == "" then
@@ -115,7 +102,7 @@ redef class ToolContext
                        end
 
                        last_line = n.location.file.line_starts.length - 1
-                       readline_add_history(text.chomp)
+                       prompt_add_history(text.chomp)
                        return n
                end
        end
diff --git a/contrib/nitin/nitin_readline.nit b/contrib/nitin/nitin_readline.nit
deleted file mode 100644 (file)
index d193059..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Add GNU readline capabilities to nitin
-module nitin_readline
-
-import nitin
-import readline
-
-redef class ToolContext
-       redef fun readline(prompt) do return sys.readline(prompt)
-       redef fun readline_add_history(text) do sys.add_history(text)
-end