From 591884e362ad95ae7dadc47a069bd4ed9d74a88b Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Fri, 26 Jan 2024 14:16:26 -0500 Subject: [PATCH] Fix: Windows support (at least from a code perspective) (#10) * fix: windows support * fix: ameba pinned --- shard.yml | 2 +- src/nox.cr | 7 ++++++- src/nox/intercepting_io.cr | 2 +- src/nox/process.cr | 12 ++++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/shard.yml b/shard.yml index ad6fde1..7a17a03 100644 --- a/shard.yml +++ b/shard.yml @@ -15,7 +15,7 @@ targets: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 1.0 + version: 1.5.0 spectator: gitlab: arctic-fox/spectator version: ~> 0.11.3 diff --git a/src/nox.cr b/src/nox.cr index 48046e0..7260f5c 100644 --- a/src/nox.cr +++ b/src/nox.cr @@ -10,7 +10,12 @@ module Nox def self.run(file : String) procfile = Nox::Procfile.parse_file(file) runner = Nox::Runner.new(procfile, output: STDOUT) - Signal::INT.trap { runner.interrupt_or_kill } + {% if compare_versions(Crystal::VERSION, "1.8.0") < 0 %} + {% raise "Windows requires >= 1.8.0" if flag?(:win32) %} + Signal::INT.trap { runner.interrupt_or_kill } + {% else %} + ::Process.on_interrupt { runner.interrupt_or_kill } + {% end %} runner.run end end diff --git a/src/nox/intercepting_io.cr b/src/nox/intercepting_io.cr index bc8aa60..3bec8a6 100644 --- a/src/nox/intercepting_io.cr +++ b/src/nox/intercepting_io.cr @@ -45,6 +45,6 @@ class Nox::InterceptingIO < IO end private def max_name_size : Int32 - @@names.map(&.size).max + @@names.max_of(&.size) end end diff --git a/src/nox/process.cr b/src/nox/process.cr index b52bc96..635dc38 100644 --- a/src/nox/process.cr +++ b/src/nox/process.cr @@ -28,11 +28,19 @@ class Nox::Process def kill with_process do |process| print_bold "Attempting to kill..." - process.signal(Signal::KILL) + {% if compare_versions(Crystal::VERSION, "1.8.0") < 0 %} + {% if flag?(:win32) %} + process.terminate + {% else %} + process.signal(Signal::KILL) + {% end %} + {% else %} + process.terminate(graceful: false) + {% end %} end end - private def with_process + private def with_process(&) if (process = @process) && process.exists? yield process end