From cf37028a520f5c679fbf4c964745020f31b1bd25 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 23 Dec 2019 12:23:53 +0200 Subject: [PATCH] test: use 'stty size' for vtest --- line instead of 'tput cols' --- tools/modules/testing/common.v | 2 ++ tools/vtest.v | 9 --------- vlib/term/can_show_color.v | 14 ++++++++++++++ vlib/term/control.v | 1 - 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/modules/testing/common.v b/tools/modules/testing/common.v index 9f10ce7c62..cf06299605 100644 --- a/tools/modules/testing/common.v +++ b/tools/modules/testing/common.v @@ -94,6 +94,7 @@ pub fn (ts mut TestSession) test() { os.rm( tmpc_filepath ) } ts.benchmark.stop() + eprintln(term.h_divider()) } pub fn vlib_should_be_present( parent_dir string ) { @@ -177,6 +178,7 @@ pub fn building_any_v_binaries_failed() bool { eprintln(bmark.step_message('$cmd => ${bok}')) } bmark.stop() + eprintln(term.h_divider()) eprintln( bmark.total_message( 'building v binaries' ) ) return failed diff --git a/tools/vtest.v b/tools/vtest.v index cd8f67e19f..7a5fe2dac1 100644 --- a/tools/vtest.v +++ b/tools/vtest.v @@ -47,15 +47,6 @@ pub fn main() { println('Testing...') ts.test() - // Print separator with dynamic width - mut cols := 76 - if tput := os.exec("tput cols; echo") { - if tput.exit_code == 0 { - cols = tput.output.int() - } - } - println("-".repeat(cols)) - println( ts.benchmark.total_message('running V _test.v files') ) if ts.failed { exit(1) diff --git a/vlib/term/can_show_color.v b/vlib/term/can_show_color.v index 0d9701760d..ae060c9cc2 100644 --- a/vlib/term/can_show_color.v +++ b/vlib/term/can_show_color.v @@ -27,3 +27,17 @@ pub fn fail_message(s string) string { return if can_show_color_on_stdout() { red(s) } else { s } } +// h_divider will return a horizontal divider line with a dynamic width, +// that depends on the current terminal settings +pub fn h_divider() string { + mut cols := 76 + if term_size := os.exec('stty size') { + if term_size.exit_code == 0 { + term_cols := term_size.output.split(' ')[1].int() + if term_cols > 0 { + cols = term_cols + } + } + } + return '-'.repeat(cols) +} diff --git a/vlib/term/control.v b/vlib/term/control.v index c19ec2e2e0..93e4fd40e3 100644 --- a/vlib/term/control.v +++ b/vlib/term/control.v @@ -95,4 +95,3 @@ pub fn show_cursor() { pub fn hide_cursor() { print('\x1b[?25l') } -