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

term: fix too long h_divider lines in CI

This commit is contained in:
Delyan Angelov 2020-01-28 21:25:17 +02:00 committed by Alexander Medvednikov
parent 78c96fe989
commit 9ac0c54eb0
2 changed files with 16 additions and 15 deletions

View File

@ -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]
}

View File

@ -1,20 +1,24 @@
module term
import os
#include <sys/ioctl.h>
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)
}