From 01b0983f7971357979c1e25529123a006f3182f4 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 16 Jan 2022 15:05:54 -0800 Subject: [PATCH] Use readline for proper editing and history --- ruby/main.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby/main.rb b/ruby/main.rb index c379a4b..568b0c7 100755 --- a/ruby/main.rb +++ b/ruby/main.rb @@ -2,6 +2,7 @@ require 'English' require 'open3' +require 'readline' require './builtins' require './colours' @@ -27,11 +28,11 @@ class Shell print_logs exit exec_command(options[:command]) elsif $stdin.isatty + add_to_history = true loop do - # TODO: use readline instead print_logs - print prompt(Dir.pwd) - process_command(gets&.chomp) + cmd = Readline.readline(prompt(Dir.pwd), add_to_history) + process_command(cmd) end end end @@ -105,7 +106,6 @@ class Shell status = exec_command(cmd) print "#{RED}-#{status}-#{CLEAR} " unless status.zero? end - # TODO: add to readline history end def exec_command(cmd)