From 46dc6cc24badc87a551bb15d9cd2170a2d27615c Mon Sep 17 00:00:00 2001 From: Henrixounez <30901439+Henrixounez@users.noreply.github.com> Date: Fri, 18 Sep 2020 15:34:00 +0200 Subject: [PATCH] repl: fix ctrl+z job to background on linux (#6417) --- vlib/readline/readline_linux.c.v | 19 ++++++++++++++++++- vlib/v/util/util.v | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vlib/readline/readline_linux.c.v b/vlib/readline/readline_linux.c.v index cc80a3efe2..46414728e4 100644 --- a/vlib/readline/readline_linux.c.v +++ b/vlib/readline/readline_linux.c.v @@ -7,9 +7,11 @@ module readline import term +import os #include #include + // Defines actions to execute enum Action { eof @@ -35,9 +37,12 @@ fn C.tcgetattr() int fn C.tcsetattr() int -// fn C.ioctl() int fn C.raise() +fn C.kill(int, int) int + +fn C.getppid() int + // Enable the raw mode of the terminal // In raw mode all keypresses are directly sent to the program and no interpretation is done // Catches the SIGUSER (CTRL+C) Signal @@ -480,6 +485,18 @@ fn (mut r Readline) history_next() { } fn (mut r Readline) suspend() { + is_standalone := os.getenv('VCHILD') != 'true' + + r.disable_raw_mode() + if !is_standalone { + // We have to SIGSTOP the parent v process + ppid := C.getppid() + C.kill(ppid, C.SIGSTOP) + } C.raise(C.SIGSTOP) + r.enable_raw_mode() r.refresh_line() + if r.is_tty { + r.refresh_line() + } } diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index ee46da5cb2..36771d79dc 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -111,6 +111,7 @@ pub fn set_vroot_folder(vroot_path string) { // can return it later to whoever needs it: vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } os.setenv('VEXE', os.real_path(os.join_path(vroot_path, vname)), true) + os.setenv('VCHILD', 'true', true) } pub fn resolve_vroot(str, dir string) ?string {