-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: paste mode #56
Feature: paste mode #56
Conversation
src/icr/console.cr
Outdated
end | ||
|
||
input += input_line | ||
input += "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings in Crystal are immutable. So each time you do +=
, you create a new string. Use String.build
instead.
src/icr/console.cr
Outdated
input += "\n" | ||
end | ||
|
||
if input.to_s.strip != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!input.blank?
should be a bit cleaner
Tested locally and it works: icr(0.23.1) > |paste
# Entering paste mode (ctrl-D to finish)
puts "hello"
puts "bro"
[1, 2, 3].each { |e| puts e }
^D
# Ctrl-D was pressed, now interpreting...
hello
bro
1
2
3
=> nil But I'm not sure if we need this because you can just use parenthesis (or icr(0.23.1) > (
icr(0.23.1) > puts "hello"
icr(0.23.1) > puts "bro"
icr(0.23.1) > [1, 2, 3].each { |e| puts e }
icr(0.23.1) > )
hello
bro
1
2
3
=> nil @greyblake WDYT? |
Your call guys. I made the requested changes :) |
Personally I don't see advantages of @greyblake @crystal-community/maintainers thoughts? |
I'll take a look tonight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good an works well.
I left a tiny comment regarding |paste
-> paste
.
What do other people think? @veelenga
src/icr/console.cr
Outdated
@@ -28,11 +28,36 @@ module Icr | |||
__exit__ | |||
elsif %w(exit quit).includes?(input.to_s.strip) | |||
__exit__ | |||
elsif %w(|paste).includes?(input.to_s.strip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be easier to read if it would be
input.to_s.strip == "|paste"
...
Also, I would prefer to use simply paste
without |
. Just like exit
and quite
commands above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greyblake good catch 👍
Using just paste
means the user can't use this word as a variable or method name... But really rare case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the changes. paste
doesn't seem like a good variable name anyway. ;)
src/icr/console.cr
Outdated
input_line = Readline.readline() | ||
|
||
if input_line.nil? | ||
puts "\n\n# Ctrl-D was pressed, now interpreting...\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think interpreting is not the right word here because crystal is compiled language 😄
Maybe better to say: "Ctrl-D was pressed, exiting paste mode... "?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good to me 👍 Just a small improvement...
No description provided.