Skip to content

Commit

Permalink
Merge pull request #56 from Porcupine96/feature/paste-mode
Browse files Browse the repository at this point in the history
Feature: paste mode
  • Loading branch information
greyblake committed Sep 2, 2017
2 parents 0abe035 + a91d6f9 commit 4fe42cb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/icr/console.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,36 @@ module Icr
__exit__
elsif %w(exit quit).includes?(input.to_s.strip)
__exit__
elsif input.to_s.strip == "paste"
paste_mode()
elsif input.to_s.strip != ""
process_command(input.to_s)
end
end

private def paste_mode()
puts "# Entering paste mode (ctrl-D to finish)"
input = String.build do |input|
loop do
input_line = Readline.readline()

if input_line.nil?
puts "\n\n# Ctrl-D was pressed, exiting paste mode...\n"
break
end

input << input_line
input << "\n"
end
end

if !input.blank?
process_command(input.to_s)
else
puts "\n# Nothing pasted, nothing gained\n"
end
end

private def process_command(command : String)
result = check_syntax(command)
process_result(result, command)
Expand Down

0 comments on commit 4fe42cb

Please sign in to comment.