From 9ac0c54eb0e336ac88f470357da962d878c6b67d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 28 Jan 2020 21:25:17 +0200 Subject: [PATCH] term: fix too long h_divider lines in CI --- vlib/term/misc.v | 5 +---- vlib/term/misc_nix.v | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/vlib/term/misc.v b/vlib/term/misc.v index b7cc3c8382..b1c845432d 100644 --- a/vlib/term/misc.v +++ b/vlib/term/misc.v @@ -1,15 +1,12 @@ module term - // h_divider will return a horizontal divider line with a dynamic width, // that depends on the current terminal settings pub fn h_divider(divider string) string { mut cols := 76 - term_cols, _ := get_terminal_size() - + term_cols,_ := get_terminal_size() if term_cols > 0 { cols = term_cols } - result := divider.repeat(1 + (cols / divider.len)) return result[0..cols] } diff --git a/vlib/term/misc_nix.v b/vlib/term/misc_nix.v index c72e914b92..39d0c2fbb4 100644 --- a/vlib/term/misc_nix.v +++ b/vlib/term/misc_nix.v @@ -1,20 +1,24 @@ module term +import os + #include - -struct C.winsize{ - pub: - ws_row int - ws_col int +pub struct C.winsize { +pub: + ws_row u16 + ws_col u16 + ws_xpixel u16 + ws_ypixel u16 } -fn C.ioctl() int +fn C.ioctl(fd int, request u64, arg voidptr) int -pub fn get_terminal_size() (int, int) { - // TODO: check for resize events - mut w := C.winsize{} +pub fn get_terminal_size() (int,int) { + if is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' { + return 80,25 + } + w := C.winsize{} C.ioctl(0, C.TIOCGWINSZ, &w) - - return w.ws_col, w.ws_row + return int(w.ws_col),int(w.ws_row) }