Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/jboss/jreadline/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* A console reader.
* Supports ansi terminals
*
* @author Ståle W. Pedersen <stale.pedersen@jboss.org>
* @author Ståle W. Pedersen <stale.pedersen@jboss.org>
*/
public class Console {

Expand Down Expand Up @@ -354,7 +354,8 @@ public ConsoleOutput read(String prompt, Character mask) throws IOException {
result = parseOperation(operation, mask);

if(result != null) {
operations = ControlOperatorParser.findAllControlOperators(result);
operations = ControlOperatorParser.findAllControlOperators(result,
settings.isOperationsEnabled());
ConsoleOutput output = parseOperations();
output = processInternalCommands(output);
if(output.getBuffer() != null) {
Expand Down Expand Up @@ -865,7 +866,7 @@ private void drawLine(String line) throws IOException {
for(int i=0; i<currentRow; i++)
terminal.writeToStdOut(Buffer.printAnsi("A")); //move to top

terminal.writeToStdOut(Buffer.printAnsi("0G")); //clear
terminal.writeToStdOut("\r"); //clear

terminal.writeToStdOut(line);
//if the current line.length < compared to previous we add spaces to the end
Expand All @@ -884,7 +885,7 @@ private void drawLine(String line) throws IOException {
else {
terminal.writeToStdOut(Buffer.printAnsi("s")); //save cursor
//move cursor to 0. - need to do this to clear the entire line
terminal.writeToStdOut(Buffer.printAnsi("0G"));
terminal.writeToStdOut("\r");
terminal.writeToStdOut(Buffer.printAnsi("2K")); // clear line

terminal.writeToStdOut(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.jboss.jreadline.console.operator;

import org.jboss.jreadline.console.ConsoleOperation;
import org.jboss.jreadline.console.operator.ControlOperator;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -81,88 +82,84 @@ private static int findLastRedirectionOrPipelinePositionBeforeCursor(Pattern pat
}
return end;
}

/**
* Parse buffer checking redirection operations
*
* @param buffer
* text
* @return all RedirectionOperations
*/
public static List<ConsoleOperation> findAllControlOperators(String buffer) {
return findAllControlOperators(buffer, true);
}

/**
* Parse buffer and find all RedirectionOperations
* Parse buffer
*
* @param buffer text
* @param buffer
* text
* @param checkOperations if true check and find operations otherwise skip this step
* @return all RedirectionOperations
*/
public static List<ConsoleOperation> findAllControlOperators(String buffer) {
Matcher matcher = controlOperatorPattern.matcher(buffer);
public static List<ConsoleOperation> findAllControlOperators(String buffer, boolean checkOperations) {
List<ConsoleOperation> reOpList = new ArrayList<ConsoleOperation>();

while(matcher.find()) {
if(matcher.group(1) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.OVERWRITE_OUT_AND_ERR,
buffer.substring(0, matcher.start(1))));
buffer = buffer.substring(matcher.end(1));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(2) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.APPEND_ERR,
buffer.substring(0, matcher.start(2))));
buffer = buffer.substring(matcher.end(2));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(3) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.OVERWRITE_ERR,
buffer.substring(0, matcher.start(3))));
buffer = buffer.substring(matcher.end(3));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(4) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.APPEND_OUT,
buffer.substring(0, matcher.start(4))));
buffer = buffer.substring(matcher.end(4));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(5) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.OVERWRITE_OUT,
buffer.substring(0, matcher.start(5))));
buffer = buffer.substring(matcher.end(5));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(6) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.OVERWRITE_IN,
buffer.substring(0, matcher.start(6))));
buffer = buffer.substring(matcher.end(6));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(7) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.PIPE_OUT_AND_ERR,
buffer.substring(0, matcher.start(7))));
buffer = buffer.substring(matcher.end(7));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(8) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.PIPE,
buffer.substring(0, matcher.start(8))));
buffer = buffer.substring(matcher.end(8));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(9) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.END,
buffer.substring(0, matcher.start(9))));
buffer = buffer.substring(matcher.end(9));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(10) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.AND,
buffer.substring(0, matcher.start(10))));
buffer = buffer.substring(matcher.end(10));
matcher = controlOperatorPattern.matcher(buffer);
}
else if(matcher.group(11) != null) {
reOpList.add( new ConsoleOperation(ControlOperator.AMP,
buffer.substring(0, matcher.start(11))));
buffer = buffer.substring(matcher.end(11));
matcher = controlOperatorPattern.matcher(buffer);
if (checkOperations) {
Matcher matcher = controlOperatorPattern.matcher(buffer);
while (matcher.find()) {
if (matcher.group(1) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.OVERWRITE_OUT_AND_ERR, buffer.substring(0,
matcher.start(1))));
buffer = buffer.substring(matcher.end(1));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(2) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.APPEND_ERR, buffer.substring(0, matcher.start(2))));
buffer = buffer.substring(matcher.end(2));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(3) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.OVERWRITE_ERR, buffer.substring(0, matcher.start(3))));
buffer = buffer.substring(matcher.end(3));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(4) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.APPEND_OUT, buffer.substring(0, matcher.start(4))));
buffer = buffer.substring(matcher.end(4));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(5) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.OVERWRITE_OUT, buffer.substring(0, matcher.start(5))));
buffer = buffer.substring(matcher.end(5));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(6) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.OVERWRITE_IN, buffer.substring(0, matcher.start(6))));
buffer = buffer.substring(matcher.end(6));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(7) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.PIPE_OUT_AND_ERR, buffer.substring(0,
matcher.start(7))));
buffer = buffer.substring(matcher.end(7));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(8) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.PIPE, buffer.substring(0, matcher.start(8))));
buffer = buffer.substring(matcher.end(8));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(9) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.END, buffer.substring(0, matcher.start(9))));
buffer = buffer.substring(matcher.end(9));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(10) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.AND, buffer.substring(0, matcher.start(10))));
buffer = buffer.substring(matcher.end(10));
matcher = controlOperatorPattern.matcher(buffer);
} else if (matcher.group(11) != null) {
reOpList.add(new ConsoleOperation(ControlOperator.AMP, buffer.substring(0, matcher.start(11))));
buffer = buffer.substring(matcher.end(11));
matcher = controlOperatorPattern.matcher(buffer);
}
}
}
if(reOpList.size() == 0)
reOpList.add(new ConsoleOperation( ControlOperator.NONE, buffer));
if(buffer.trim().length() > 0)
if (reOpList.size() == 0)
reOpList.add(new ConsoleOperation(ControlOperator.NONE, buffer));
if (buffer.trim().length() > 0)
reOpList.add(new ConsoleOperation(ControlOperator.NONE, buffer));

return reOpList;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jboss/jreadline/console/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Settings {
private KeyOperationManager operationManager = new KeyOperationManager();
private File aliasFile;
private boolean aliasEnabled = true;
private boolean operationsEnabled = true;

private static final Settings INSTANCE = new Settings();

Expand Down Expand Up @@ -80,6 +81,7 @@ public void resetToDefaults() {
setQuitHandler(null);
operationManager.clear();
setAliasEnabled(true);
setOperationsEnabled(true);
}

/**
Expand Down Expand Up @@ -498,6 +500,14 @@ public boolean isAliasEnabled() {
public void setAliasEnabled(boolean enabled) {
aliasEnabled = enabled;
}

public boolean isOperationsEnabled() {
return operationsEnabled;
}

public void setOperationsEnabled(boolean operationsEnabled) {
this.operationsEnabled = operationsEnabled;
}

public void setQuitHandler(QuitHandler qh) {
quitHandler = qh;
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/org/jboss/jreadline/terminal/POSIXTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ public void writeToStdErr(char err) throws IOException {
*/
@Override
public int getHeight() {
if(height < 0) {
try {
height = getTerminalProperty("rows");
}
catch (Exception e) {
logger.severe("Failed to fetch terminal height: "+e.getMessage());
}
try {
height = getTerminalProperty("rows");
}
catch (Exception e) {
logger.severe("Failed to fetch terminal height: "+e.getMessage());
}
//cant use height < 0
if(height < 0)
Expand All @@ -178,13 +176,11 @@ public int getHeight() {
*/
@Override
public int getWidth() {
if(width < 0) {
try {
width = getTerminalProperty("columns");
}
catch (Exception e) {
logger.severe("Failed to fetch terminal width: "+e.getMessage());
}
try {
width = getTerminalProperty("columns");
}
catch (Exception e) {
logger.severe("Failed to fetch terminal width: "+e.getMessage());
}
//cant use with < 0
if(width < 0)
Expand Down