diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-25 14:39:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-25 15:05:51 +0100 |
commit | 65307235bf255b8247397b1d0b62a1e5f65e0bfb (patch) | |
tree | f342a3f88f175d1deddf8a3790b057e969d395c3 | |
parent | d7ce2174f12d1b7730a015100ca0fef457ad4d72 (diff) | |
download | chawan-65307235bf255b8247397b1d0b62a1e5f65e0bfb.tar.gz |
pager: improve title display, fix alert display
-rw-r--r-- | src/display/client.nim | 1 | ||||
-rw-r--r-- | src/display/pager.nim | 38 |
2 files changed, 35 insertions, 4 deletions
diff --git a/src/display/client.nim b/src/display/client.nim index d1c33816..2e6528a3 100644 --- a/src/display/client.nim +++ b/src/display/client.nim @@ -313,6 +313,7 @@ proc inputLoop(client: Client) = client.command(client.pager.scommand) client.pager.scommand = "" client.handlePagerEvents() + client.pager.showAlerts() client.pager.draw() client.acceptBuffers() diff --git a/src/display/pager.nim b/src/display/pager.nim index f90b057c..49ff2227 100644 --- a/src/display/pager.nim +++ b/src/display/pager.nim @@ -37,6 +37,7 @@ type jsctx: JSContext numload*: int alerts: seq[string] + alerton: bool commandMode*: bool container*: Container dispatcher*: Dispatcher @@ -264,21 +265,50 @@ proc refreshStatusMsg*(pager: Pager) = if container == nil: return if pager.tty == nil: return if container.loadinfo != "": + pager.alerton = true pager.writeStatusMessage(container.loadinfo) elif pager.alerts.len > 0: + pager.alerton = true pager.writeStatusMessage(pager.alerts[0]) pager.alerts.delete(0) else: + pager.alerton = false container.clearHover() var msg = $(container.cursory + 1) & "/" & $container.numLines & " (" & - $container.atPercentOf() & "%) " & "<" & container.getTitle() & ">" - let h = container.getHoverText() - if h != "": - msg &= " " & h + $container.atPercentOf() & "%)" + let mw = msg.width() + let t = container.getTitle() + let tt = " <" & t & ">" + let tw = tt.width() + let ht = container.getHoverText() + if ht.len == 0: # hover text is empty. + msg &= tt + else: + let h = " " & ht + let hw = h.width() + if mw + tw + hw < pager.statusgrid.width: + msg &= tt + elif mw + hw + 3 < pager.statusgrid.width: + # squeezing the title would mean we still have some space for it. + var t2 = " <" + var w = mw + hw + 2 # t2 has a width of 2 + for r in t.runes: + if w >= pager.statusgrid.width - 1: # ends with another > + t2 &= ">" + break + t2 &= r + w += r.width() + msg &= t2 + msg &= h var format = newFormat() format.reverse = true pager.writeStatusMessage(msg, format) +# Call refreshStatusMsg if no alert is being displayed on the screen. +proc showAlerts*(pager: Pager) = + if not pager.alerton: + pager.refreshStatusMsg() + proc drawBuffer*(pager: Pager, container: Container, ostream: Stream) = var format = newFormat() container.readLines(proc(line: SimpleFlexibleLine) = |