Skip to content

Commit

Permalink
Experimental UI: increase progress rate limit with time, if no in-pla…
Browse files Browse the repository at this point in the history
…ce update

In the experimental UI, increase the rate limit for updates to the progress
bar over time, if it cannot be updated in place. In this way, we can get snappy
first progress descriptions, while not overwhelming the user with too many progress
messages.

Change-Id: I769f1a9ef4304b613d40ece42b87df22881549cd
PiperOrigin-RevId: 152502295
  • Loading branch information
aehlig authored and buchgr committed Apr 10, 2017
1 parent d6fec93 commit fa29175
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public class ExperimentalEventHandler implements EventHandler {
private static Logger LOG = Logger.getLogger(ExperimentalEventHandler.class.getName());
/** Latest refresh of the progress bar, if contents other than time changed */
static final long MAXIMAL_UPDATE_DELAY_MILLIS = 200L;
/** Minimal rate limiting, if the progress bar cannot be updated in place */
static final long NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT = 2000L;
/** Minimal rate limiting (in ms), if the progress bar cannot be updated in place */
static final long NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT = 1000L;
/**
* Minimal rate limiting, as fraction of the request time so far, if the progress bar cannot be
* updated in place
*/
static final double NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT = 0.15;
/** Periodic update interval of a time-dependent progress bar if it can be updated in place */
static final long SHORT_REFRESH_MILLIS = 1000L;
/** Periodic update interval of a time-dependent progress bar if it cannot be updated in place */
Expand All @@ -64,17 +69,18 @@ public class ExperimentalEventHandler implements EventHandler {
private static final DateTimeFormatter TIMESTAMP_FORMAT =
DateTimeFormat.forPattern("(HH:mm:ss.SSS) ");

private final long minimalDelayMillis;
private final boolean cursorControl;
private final Clock clock;
private final long uiStartTimeMillis;
private final AnsiTerminal terminal;
private final boolean debugAllEvents;
private final ExperimentalStateTracker stateTracker;
private final long minimalUpdateInterval;
private final boolean showProgress;
private final boolean progressInTermTitle;
private final boolean showTimestamp;
private final OutErr outErr;
private long minimalDelayMillis;
private long minimalUpdateInterval;
private long lastRefreshMillis;
private long mustRefreshAfterMillis;
private int numLinesProgressBar;
Expand All @@ -96,6 +102,7 @@ public ExperimentalEventHandler(
this.progressInTermTitle = options.progressInTermTitle && options.useCursorControl();
this.showTimestamp = options.showTimestamp;
this.clock = clock;
this.uiStartTimeMillis = clock.currentTimeMillis();
this.debugAllEvents = options.experimentalUiDebugAllEvents;
// If we have cursor control, we try to fit in the terminal width to avoid having
// to wrap the progress bar. We will wrap the progress bar to terminalWidth - 1
Expand Down Expand Up @@ -447,6 +454,17 @@ private void doRefresh(boolean fromUpdateThread) {
clearProgressBar();
addProgressBar();
terminal.flush();
if (!cursorControl) {
// If we can't update the progress bar in place, make sure we increase the update
// interval as time progresses, to avoid too many progress messages in place.
minimalDelayMillis =
Math.max(
minimalDelayMillis,
Math.round(
NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT
* (clock.currentTimeMillis() - uiStartTimeMillis)));
minimalUpdateInterval = Math.max(minimalDelayMillis, MAXIMAL_UPDATE_DELAY_MILLIS);
}
}
} catch (IOException e) {
LOG.warning("IO Error writing to output stream: " + e);
Expand Down

0 comments on commit fa29175

Please sign in to comment.