lib/pty1.rb in markdown_exec-1.6 vs lib/pty1.rb in markdown_exec-1.7

- old
+ new

@@ -1,26 +1,26 @@ +# frozen_string_literal: true + require 'pty' def launch_and_interact_with_terminal - begin - PTY.spawn("bash") do |stdout, stdin, pid| - # Send a command to the terminal - stdin.puts "echo 'Hello from Ruby!'" + PTY.spawn('bash') do |stdout, stdin, _pid| + # Send a command to the terminal + stdin.puts "echo 'Hello from Ruby!'" - # Read the output of the command - stdout.each do |line| - puts line - break if line.include?("Hello from Ruby!") - end + # Read the output of the command + stdout.each do |line| + puts line + break if line.include?('Hello from Ruby!') + end - # You can continue to interact with the terminal here - # ... + # You can continue to interact with the terminal here + # ... - # Ensure to exit the spawned shell - stdin.puts "exit" - end - rescue PTY::ChildExited => e - puts "The child process exited!" + # Ensure to exit the spawned shell + stdin.puts 'exit' end +rescue PTY::ChildExited + puts 'The child process exited!' end launch_and_interact_with_terminal