I'm using the sass-lint
NPM package to style-check .scss
files from within a Rake task, thus:
sass_lint_cmd = "sass-lint --config #{ui_library_path}/scss/.sass-lint.yml '#{ui_library_path}/scss/*.scss' -v -q --max-warnings=0"
output, status = Open3.capture2e(sass_lint_cmd)
raise IOError, output unless status == 0
This basically works, insofar as in the event of any linter warnings or errors the Rake task aborts and the sass-lint
output, including errors, is dumped to the console.
However, when run directly, sass-lint
produces nice colorized output. When captured by capture2e
, the colors are lost.
I assume the issue is that sass-lint
(or Node) detects it's not running in a TTY, and so outputs plain text. Is there some Process.spawn()
option I can pass to Open3.capture2e()
, or some other method, by which I can make it think it's running in a TTY?
(Note: I did look at Trick an application into thinking its stdout is a terminal, not a pipe, but the BSD version of script
that ships with macOS doesn't seem to support either the --return
or the -c
options, and I'm running on macOS.)
Update: I tried script -q /dev/null
and PTY.spawn()
as per Piccolo's answer, but no luck.
script -q /dev/null …
works from the command line, but doesn't work in Open3.capture2e()
(it runs, but produces monochrome output and a spurious Bundler::GemNotFound
stack trace).
As for PTY.spawn()
, replacing the code above with the following:
r, _w, pid = PTY.spawn(scss_lint_command)
_, proc_status = Process.wait2(pid)
output, status = [r, proc_status.exitstatus]
(warn(output); raise) unless status == 0
the subprocess never seems to complete; if I ps
in another terminal it shows as in interruptible sleep status. Killing the subprocess doesn't free up the parent process.
The same happens with the block form.
output, status = nil
PTY.spawn(scss_lint_command) do |r, _w, pid|
_, proc_status = Process.wait2(pid)
output, status = [r, proc_status.exitstatus]
end
(warn(output); raise) unless status == 0