Max out display update rate at every 10 ms

This commit is contained in:
Guillaume Nodet
2020-02-17 12:01:10 +01:00
parent 7002f127a0
commit a6248fc919

View File

@@ -139,6 +139,7 @@ public class Client {
Display display = new Display(terminal, false); Display display = new Display(terminal, false);
boolean exit = false; boolean exit = false;
BuildException error = null; BuildException error = null;
long lastUpdate = 0;
while (!exit) { while (!exit) {
Message m = daemon.receive(); Message m = daemon.receive();
if (m instanceof BuildException) { if (m instanceof BuildException) {
@@ -160,21 +161,26 @@ public class Client {
case ProjectStopped: case ProjectStopped:
projects.remove(be.projectId); projects.remove(be.projectId);
} }
// no need to refresh the display at every single step
long curTime = System.currentTimeMillis();
if (curTime - lastUpdate >= 10) {
Size size = terminal.getSize(); Size size = terminal.getSize();
display.resize(size.getRows(), size.getColumns()); display.resize(size.getRows(), size.getColumns());
List<AttributedString> lines = new ArrayList<>(); List<AttributedString> lines = new ArrayList<>();
projects.values().stream() projects.values().stream()
.map(AttributedString::fromAnsi) .map(AttributedString::fromAnsi)
.map(s -> s.columnSubSequence(0, size.getColumns())) .map(s -> s.columnSubSequence(0, size.getColumns() - 1))
.forEachOrdered(lines::add); .forEachOrdered(lines::add);
// Make sure we don't try to display more lines than the terminal height // Make sure we don't try to display more lines than the terminal height
boolean rem = false; int rem = 0;
while (lines.size() >= terminal.getHeight()) { while (lines.size() >= terminal.getHeight()) {
lines.remove(0); lines.remove(0);
rem = true; rem++;
} }
lines.add(0, new AttributedString(rem ? "Building... (trimmed)" : "Building...")); lines.add(0, new AttributedString("Building..." + (rem > 0 ? " (" + rem + " more)" : "")));
display.update(lines, -1); display.update(lines, -1);
lastUpdate = curTime;
}
} else if (m instanceof BuildMessage) { } else if (m instanceof BuildMessage) {
BuildMessage bm = (BuildMessage) m; BuildMessage bm = (BuildMessage) m;
log.add(bm.getMessage()); log.add(bm.getMessage());