Explaining IO behavior
If you build and run the application as ./bin/transform .
, it will just hang indefinitely. The reason for this is due to how most IO works in Crystal. The majority of IO is blocking by nature, meaning it will wait for data to come through the input IO type, in this case, STDIN. This can be best demonstrated with this simple program:
print "What is your name? " if (name = gets).presence puts "Your name is: '#{name}'" else puts "No name supplied" end
The gets
method is used to read a line in from STDIN and will wait until it either receives data or the user interrupts the command. This behavior is also true for non-terminal-based IO, such as HTTP response bodies. The reasoning and benefit of this behavior will be explained in the next chapter.