From a018159e667a550349a0d4c002888f0227fe4039 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 18 May 2015 08:50:16 -0500 Subject: [PATCH] Truncate title if it is too long --- termbox_inputmodal.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/termbox_inputmodal.go b/termbox_inputmodal.go index 239b2a9..e2b5f49 100644 --- a/termbox_inputmodal.go +++ b/termbox_inputmodal.go @@ -123,13 +123,15 @@ func (i *InputModal) Draw() { if i.is_visible { // First blank out the area we'll be putting the modal FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg) - // Now draw the border - DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg) - next_y := i.y + 1 // The title if i.title != "" { - DrawStringAtPoint(i.title, i.x+1, next_y, i.fg, i.bg) + if len(i.title) > i.width { + diff := i.width - len(i.title) + DrawStringAtPoint(i.title[:len(i.title)+diff-1], i.x+1, next_y, i.fg, i.bg) + } else { + DrawStringAtPoint(i.title, i.x+1, next_y, i.fg, i.bg) + } next_y += 1 FillWithChar('-', i.x+1, next_y, i.x+i.width-1, next_y, i.fg, i.bg) next_y += 1 @@ -146,5 +148,7 @@ func (i *InputModal) Draw() { help_x := (i.x + i.width - len(help_string)) - 1 DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg) } + // Now draw the border + DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg) } }