Closed mokun closed 5 years ago
No, this is beyond the scope of Text-IO. You could in principle add this capability to the SwingTextTerminal, but it's not trivial.
oh okay. Now I'll be less ambitious :D
But say, I'd like to refresh a bunch of numbers to the terminal and unfortunately, it needs to occupy 3 lines, instead of just 1 line that your Weather class can do.
Is there any quick way to delete the last 3 lines from the bottom of the screen and then redraw them over ?
I'm looking at the method resetLine()
in SwingTextTerminal
. It calls up resetToOffset(startLineOffset)
.
@Override
public boolean resetLine() {
return resetToOffset(startLineOffset);
}
public boolean resetToOffset(int offset) {
if(offset < 0) return false;
display();
synchronized (editLock) {
boolean result = true;
int len = document.getLength() - offset;
if(len > 0) {
int oldStartReadLen = startReadLen;
if(startReadLen > offset) {
startReadLen = offset;
}
try {
document.remove(offset, len);
} catch (BadLocationException e) {
logger.error("Cannot reset to offset " + offset, e);
startReadLen = oldStartReadLen;
result = false;
}
textPane.setCaretPosition(document.getLength());
}
return result;
}
}
You need to set a bookmark at the beginning of the block you want to refresh. Then, you call resetToBookmark
when you want to delete all lines after this bookmark. The Weather application also uses this technique.
okay. Closing this.
Is there a way to go beyond changing the value on the whole screen or the value on, say, the 5th line from the bottom of the screen ?
I can see in the Weather that it calls
terminal.resetLine()
andterminal.moveToLineStart()
to refresh the value of the very last line on the screen.In TextTerminal, there is :
We can literally build a game out of the text terminal if we can give the ability to change the value of a text with, say, overwrite(x,y), where x being the x-th position from the left, y being the y-th line from the bottom.