Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rstudio/rstudio
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Jan 2, 2012
2 parents 1fd6acd + e62db2c commit b9d0b94
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/cpp/session/consoleio/ConsoleIOMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ BOOL capture_console_output(HANDLE hConsoleOut, std::string* pOutput)
{
return false;
}

// Remove trailing spaces
std::string::iterator trimPos = pOutput->end();
while (trimPos != pOutput->begin())
{
if (*(trimPos-1) != ' ')
break;
trimPos--;
}
pOutput->erase(trimPos, pOutput->end());

pOutput->push_back('\r');
pOutput->push_back('\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
package org.rstudio.studio.client.common.shell;


import com.google.gwt.user.client.Window;
import org.rstudio.core.client.BrowseCap;
import org.rstudio.core.client.CommandWithArg;
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.command.KeyboardShortcut;
import org.rstudio.studio.client.application.Desktop;
import org.rstudio.studio.client.common.CommandLineHistory;
Expand Down Expand Up @@ -49,13 +51,34 @@ public void setHistoryEnabled(boolean enabled)
{
historyEnabled_ = enabled;
}

@Override
public void consoleWriteOutput(String output)
{
display_.consoleWriteOutput(output);
output = maybeSuppressOutputPrefix(output);
if (StringUtil.isNullOrEmpty(output))
return;

display_.consoleWriteOutput(output);
}


private String maybeSuppressOutputPrefix(String output)
{
if (!Desktop.isDesktop() || !BrowseCap.isWindows())
return output;

if (StringUtil.isNullOrEmpty(outputPrefixToSuppress_))
return output;

String prefix = outputPrefixToSuppress_;
outputPrefixToSuppress_ = null;

if (output.startsWith(prefix))
return output.substring(prefix.length());

return output;
}

@Override
public void consoleWriteError(String error)
{
Expand Down Expand Up @@ -85,15 +108,15 @@ private void processInput(final CommandWithArg<ShellInput> onInputReady)
// input is entry + newline
String input = commandEntry + "\n";

outputPrefixToSuppress_ = null;
// update console with prompt and input
display_.consoleWritePrompt(promptText);
final boolean echoInput = showInputForPrompt(promptText);
if (!Desktop.isDesktop() || !BrowseCap.isWindows())
if (echoInput)
{
if (echoInput)
display_.consoleWriteInput(input);
else
display_.consoleWriteInput("\n");
display_.consoleWriteInput(input);
if (Desktop.isDesktop() && BrowseCap.isWindows())
outputPrefixToSuppress_ = commandEntry;
}

// encrypt the input and return it
Expand Down Expand Up @@ -288,4 +311,17 @@ public void onError(ServerError error)

private final CryptoServerOperations server_;
private PublicKeyInfo publicKeyInfo_ = null;

/* Hack to fix echoing problems on Windows.
* For echoed input like username, Windows always echoes input back to the
* client. We don't have a good way to avoid this happening on the server,
* nor can we simply not echo locally on the client because there is a
* several-hundred-millisecond delay between when we send input and when the
* server echoes it back to us (normally would be a much shorter delay but
* consoleio.exe makes it longer due to console polling instead of
* streaming). Therefore, we echo the input locally, and then look for the
* same string at the head of the next output event. If we find it, we strip
* it off.
*/
private String outputPrefixToSuppress_;
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public ConsoleProgressDialog(String title,
style.setWidth(width, Unit.PX);

display_.setMaxOutputLines(getMaxOutputLines());
if (Desktop.isDesktop() && BrowseCap.isWindows())
display_.setSuppressPendingInput(true);
display_.setSuppressPendingInput(true);

if (getInteractionMode() != ConsoleProcessInfo.INTERACTION_NEVER)
{
Expand Down

0 comments on commit b9d0b94

Please sign in to comment.