From edd90d55461127bc46192de0eb8f0b89b19a98c3 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 24 Apr 2024 22:17:58 +0900 Subject: [PATCH] Use IO.popen instead of system to avoid stdin read by tailwindcss watch command `tailwindcss -w` reads stdin, probably to detect stdin close. When using binding.irb or debugger with tailwindcss-rails, some keystrokes are taken by tailwindcss. To not let tailwindcss watch command read stdin, we should use `IO.popen(command, 'r+')` instead of `system(*command)`. Workaround for https://github.com/rails/tailwindcss-rails/discussions/346 --- lib/puma/plugin/tailwindcss.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/puma/plugin/tailwindcss.rb b/lib/puma/plugin/tailwindcss.rb index d78b068e..e614d62a 100644 --- a/lib/puma/plugin/tailwindcss.rb +++ b/lib/puma/plugin/tailwindcss.rb @@ -8,7 +8,12 @@ def start(launcher) @puma_pid = $$ @tailwind_pid = fork do Thread.new { monitor_puma } - system(*Tailwindcss::Commands.watch_command) + # Using IO.popen(command, 'r+') will avoid watch_command read from $stdin. + # If we use system(*command) instead, IRB and Debug can't read from $stdin + # correctly bacause some keystrokes will be taken by watch_command. + IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io| + IO.copy_stream(io, $stdout) + end end launcher.events.on_stopped { stop_tailwind }