diff --git a/display/display.go b/display/display.go index edba031..c612b13 100644 --- a/display/display.go +++ b/display/display.go @@ -83,6 +83,13 @@ var App = cview.NewApplication(). // Store width and height for calculations termW = width termH = height + + // Shift new tabs created before app startup, when termW == 0 + // XXX: This is hacky but works. The biggest issue is that there will sometimes be a tiny flash + // of the old not shifted tab on startup. + if tabMap[curTab] == &newTabPage { + tabViews[curTab].SetText(addLeftMargin(renderedNewTabContent)) + } }) var renderedNewTabContent string @@ -289,7 +296,7 @@ func NewTab() { SetRegions(true). SetScrollable(true). SetWrap(false). - SetText(renderedNewTabContent). + SetText(addLeftMargin(renderedNewTabContent)). SetChangedFunc(func() { App.Draw() }). diff --git a/display/private.go b/display/private.go index a1649f4..bb6f2e0 100644 --- a/display/private.go +++ b/display/private.go @@ -100,17 +100,21 @@ func followLink(prev, next string) { }() } +func addLeftMargin(text string) string { + var shifted string + for _, line := range strings.Split(text, "\n") { + shifted += strings.Repeat(" ", leftMargin()) + line + "\n" + } + return shifted +} + // setPage displays a Page on the current tab. func setPage(p *structs.Page) { saveScroll() // Save the scroll of the previous page if !p.Displayable { // Add margin to page based on terminal width - var shifted string - for _, line := range strings.Split(p.Content, "\n") { - shifted += strings.Repeat(" ", leftMargin()) + line + "\n" - } - p.Content = shifted + p.Content = addLeftMargin(p.Content) p.Displayable = true }