Skip to content

Commit

Permalink
[ddwplay] use clipdraw to make help more robust on small scr
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 20, 2023
1 parent bda77b1 commit 3a3fca9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions visidata/ddwplay.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
import json
import time
from visidata import colors, vd
from visidata import colors, vd, clipdraw

__all__ = ['Animation', 'AnimationMgr']

Expand Down Expand Up @@ -68,7 +68,7 @@ def load_from(self, fp):

def draw(self, scr, *, t=0, x=0, y=0, loop=False, **kwargs):
for r, dx, dy, _ in self.iterdeep(self.frames[''].rows):
scr.addstr(y+dy, x+dx, r.text, colors[r.color].attr)
clipdraw(scr, y+dy, x+dx, r.text, colors[r.color])

if not self.total_ms:
return None
Expand All @@ -78,7 +78,7 @@ def draw(self, scr, *, t=0, x=0, y=0, loop=False, **kwargs):
ms -= int(f.duration_ms or 0)
if ms < 0:
for r, dx, dy, _ in self.iterdeep(f.rows):
scr.addstr(y+dy, x+dx, r.text, colors[r.color].attr)
clipdraw(scr, y+dy, x+dx, r.text, colors[r.color])

return -ms/1000

Expand Down
31 changes: 18 additions & 13 deletions visidata/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,37 @@ def __init__(self, name):

def draw(self, scr, x=None, y=None):
if not scr: return
if not vd.options.disp_help:
if self.scr:
self.scr.erase()
self.scr.refresh()
self.scr = None
return
# if vd.options.disp_help <= 0:
# if self.scr:
# self.scr.erase()
# self.scr.refresh()
# self.scr = None
# return
if y is None: y=0 # show at top of screen by default
if x is None: x=0
hneeded = self.amgr.maxHeight+3
wneeded = self.amgr.maxWidth+4
scrh, scrw = scr.getmaxyx()
if not self.scr or scr is not self.parentscr: # (re)allocate help pane scr
if y >= 0:
if y+self.amgr.maxHeight+3 < scr.getmaxyx()[0]:
if y+hneeded < scrh:
yhelp = y+1
else:
yhelp = y-self.amgr.maxHeight-3
hneeded = max(0, min(hneeded, y-1))
yhelp = y-hneeded
else: # y<0
yhelp = scr.getmaxyx()[0]-self.amgr.maxHeight-4
yhelp = max(0, scrh-hneeded-1)

if x >= 0:
if x+self.amgr.maxWidth+4 < scr.getmaxyx()[1]:
if x+wneeded < scrw:
xhelp = x+1
else:
xhelp = x-self.amgr.maxWidth-4
wneeded = max(0, min(wneeded, x-1))
xhelp = x-wneeded
else: # x<0
xhelp = scr.getmaxyx()[1]-self.amgr.maxWidth-5
xhelp = max(0, scrh-wneeded-1)

self.scr = vd.subwindow(scr, xhelp, yhelp, self.amgr.maxWidth+4, self.amgr.maxHeight+3)
self.scr = vd.subwindow(scr, xhelp, yhelp, wneeded, hneeded)
self.parentscr = scr

self.scr.erase()
Expand Down
3 changes: 2 additions & 1 deletion visidata/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def drawRightStatus(vd, scr, vs):
cattr = update_attr(cattr, colors.color_top_status, 0)
cattr = update_attr(cattr, colors.color_active_status if vs is vd.activeSheet else colors.color_inactive_status, 0)
rstat = vd.rightStatus(vs)
statuslen = clipdraw(scr, vs.windowHeight-1, rightx-dispwidth(rstat)-1, rstat, cattr, w=vs.windowWidth-1)
x = max(2, rightx-dispwidth(rstat)-1)
statuslen = clipdraw(scr, vs.windowHeight-1, x, rstat, cattr, w=vs.windowWidth-1)
except Exception as e:
vd.exceptionCaught(e)
finally:
Expand Down

0 comments on commit 3a3fca9

Please sign in to comment.