Fix CTRL-C one time use on Windows

This commit is contained in:
Robert Bendun 2023-03-04 16:39:16 +01:00
parent 2d61896824
commit ff58e6506d
4 changed files with 24 additions and 12 deletions

View File

@ -13,7 +13,7 @@ VERSION := $(MAJOR).$(MINOR).$(PATCH)-dev+$(COMMIT)
CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -ggdb CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -ggdb
CPPFLAGS:=$(CPPFLAGS) -DMusique_Version='"$(VERSION)"' \ CPPFLAGS:=$(CPPFLAGS) -DMusique_Version='"$(VERSION)"' \
-Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -Ilib/link/include -Ilib/asio/include/ -Ilib/replxx/include -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -Ilib/link/include -Ilib/asio/include/ -Ilib/replxx/include -DREPLXX_STATIC
LDFLAGS=-flto LDFLAGS=-flto
LDLIBS= -lpthread LDLIBS= -lpthread

View File

@ -225,6 +225,7 @@ struct Runner
} }
} catch (KeyboardInterrupt const&) { } catch (KeyboardInterrupt const&) {
interpreter.turn_off_all_active_notes(); interpreter.turn_off_all_active_notes();
interpreter.starter.stop();
std::cout << std::endl; std::cout << std::endl;
} }
return {}; return {};
@ -357,6 +358,16 @@ static Result<bool> handle_repl_session_commands(std::string_view input, Runner
return false; return false;
} }
static Runner *runner;
void sigint_handler(int sig)
{
if (sig == SIGINT) {
runner->interpreter.issue_interrupt();
}
std::signal(SIGINT, sigint_handler);
}
/// Fancy main that supports Result forwarding on error (Try macro) /// Fancy main that supports Result forwarding on error (Try macro)
static std::optional<Error> Main(std::span<char const*> args) static std::optional<Error> Main(std::span<char const*> args)
{ {
@ -431,8 +442,9 @@ static std::optional<Error> Main(std::span<char const*> args)
std::exit(1); std::exit(1);
} }
static Runner runner; Runner runner;
std::signal(SIGINT, [](int sig) { if (sig == SIGINT) runner.interpreter.issue_interrupt(); }); ::runner = &runner;
std::signal(SIGINT, sigint_handler);
for (auto const& [type, argument] : runnables) { for (auto const& [type, argument] : runnables) {
if (type == Run::Argument) { if (type == Run::Argument) {

View File

@ -1,15 +1,15 @@
Release_Obj=$(addprefix bin/$(os)/,$(Obj)) Release_Obj=$(addprefix bin/$(os)/,$(Obj))
bin/$(os)/libreplxx.a: # bin/$(os)/libreplxx.a:
@CXX=$(CXX) os=$(os) scripts/build_replxx.sh # @CXX=$(CXX) os=$(os) scripts/build_replxx.sh
bin/$(os)/%.o: musique/%.cc bin/$(os)/%.o: musique/%.cc
@echo "CXX $@" @echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c
bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o bin/$(os)/libreplxx.a bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o
@echo "CXX $@" @echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o -Lbin/$(os)/ $(LDFLAGS) $(LDLIBS) -lreplxx @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(shell CXX=$(CXX) os=$(os) scripts/build_replxx.sh) $(Release_Obj) bin/$(os)/rtmidi.o $(LDFLAGS) $(LDLIBS)
Debug_Obj=$(addprefix bin/$(os)/debug/,$(Obj)) Debug_Obj=$(addprefix bin/$(os)/debug/,$(Obj))

View File

@ -8,13 +8,13 @@ mkdir -p "bin/${os}/replxx"
objects="" objects=""
echo "Building libreplxx library archive" find lib/replxx/src/ -name '*.cxx' -o -name '*.cpp' | while read -r src
ar rcs "bin/${os}/libreplxx.a" $(find lib/replxx/src/ -name '*.cxx' -o -name '*.cpp' | while read -r src
do do
dst="${src##"$prefix"}" dst="${src##"$prefix"}"
dst="bin/${os}/replxx/${dst%%.*}.o" dst="bin/${os}/replxx/${dst%%.*}.o"
if [ ! -f "$dst" ]; then
"${CXX}" -Ilib/replxx/src/ -Ilib/replxx/include/ -c -o "$dst" "$src" -std=c++20 -O3 -DREPLXX_STATIC "${CXX}" -Ilib/replxx/src/ -Ilib/replxx/include/ -c -o "$dst" "$src" -std=c++20 -O3 -DREPLXX_STATIC
fi
echo "${dst}" echo "${dst}"
done) done