fix drawHeader strings.Repeat crash
This commit is contained in:
parent
19bf4d25d2
commit
10e63ac072
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -534,10 +535,22 @@ func (screen *BrowserScreen) drawScreen(style Style) {
|
|||||||
|
|
||||||
func (screen *BrowserScreen) drawHeader(style Style) {
|
func (screen *BrowserScreen) drawHeader(style Style) {
|
||||||
width, _ := termbox.Size()
|
width, _ := termbox.Size()
|
||||||
headerString := ProgramName + ": " + currentFilename
|
headerStringLen := func(fileName string) int {
|
||||||
spaces := strings.Repeat(" ", ((width-len(headerString))/2)+1)
|
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)
|
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, headerString, spaces), 0, 0, style.titleFg, style.titleBg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (screen *BrowserScreen) drawFooter(style Style) {
|
func (screen *BrowserScreen) drawFooter(style Style) {
|
||||||
if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout {
|
if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout {
|
||||||
screen.clearMessage()
|
screen.clearMessage()
|
||||||
|
Loading…
Reference in New Issue
Block a user