1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

repl: fix ctrl+z job to background on linux (#6417)

This commit is contained in:
Henrixounez 2020-09-18 15:34:00 +02:00 committed by GitHub
parent d2badcdedf
commit 46dc6cc24b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -7,9 +7,11 @@
module readline module readline
import term import term
import os
#include <termios.h> #include <termios.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
// Defines actions to execute // Defines actions to execute
enum Action { enum Action {
eof eof
@ -35,9 +37,12 @@ fn C.tcgetattr() int
fn C.tcsetattr() int fn C.tcsetattr() int
// fn C.ioctl() int
fn C.raise() fn C.raise()
fn C.kill(int, int) int
fn C.getppid() int
// Enable the raw mode of the terminal // Enable the raw mode of the terminal
// In raw mode all keypresses are directly sent to the program and no interpretation is done // In raw mode all keypresses are directly sent to the program and no interpretation is done
// Catches the SIGUSER (CTRL+C) Signal // Catches the SIGUSER (CTRL+C) Signal
@ -480,6 +485,18 @@ fn (mut r Readline) history_next() {
} }
fn (mut r Readline) suspend() { 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) C.raise(C.SIGSTOP)
r.enable_raw_mode()
r.refresh_line()
if r.is_tty {
r.refresh_line() r.refresh_line()
} }
}

View File

@ -111,6 +111,7 @@ pub fn set_vroot_folder(vroot_path string) {
// can return it later to whoever needs it: // can return it later to whoever needs it:
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } 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('VEXE', os.real_path(os.join_path(vroot_path, vname)), true)
os.setenv('VCHILD', 'true', true)
} }
pub fn resolve_vroot(str, dir string) ?string { pub fn resolve_vroot(str, dir string) ?string {