From: Kevin Lamonte Date: Wed, 13 Nov 2019 18:25:08 +0000 (-0600) Subject: limit images in scrollback X-Git-Tag: fanfix-swing-0.0.1~12^2~13^2^2~11 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=564040def0ab28b40a9571aca3622643e28451f4;p=fanfix-swing.git limit images in scrollback --- diff --git a/src/jexer/tterminal/DisplayLine.java b/src/jexer/tterminal/DisplayLine.java index 06a05a33..87e6952f 100644 --- a/src/jexer/tterminal/DisplayLine.java +++ b/src/jexer/tterminal/DisplayLine.java @@ -248,4 +248,29 @@ public class DisplayLine { chars[chars.length - 1] = new Cell(newCell); } + /** + * Determine if line contains image data. + * + * @return true if the line has image data + */ + public boolean isImage() { + for (int i = 0; i < chars.length; i++) { + if (chars[i].isImage()) { + return true; + } + } + return false; + } + + /** + * Clear image data from line. + */ + public void clearImages() { + for (int i = 0; i < chars.length; i++) { + if (chars[i].isImage()) { + chars[i].reset(); + } + } + } + } diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index c6aa0b21..5d7eaaa0 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -274,7 +274,7 @@ public class ECMA48 implements Runnable { /** * The maximum number of lines in the scrollback buffer. */ - private int maxScrollback = 10000; + private int scrollbackMax = 10000; /** * The terminal's input. For type == XTERM, this is an InputStreamReader @@ -1255,10 +1255,29 @@ public class ECMA48 implements Runnable { display.add(line); } while (display.size() > height) { - scrollback.add(display.remove(0)); + appendScrollbackLine(display.remove(0)); } } + /** + * Get the maximum number of lines in the scrollback buffer. + * + * @return the maximum number of lines in the scrollback buffer + */ + public int getScrollbackMax() { + return scrollbackMax; + } + + /** + * Set the maximum number of lines for the scrollback buffer. + * + * @param scrollbackMax the maximum number of lines for the scrollback + * buffer + */ + public final void setScrollbackMax(final int scrollbackMax) { + this.scrollbackMax = scrollbackMax; + } + /** * Get visible cursor flag. * @@ -1452,14 +1471,25 @@ public class ECMA48 implements Runnable { toGround(); } + /** + * Append a to the scrollback buffer, clearing image data for lines more + * than three screenfuls in. + */ + private void appendScrollbackLine(DisplayLine line) { + scrollback.add(line); + if (scrollback.size() > height * 3) { + scrollback.get(scrollback.size() - (height * 3)).clearImages(); + } + } + /** * Append a new line to the bottom of the display, adding lines off the * top to the scrollback buffer. */ private void newDisplayLine() { // Scroll the top line off into the scrollback buffer - scrollback.add(display.get(0)); - if (scrollback.size() > maxScrollback) { + appendScrollbackLine(display.get(0)); + while (scrollback.size() > scrollbackMax) { scrollback.remove(0); scrollback.trimToSize(); }