v -watch: support for VWATCH_CLEAR_TERMINAL

pull/9892/head^2
Delyan Angelov 2021-04-27 16:29:02 +03:00
parent 1fbf75f2e8
commit a0963f4d74
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 7 additions and 1 deletions

View File

@ -2,6 +2,7 @@ module main
import os import os
import time import time
import term
const scan_timeout_s = 5 * 60 const scan_timeout_s = 5 * 60
@ -74,11 +75,12 @@ mut:
is_exiting bool // set by SIGINT/Ctrl-C is_exiting bool // set by SIGINT/Ctrl-C
v_cycles int // how many times the worker has restarted the V compiler v_cycles int // how many times the worker has restarted the V compiler
scan_cycles int // how many times the worker has scanned for source file changes scan_cycles int // how many times the worker has scanned for source file changes
clear_terminal bool // whether to clear the terminal before each re-run
} }
[if debug_vwatch] [if debug_vwatch]
fn (mut context Context) elog(msg string) { fn (mut context Context) elog(msg string) {
eprintln('> vredo $context.pid, $msg') eprintln('> vwatch $context.pid, $msg')
} }
fn (context &Context) str() string { fn (context &Context) str() string {
@ -199,6 +201,9 @@ fn (mut context Context) compilation_runner_loop() {
context.child_process.use_pgroup = true context.child_process.use_pgroup = true
context.child_process.set_args(context.opts) context.child_process.set_args(context.opts)
context.child_process.run() context.child_process.run()
if context.clear_terminal {
term.clear()
}
eprintln('$timestamp: $cmd | pid: ${context.child_process.pid:7d} | reload cycle: ${context.v_cycles:5d}') eprintln('$timestamp: $cmd | pid: ${context.child_process.pid:7d} | reload cycle: ${context.v_cycles:5d}')
for { for {
mut cmds := []RerunCommand{} mut cmds := []RerunCommand{}
@ -246,6 +251,7 @@ fn main() {
context.pid = os.getpid() context.pid = os.getpid()
context.vexe = os.getenv('VEXE') context.vexe = os.getenv('VEXE')
context.is_worker = os.args.contains('-vwatchworker') context.is_worker = os.args.contains('-vwatchworker')
context.clear_terminal = os.getenv('VWATCH_CLEAR_TERMINAL') != ''
context.opts = os.args[1..].filter(it != '-vwatchworker') context.opts = os.args[1..].filter(it != '-vwatchworker')
context.elog('>>> context.pid: $context.pid') context.elog('>>> context.pid: $context.pid')
context.elog('>>> context.vexe: $context.vexe') context.elog('>>> context.vexe: $context.vexe')