2121import org .rstudio .core .client .Stopwatch ;
2222import org .rstudio .core .client .StringUtil ;
2323import org .rstudio .core .client .regex .Pattern ;
24- import org .rstudio .studio .client .RStudioGinjector ;
2524import org .rstudio .studio .client .application .Desktop ;
2625import org .rstudio .studio .client .common .console .ConsoleOutputEvent ;
2726import org .rstudio .studio .client .common .console .ConsoleProcess ;
3130import org .rstudio .studio .client .server .ServerRequestCallback ;
3231import org .rstudio .studio .client .server .Void ;
3332import org .rstudio .studio .client .server .VoidServerRequestCallback ;
34- import org .rstudio .studio .client .workbench .prefs .model .UIPrefs ;
3533import org .rstudio .studio .client .workbench .views .terminal .events .TerminalDataInputEvent ;
3634import org .rstudio .studio .client .workbench .views .terminal .xterm .XTermWidget ;
3735
3836import com .google .gwt .core .client .GWT ;
3937import com .google .gwt .event .shared .HandlerRegistration ;
40- import com .google .inject .Inject ;
4138import com .sksamuel .gwt .websockets .CloseEvent ;
4239import com .sksamuel .gwt .websockets .Websocket ;
4340import com .sksamuel .gwt .websockets .WebsocketListenerExt ;
@@ -99,7 +96,7 @@ long duration()
9996 }
10097
10198 private String input_ ;
102- private Stopwatch stopWatch_ = new Stopwatch ();
99+ private Stopwatch stopWatch_ = new Stopwatch (false );
103100 private long duration_ ;
104101 }
105102
@@ -119,12 +116,7 @@ public void outputReceived(String output)
119116 if (item == null )
120117 return ;
121118
122- long average = 0 ;
123- if (accumulatedPoints_ > 0 )
124- {
125- average = accumulatedTime_ / accumulatedPoints_ ;
126- }
127- if (!item .matches (output , average ))
119+ if (!item .matches (output , average ()))
128120 {
129121 // output not what we expected, reset the whole list
130122 pending_ .clear ();
@@ -136,6 +128,20 @@ public void outputReceived(String output)
136128 }
137129 }
138130
131+ private long average ()
132+ {
133+ if (accumulatedPoints_ > 0 )
134+ {
135+ return accumulatedTime_ / accumulatedPoints_ ;
136+ }
137+ return 0 ;
138+ }
139+
140+ public String averageTimeMsg ()
141+ {
142+ return Long .toString (average ()) + "ms" ;
143+ }
144+
139145 private LinkedList <InputDatapoint > pending_ ;
140146 private long accumulatedPoints_ ;
141147 private long accumulatedTime_ ;
@@ -149,29 +155,16 @@ public void outputReceived(String output)
149155 public TerminalSessionSocket (Session session ,
150156 XTermWidget xterm )
151157 {
152- RStudioGinjector .INSTANCE .injectMembers (this );
153-
154158 session_ = session ;
155159 xterm_ = xterm ;
156160 localEcho_ = new TerminalLocalEcho (xterm_ );
157161
158162 // Show delay between receiving a keystroke and sending it to the
159- // terminal emulator; for diagnostics on laggy typing. Intended for
160- // brief use from a command-prompt. Time between input/display shown
161- // in console.
162- reportTypingLag_ = uiPrefs_ .enableReportTerminalLag ().getValue ();
163- if (reportTypingLag_ )
164- {
165- inputEchoTiming_ = new InputEchoTimeMonitor ();
166- }
163+ // terminal emulator; for diagnostics on laggy typing.
164+ // Time between input/display shown in terminal diagnostics dialog.
165+ inputEchoTiming_ = new InputEchoTimeMonitor ();
167166 }
168167
169- @ Inject
170- private void initialize (UIPrefs uiPrefs )
171- {
172- uiPrefs_ = uiPrefs ;
173- }
174-
175168 /**
176169 * Connect the input/output channel to the server. This requires that
177170 * an rsession has already been started via RPC and the consoleProcess
@@ -360,16 +353,14 @@ public void dispatchOutput(String output, boolean detectLocalEcho)
360353 @ Override
361354 public void onTerminalDataInput (TerminalDataInputEvent event )
362355 {
363- if (reportTypingLag_ )
364- inputEchoTiming_ .inputReceived (event .getData ());
356+ inputEchoTiming_ .inputReceived (event .getData ());
365357 session_ .receivedInput (event .getData ());
366358 }
367359
368360 @ Override
369361 public void onConsoleOutput (ConsoleOutputEvent event )
370362 {
371- if (reportTypingLag_ )
372- inputEchoTiming_ .outputReceived (event .getOutput ());
363+ inputEchoTiming_ .outputReceived (event .getOutput ());
373364 session_ .receivedOutput (event .getOutput ());
374365 }
375366
@@ -430,13 +421,17 @@ private void diagnostic(String msg)
430421 diagnostic_ .append (msg );
431422 diagnostic_ .append ("\n " );
432423 }
424+
425+ public String getTypingLagMsg ()
426+ {
427+ return inputEchoTiming_ .averageTimeMsg ();
428+ }
433429
434430 private HandlerRegistrations registrations_ = new HandlerRegistrations ();
435431 private final Session session_ ;
436432 private final XTermWidget xterm_ ;
437433 private ConsoleProcess consoleProcess_ ;
438434 private HandlerRegistration terminalInputHandler_ ;
439- private boolean reportTypingLag_ ;
440435 private InputEchoTimeMonitor inputEchoTiming_ ;
441436 private Websocket socket_ ;
442437 private TerminalLocalEcho localEcho_ ;
@@ -448,7 +443,4 @@ private void diagnostic(String msg)
448443
449444 public static final Pattern PASSWORD_PATTERN =
450445 Pattern .create (PASSWORD_REGEX , "im" );
451-
452- // Injected ----
453- private UIPrefs uiPrefs_ ;
454446}
0 commit comments