X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FECMA48.java;h=e3e7c929397a9b417324933a1057b057638ac57f;hb=9917c620116aa68ebf5d74afaeec44416b314729;hp=c277795d69450b2db44f79d77a1caa8062c11275;hpb=955c55b766a8aebb528d5af5f7582a857c72e2f5;p=fanfix.git diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index c277795..e3e7c92 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -1078,6 +1078,64 @@ public class ECMA48 implements Runnable { return display; } + /** + * Get the visible display + scrollback buffer, offset by a specified + * number of rows from the bottom. + * + * @param visibleHeight the total height of the display to show + * @param scrollBottom the number of rows from the bottom to scroll back + * @return a copy of the display + scrollback buffers + */ + public final List getVisibleDisplay(final int visibleHeight, + final int scrollBottom) { + + assert (visibleHeight >= 0); + assert (scrollBottom >= 0); + + int visibleBottom = scrollback.size() + display.size() - scrollBottom; + + List preceedingBlankLines = new ArrayList(); + int visibleTop = visibleBottom - visibleHeight; + if (visibleTop < 0) { + for (int i = visibleTop; i < 0; i++) { + preceedingBlankLines.add(getBlankDisplayLine()); + } + visibleTop = 0; + } + assert (visibleTop >= 0); + + List displayLines = new ArrayList(); + displayLines.addAll(scrollback); + displayLines.addAll(display); + + List visibleLines = new ArrayList(); + visibleLines.addAll(preceedingBlankLines); + visibleLines.addAll(displayLines.subList(visibleTop, visibleBottom)); + + // Fill in the blank lines on bottom + int bottomBlankLines = visibleHeight - visibleLines.size(); + assert (bottomBlankLines >= 0); + for (int i = 0; i < bottomBlankLines; i++) { + visibleLines.add(getBlankDisplayLine()); + } + + return copyBuffer(visibleLines); + } + + /** + * Copy a display buffer. + * + * @param buffer the buffer to copy + * @return a deep copy of the buffer's data + */ + private List copyBuffer(final List buffer) { + ArrayList result = new ArrayList(buffer.size()); + for (DisplayLine line: buffer) { + result.add(new DisplayLine(line)); + } + return result; + } + /** * Get the display width. *