From 5c9cbae10dd9b7b5cf78bc09789c2bd0d6117cf4 Mon Sep 17 00:00:00 2001 From: Major Taylor Date: Mon, 23 Mar 2020 15:05:08 -0400 Subject: [PATCH] term: fix divide by 0 error on empty delimiter --- vlib/term/term.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/term/term.v b/vlib/term/term.v index 399df46fdb..31b2a1020b 100644 --- a/vlib/term/term.v +++ b/vlib/term/term.v @@ -32,9 +32,10 @@ pub fn fail_message(s string) string { // h_divider returns a horizontal divider line with a dynamic width, // that depends on the current terminal settings. +// If an empty string is passed in, print enough spaces to make a new line pub fn h_divider(divider string) string { cols,_ := get_terminal_size() - result := divider.repeat(1 + (cols / divider.len)) + result := if divider.len > 0 { divider.repeat(1 + (cols / divider.len)) } else { " ".repeat(1 + cols) } return result[0..cols] } @@ -49,7 +50,7 @@ pub fn header(text, divider string) string { tlimit := if cols > text.len + 2 + 2 * divider.len { text.len } else { cols - 3 - 2 * divider.len } tlimit_alligned := if (tlimit % 2) != (cols % 2) { tlimit + 1 } else { tlimit } tstart := (cols - tlimit_alligned) / 2 - ln := divider.repeat(1 + cols / divider.len)[0..cols] + ln := if divider.len > 0 { divider.repeat(1 + cols / divider.len)[0..cols] } else { " ".repeat(1 + cols) } return ln[0..tstart] + ' ' + text[0..tlimit] + ' ' + ln[tstart + tlimit + 2..cols] }