Skip to content

Commit

Permalink
Add configuration option to hide server commands from console and his…
Browse files Browse the repository at this point in the history
…tory.
  • Loading branch information
alexgobbo committed Mar 18, 2019
1 parent 4c152e2 commit b9f5941
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ch/psi/pshell/core/CommandSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public boolean isLocal() {
public boolean isRemote() {
return (this == terminal) || (this == server);
}

public boolean isDisplayable(){
return !this.isRemote() || !Context.getInstance().getConfig().hideServerMessages;
}
}
1 change: 1 addition & 0 deletions src/main/java/ch/psi/pshell/core/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Configuration extends Config {
public boolean dataScanPreserveTypes = false;
public boolean commandExecutionEvents = false;
public String hostName;
public boolean hideServerMessages = false;
public String logPath = TOKEN_LOGS + "/" + TOKEN_DATE + "_" + TOKEN_TIME;
public int logDaysToLive = -1;
public LogLevel logLevel = LogLevel.Info;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/psi/pshell/core/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,9 @@ Object evalLine(final CommandSource source, final String command) throws ScriptE
} finally {
try {
if (!command.trim().isEmpty()) {
history.put(command);
if (source.isDisplayable()){
history.put(command);
}
}
} catch (Exception ex) {
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/ch/psi/pshell/swing/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@ public boolean getPropagateVariableEvaluation() {
final ContextListener contextListener = new ContextAdapter() {
@Override
public void onShellCommand(CommandSource source, String command) {
output.append(Context.getInstance().getCursor(command) + command + "\n", (source == CommandSource.ui) ? INPUT_COLOR : REMOTE_COLOR);
if (source.isDisplayable()){
output.append(Context.getInstance().getCursor(command) + command + "\n", (source == CommandSource.ui) ? INPUT_COLOR : REMOTE_COLOR);
}
}

@Override
public void onShellResult(CommandSource source, Object result) {
if (result != null) {
if (result instanceof Throwable) {
output.append(Console.getPrintableMessage((Throwable) result) + "\n", ERROR_COLOR);
} else {
output.append(String.valueOf(result) + "\n", OUTPUT_COLOR);
if (source.isDisplayable()){
if (result instanceof Throwable) {
output.append(Console.getPrintableMessage((Throwable) result) + "\n", ERROR_COLOR);
} else {
output.append(String.valueOf(result) + "\n", (source == CommandSource.ui) ? OUTPUT_COLOR : REMOTE_COLOR);
}
}
}
}
Expand Down

0 comments on commit b9f5941

Please sign in to comment.