better handling of changing width with opnk

This commit is contained in:
Lionel Dricot 2023-08-17 15:38:47 +02:00
parent 38fcc89193
commit fe06f17b16
3 changed files with 11 additions and 5 deletions

View File

@ -451,6 +451,7 @@ class GeminiClient(cmd.Cmd):
value = int(value)
print("changing width to ",value)
term_width(new_width=value)
self.opencache.cleanup(full=False)
else:
print("%s is not a valid width (integer required)"%value)
elif value.isnumeric():

View File

@ -78,12 +78,15 @@ def run(cmd, *, input=None, parameter=None, direct_output=False, env={}):
global TERM_WIDTH
TERM_WIDTH = 72
def term_width(new_width=None):
#if absolute, returns the real terminal width, not the text width
def term_width(new_width=None,absolute=False):
if new_width:
global TERM_WIDTH
TERM_WIDTH = new_width
width = TERM_WIDTH
cur = shutil.get_terminal_size()[0]
if absolute:
return cur
width = TERM_WIDTH
if cur < width:
width = cur
return width

View File

@ -89,7 +89,7 @@ class opencache():
self.renderer_time = {}
self.mime_handlers = {}
self.last_mode = {}
self.last_width = term_width()
self.last_width = term_width(absolute=True)
def _get_handler_cmd(self, mimetype):
# Now look for a handler for this mimetype
@ -149,10 +149,11 @@ class opencache():
if path:
usecache = inpath in self.rendererdic.keys()
#Screen size may have changed
if usecache and self.last_width != term_width():
width = term_width(absolute=True)
if usecache and self.last_width != width:
self.cleanup(full=False)
usecache = False
self.last_width = term_width()
self.last_width = width
if usecache:
if inpath in self.renderer_time.keys():
last_downloaded = netcache.cache_last_modified(inpath)
@ -255,6 +256,7 @@ class opencache():
os.remove(self.temp_files.popitem()[1])
while len(self.less_histfile) > 0:
os.remove(self.less_histfile.popitem()[1])
self.last_width = None
if full:
self.rendererdic = {}
self.renderer_time = {}