Skip to content

Commit

Permalink
remove absolute positioning & fix displaying figures
Browse files Browse the repository at this point in the history
It seems like kitty changed their handling of images somewhat.

The result is that the initial scrolling issues that lead to
prefering absolute positioning seem to be fixed, which means
we can simply use --align=left now.

Another side effect was that display of images was broken at
some point. This should be fixed as well with the above change.

Lastly, I've dropped transparency, as cell content now flows
properly around images, even in scrollback.
  • Loading branch information
jktr committed May 9, 2020
1 parent dff1864 commit 76a7bbc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,22 @@ def f(args, **kwargs):
icat = ['kitty', '+kitten', 'icat']

# gather terminal dimensions
cols = int(tput(['cols']))
rows = int(tput(['lines']))
px = run_with_output(icat)(['--print-window-size'])
px = list(map(int, px.split('x')))

# account for post-display prompt scrolling
px[1] -= int(1*(px[1]/rows))
rows = int(tput(['lines'])) - 1
# 3 line shift for [\n, <matplotlib.axes…, >>>] after the figure
px[1] -= int(3*(px[1]/rows))

# resize figure to terminal size
# resize figure to terminal size & aspect ratio
dpi = self.canvas.figure.dpi
self.canvas.figure.set_size_inches(tuple(map(lambda x: (x / dpi), px)))
self.canvas.figure.set_size_inches((px[0] / dpi, px[1] / dpi))

with BytesIO() as buf:
self.canvas.figure.savefig(buf, format='png',
facecolor='#ffffff7f', transparent=True)
self.canvas.figure.savefig(buf, format='png', facecolor='#888888')

run(icat + ['--clear', '--place', f'{cols}x{rows}@0x0'],
input=buf.getbuffer())
run(icat + ['--align', 'left'], input=buf.getbuffer())


@_Backend.export
Expand Down

0 comments on commit 76a7bbc

Please sign in to comment.