Merge pull request #43 from sp0cket/master

fix drawHeader strings.Repeat crash
This commit is contained in:
Brian Buller 2020-04-08 15:29:24 -05:00 committed by GitHub
commit 14bd1cdd41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
"time"
@ -534,10 +535,22 @@ func (screen *BrowserScreen) drawScreen(style Style) {
func (screen *BrowserScreen) drawHeader(style Style) {
width, _ := termbox.Size()
headerString := ProgramName + ": " + currentFilename
spaces := strings.Repeat(" ", ((width-len(headerString))/2)+1)
headerStringLen := func(fileName string) int {
return len(ProgramName) + len(fileName) + 1
}
headerFileName := currentFilename
if headerStringLen(headerFileName) > width {
headerFileName = filepath.Base(headerFileName)
}
headerString := ProgramName + ": " + headerFileName
count := ((width-len(headerString))/2)+1
if count < 0 {
count = 0
}
spaces := strings.Repeat(" ", count)
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, headerString, spaces), 0, 0, style.titleFg, style.titleBg)
}
func (screen *BrowserScreen) drawFooter(style Style) {
if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout {
screen.clearMessage()