@@ -81,27 +81,19 @@ public final class UiEventHandler implements EventHandler {
81
81
82
82
private static final GoogleLogger logger = GoogleLogger .forEnclosingClass ();
83
83
84
- /** Latest refresh of the progress bar, if contents other than time changed */
85
- private static final long MAXIMAL_UPDATE_DELAY_MILLIS = 200L ;
84
+ /** Minimal time between scheduled updates */
85
+ private static final long MINIMAL_UPDATE_INTERVAL_MILLIS = 200L ;
86
86
/** Minimal rate limiting (in ms), if the progress bar cannot be updated in place */
87
87
private static final long NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT = 1000L ;
88
- /**
89
- * Minimal rate limiting, as fraction of the request time so far, if the progress bar cannot be
90
- * updated in place
91
- */
92
- private static final double NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT = 0.15 ;
93
88
/** Periodic update interval of a time-dependent progress bar if it can be updated in place */
94
89
private static final long SHORT_REFRESH_MILLIS = 1000L ;
95
- /** Periodic update interval of a time-dependent progress bar if it cannot be updated in place */
96
- private static final long LONG_REFRESH_MILLIS = 20000L ;
97
90
98
91
private static final DateTimeFormatter TIMESTAMP_FORMAT =
99
92
DateTimeFormatter .ofPattern ("(HH:mm:ss) " );
100
93
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter .ofPattern ("yyyy-MM-dd" );
101
94
102
95
private final boolean cursorControl ;
103
96
private final Clock clock ;
104
- private final long uiStartTimeMillis ;
105
97
private final AnsiTerminal terminal ;
106
98
private final boolean debugAllEvents ;
107
99
private final UiStateTracker stateTracker ;
@@ -111,7 +103,7 @@ public final class UiEventHandler implements EventHandler {
111
103
private final boolean showTimestamp ;
112
104
private final OutErr outErr ;
113
105
private final ImmutableSet <EventKind > filteredEvents ;
114
- private long minimalDelayMillis ;
106
+ private long progressRateLimitMillis ;
115
107
private long minimalUpdateInterval ;
116
108
private long lastRefreshMillis ;
117
109
private long mustRefreshAfterMillis ;
@@ -175,7 +167,6 @@ public UiEventHandler(
175
167
this .progressInTermTitle = options .progressInTermTitle && options .useCursorControl ();
176
168
this .showTimestamp = options .showTimestamp ;
177
169
this .clock = clock ;
178
- this .uiStartTimeMillis = clock .currentTimeMillis ();
179
170
this .debugAllEvents = options .experimentalUiDebugAllEvents ;
180
171
this .locationPrinter =
181
172
new LocationPrinter (options .attemptToPrintRelativePaths , workspacePathFragment );
@@ -200,14 +191,15 @@ public UiEventHandler(
200
191
this .stateTracker .setProgressSampleSize (options .uiActionsShown );
201
192
this .numLinesProgressBar = 0 ;
202
193
if (this .cursorControl ) {
203
- this .minimalDelayMillis = Math .round (options .showProgressRateLimit * 1000 );
194
+ this .progressRateLimitMillis = Math .round (options .showProgressRateLimit * 1000 );
204
195
} else {
205
- this .minimalDelayMillis =
196
+ this .progressRateLimitMillis =
206
197
Math .max (
207
198
Math .round (options .showProgressRateLimit * 1000 ),
208
199
NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT );
209
200
}
210
- this .minimalUpdateInterval = Math .max (this .minimalDelayMillis , MAXIMAL_UPDATE_DELAY_MILLIS );
201
+ this .minimalUpdateInterval =
202
+ Math .max (this .progressRateLimitMillis , MINIMAL_UPDATE_INTERVAL_MILLIS );
211
203
this .stdoutLineBuffer = new ByteArrayOutputStream ();
212
204
this .stderrLineBuffer = new ByteArrayOutputStream ();
213
205
this .dateShown = false ;
@@ -854,7 +846,7 @@ private void doRefresh(boolean fromUpdateThread) {
854
846
return ;
855
847
}
856
848
long nowMillis = clock .currentTimeMillis ();
857
- if (lastRefreshMillis + minimalDelayMillis < nowMillis ) {
849
+ if (lastRefreshMillis + progressRateLimitMillis < nowMillis ) {
858
850
if (updateLock .tryLock ()) {
859
851
try {
860
852
synchronized (this ) {
@@ -863,17 +855,6 @@ private void doRefresh(boolean fromUpdateThread) {
863
855
clearProgressBar ();
864
856
addProgressBar ();
865
857
terminal .flush ();
866
- if (!cursorControl ) {
867
- // If we can't update the progress bar in place, make sure we increase the update
868
- // interval as time progresses, to avoid too many progress messages in place.
869
- minimalDelayMillis =
870
- Math .max (
871
- minimalDelayMillis ,
872
- Math .round (
873
- NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT
874
- * (clock .currentTimeMillis () - uiStartTimeMillis )));
875
- minimalUpdateInterval = Math .max (minimalDelayMillis , MAXIMAL_UPDATE_DELAY_MILLIS );
876
- }
877
858
}
878
859
}
879
860
} catch (IOException e ) {
@@ -901,7 +882,7 @@ private void refreshSoon() {
901
882
// a future update scheduled.
902
883
long nowMillis = clock .currentTimeMillis ();
903
884
if (mustRefreshAfterMillis <= lastRefreshMillis ) {
904
- mustRefreshAfterMillis = Math .max (nowMillis + minimalUpdateInterval , lastRefreshMillis + 1 );
885
+ mustRefreshAfterMillis = Math .max (nowMillis + 1 , lastRefreshMillis + minimalUpdateInterval );
905
886
}
906
887
startUpdateThread ();
907
888
}
@@ -911,22 +892,25 @@ private synchronized boolean timeBasedRefresh() {
911
892
if (!stateTracker .progressBarTimeDependent ()) {
912
893
return false ;
913
894
}
895
+ // Don't do more updates than are requested through events when there is no cursor control.
896
+ if (!cursorControl ) {
897
+ return false ;
898
+ }
914
899
long nowMillis = clock .currentTimeMillis ();
915
- long intervalMillis = cursorControl ? SHORT_REFRESH_MILLIS : LONG_REFRESH_MILLIS ;
916
900
if (lastRefreshMillis < mustRefreshAfterMillis
917
- && mustRefreshAfterMillis < nowMillis + minimalDelayMillis ) {
918
- // Within the small interval from now, an update is scheduled anyway,
901
+ && mustRefreshAfterMillis < nowMillis + progressRateLimitMillis ) {
902
+ // Within a small interval from now, an update is scheduled anyway,
919
903
// so don't do a time-based update of the progress bar now, to avoid
920
904
// updates too close to each other.
921
905
return false ;
922
906
}
923
- return lastRefreshMillis + intervalMillis < nowMillis ;
907
+ return lastRefreshMillis + SHORT_REFRESH_MILLIS < nowMillis ;
924
908
}
925
909
926
910
private void ignoreRefreshLimitOnce () {
927
911
// Set refresh time variables in a state such that the next progress bar
928
912
// update will definitely be written out.
929
- lastRefreshMillis = clock .currentTimeMillis () - minimalDelayMillis - 1 ;
913
+ lastRefreshMillis = clock .currentTimeMillis () - progressRateLimitMillis - 1 ;
930
914
}
931
915
932
916
private void startUpdateThread () {
0 commit comments