Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[canvas-] change mock window size from 80x25 to 1x1 #2171 #2485

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions visidata/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self, *names, **kwargs):
self.labels = [] # (x, y, text, attr, row)
self.hiddenAttrs = set()
self.needsRefresh = False
self.resetCanvasDimensions(self.windowHeight, self.windowWidth)
self.resetCanvasDimensions(1, 1) #2171

@property
def nRows(self):
Expand Down Expand Up @@ -393,6 +393,12 @@ def resetCanvasDimensions(self, windowHeight, windowWidth):
if self.cursorBox.xmin == self.visibleBox.xmin and self.cursorBox.ymin == self.calcBottomCursorY():
realign_cursor = True
super().resetCanvasDimensions(windowHeight, windowWidth)
# if window is not big enough to contain a particular margin, pretend that margin is 0
pvbox_x = pvbox_y = 0
if self.plotwidth > self.left_margin:
pvbox_x = self.left_margin
if self.plotheight > self.topMarginPixels:
pvbox_y = self.topMarginPixels
if hasattr(self, 'legendwidth'):
# +4 = 1 empty space after the graph + 2 characters for the legend prefixes of "1:", "2:", etc +
# 1 character for the empty rightmost column
Expand All @@ -403,8 +409,10 @@ def resetCanvasDimensions(self, windowHeight, windowWidth):
else:
pvbox_xmax = self.plotwidth-self.rightMarginPixels-1
self.left_margin = min(self.left_margin, math.ceil(self.plotwidth * 1/3)//2*2)
self.plotviewBox = BoundingBox(self.left_margin, self.topMarginPixels,
pvbox_xmax, self.plotheight-self.bottomMarginPixels-1)
# enforce a minimum plotview box size of 1x1
pvbox_xmax = max(pvbox_xmax, 1)
pvbox_ymax = max(self.plotheight-self.bottomMarginPixels-1, 1)
self.plotviewBox = BoundingBox(pvbox_x, pvbox_y, pvbox_xmax, pvbox_ymax)
if [self.plotheight, self.plotwidth] != old_plotsize:
if hasattr(self, 'cursorBox') and self.cursorBox:
self.setCursorSizeInPlotterPixels(2, 4)
Expand Down
Loading