Kouhei Sutou
null+****@clear*****
Fri Feb 16 16:22:19 JST 2018
Kouhei Sutou 2018-02-16 16:22:19 +0900 (Fri, 16 Feb 2018) New Revision: 552f978a15439f94a857061e274f6dc0275c3ac7 https://github.com/ranguba/groonga-client/commit/552f978a15439f94a857061e274f6dc0275c3ac7 Message: groonga-client: support repl Modified files: lib/groonga/client/command-line/groonga-client.rb Modified: lib/groonga/client/command-line/groonga-client.rb (+36 -3) =================================================================== --- lib/groonga/client/command-line/groonga-client.rb 2017-12-13 15:27:44 +0900 (c13360d) +++ lib/groonga/client/command-line/groonga-client.rb 2018-02-16 16:22:19 +0900 (0164646) @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2017 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2015-2018 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -45,8 +45,12 @@ module Groonga runner = Runner.new(client, @runner_options) if command_file_paths.empty? - $stdin.each_line do |line| - runner << line + if $stdin.tty? and $stdout.tty? + runner.repl + else + $stdin.each_line do |line| + runner << line + end end else command_file_paths.each do |command_file_path| @@ -114,6 +118,16 @@ module Groonga @parser.finish end + def repl + begin + require "readline" + rescue LoadError + repl_bare + else + repl_readline + end + end + private def create_command_parser parser = Groonga::Command::Parser.new @@ -175,6 +189,25 @@ module Groonga puts(response.body) end end + + def repl_bare + loop do + print("> ") + $stdout.flush + line = gets + break if line.nil? + self << line + end + end + + def repl_readline + loop do + line = Readline.readline("> ", true) + break if line.nil? + self << line + self << "\n" + end + end end end end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180216/cb59cd88/attachment-0001.htm