Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils updates for sqlcl #1111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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: 3 additions & 6 deletions builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
*
* Based on http://antony.lesuisse.org/software/ajaxterm/
* Public Domain License
*/

/**
*
* See http://www.ecma-international.org/publications/standards/Ecma-048.htm
* and http://vt100.net/docs/vt510-rm/
*/

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/java/org/apache/felix/gogo/jline/Posix.java
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ public static class SortComparator implements Comparator<String> {
private char separator;
private List<Key> sortKeys;

@SuppressWarnings("this-escape")
public SortComparator(
boolean caseInsensitive,
boolean reverse,
Expand Down
9 changes: 5 additions & 4 deletions jansi-core/src/main/java/org/jline/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,11 @@ public String toString() {
return builder.toString();
}

///////////////////////////////////////////////////////////////////
// Private Helper Methods
///////////////////////////////////////////////////////////////////

/*
///////////////////////////////////////////////////////////////////
// Private Helper Methods
///////////////////////////////////////////////////////////////////
*/
private Ansi appendEscapeSequence(char command) {
flushAttributes();
builder.append(FIRST_ESC_CHAR);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
<java>
<toggleOffOn />
<palantirJavaFormat>
<version>2.38.0</version>
<version>2.39.0</version>
</palantirJavaFormat>
<importOrder>
<order>java|javax,org,,\#</order>
Expand Down
115 changes: 80 additions & 35 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@
import org.jline.terminal.Terminal.Signal;
import org.jline.terminal.Terminal.SignalHandler;
import org.jline.terminal.impl.AbstractWindowsTerminal;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.jline.utils.Curses;
import org.jline.utils.Display;
import org.jline.utils.*;
import org.jline.utils.InfoCmp.Capability;
import org.jline.utils.Log;
import org.jline.utils.Status;
import org.jline.utils.StyleResolver;
import org.jline.utils.WCWidth;

import static org.jline.keymap.KeyMap.alt;
import static org.jline.keymap.KeyMap.ctrl;
Expand Down Expand Up @@ -1200,26 +1192,31 @@ protected String finish(String str) {
}

protected synchronized void handleSignal(Signal signal) {
doAutosuggestion = false;
if (signal == Signal.WINCH) {
size.copy(terminal.getBufferSize());
display.resize(size.getRows(), size.getColumns());
Status status = Status.getStatus(terminal, false);
if (status != null) {
status.resize(size);
status.reset();
try {
lock.lock();
doAutosuggestion = false;
if (signal == Signal.WINCH) {
size.copy(terminal.getBufferSize());
display.resize(size.getRows(), size.getColumns());
Status status = Status.getStatus(terminal, false);
if (status != null) {
status.resize(size);
status.reset();
}
terminal.puts(Capability.carriage_return);
terminal.puts(Capability.clr_eos);
redrawLine();
redisplay();
} else if (signal == Signal.CONT) {
terminal.enterRawMode();
size.copy(terminal.getBufferSize());
display.resize(size.getRows(), size.getColumns());
terminal.puts(Capability.keypad_xmit);
redrawLine();
redisplay();
}
terminal.puts(Capability.carriage_return);
terminal.puts(Capability.clr_eos);
redrawLine();
redisplay();
} else if (signal == Signal.CONT) {
terminal.enterRawMode();
size.copy(terminal.getBufferSize());
display.resize(size.getRows(), size.getColumns());
terminal.puts(Capability.keypad_xmit);
redrawLine();
redisplay();
} finally {
lock.unlock();
}
}

Expand Down Expand Up @@ -3871,6 +3868,10 @@ public boolean redisplay() {
}

protected void redisplay(boolean flush) {
redisplay(flush, false);
}

protected void redisplay(boolean flush, boolean complete) {
try {
lock.lock();

Expand Down Expand Up @@ -3925,7 +3926,7 @@ protected void redisplay(boolean flush) {
full = sb.toAttributedString();
}

display.update(Collections.singletonList(full), cursor - smallTerminalOffset, flush);
display.update(Collections.singletonList(full), cursor - smallTerminalOffset, flush, complete);
return;
}

Expand Down Expand Up @@ -4007,7 +4008,7 @@ protected void redisplay(boolean flush) {
} else {
newLinesToDisplay = newLines;
}
display.update(newLinesToDisplay, cursorPos, flush);
display.update(newLinesToDisplay, cursorPos, flush, complete);
} finally {
lock.unlock();
}
Expand All @@ -4033,7 +4034,9 @@ private String matchPreviousCommand(String buffer) {
StringBuilder sb = new StringBuilder();
for (char c : buffer.replace("\\", "\\\\").toCharArray()) {
if (c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '^' || c == '*' || c == '$'
|| c == '.' || c == '?' || c == '+' || c == '|' || c == '<' || c == '>' || c == '!' || c == '-') {
|| c == '.' || c == '?'
|| c == '+') // BMGFIXX || c == '|' || c == '<' || c == '>' || c == '!' || c == '-')
{
sb.append('\\');
}
sb.append(c);
Expand Down Expand Up @@ -4130,6 +4133,11 @@ private AttributedString getHighlightedBuffer(String buffer) {
}

private AttributedString expandPromptPattern(String pattern, int padToWidth, String message, int line) {
return expandPromptPattern(pattern, padToWidth, message, line, false);
}

private AttributedString expandPromptPattern(
String pattern, int padToWidth, String message, int line, boolean currentLine) {
ArrayList<AttributedString> parts = new ArrayList<>();
boolean isHidden = false;
int padPartIndex = -1;
Expand Down Expand Up @@ -4177,6 +4185,9 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str
case 'N':
sb.append(getInt(LINE_OFFSET, 0) + line);
break decode;
case 'C':
sb.append(getInt(LINE_OFFSET, 0) + line + 1);
break decode;
case 'M':
if (message != null) sb.append(message);
break decode;
Expand All @@ -4189,6 +4200,13 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str
padPos = sb.length();
padPartIndex = parts.size();
break decode;
case '*':
if (currentLine) {
sb.append("*");
} else {
sb.append(" ");
}
break decode;
case '-':
case '0':
case '1':
Expand Down Expand Up @@ -4246,6 +4264,7 @@ private AttributedString insertSecondaryPrompts(
List<AttributedString> lines = strAtt.columnSplitLength(Integer.MAX_VALUE);
AttributedStringBuilder sb = new AttributedStringBuilder();
String secondaryPromptPattern = getString(SECONDARY_PROMPT_PATTERN, DEFAULT_SECONDARY_PROMPT_PATTERN);
int secondaryLineNo = secondaryPromptPattern.contains("%*") ? getCurrentLineNo(lines) - 1 : -1;
boolean needsMessage = secondaryPromptPattern.contains("%M")
&& strAtt.length() < getInt(FEATURES_MAX_BUFFER_SIZE, DEFAULT_FEATURES_MAX_BUFFER_SIZE);
AttributedStringBuilder buf = new AttributedStringBuilder();
Expand All @@ -4272,7 +4291,7 @@ private AttributedString insertSecondaryPrompts(
}
}
missings.add(missing);
prompt = expandPromptPattern(secondaryPromptPattern, 0, missing, line + 1);
prompt = expandPromptPattern(secondaryPromptPattern, 0, missing, line + 1, line == secondaryLineNo);
width = Math.max(width, prompt.columnLength());
}
buf.setLength(0);
Expand All @@ -4297,7 +4316,7 @@ private AttributedString insertSecondaryPrompts(
missing = missings.get(line);
}
}
prompt = expandPromptPattern(secondaryPromptPattern, width, missing, line + 1);
prompt = expandPromptPattern(secondaryPromptPattern, width, missing, line + 1, line == secondaryLineNo);
} else {
prompt = prompts.get(line);
}
Expand All @@ -4310,6 +4329,21 @@ private AttributedString insertSecondaryPrompts(
return sb.toAttributedString();
}

private int getCurrentLineNo(List<AttributedString> lines) {
int currentLine = -1;
int cursor = buf.cursor();
int start = 0;
for (int l = 0; l < lines.size(); l++) {
int end = start + lines.get(l).length();
if (cursor >= start && cursor <= end) {
currentLine = l;
break;
}
start = end + 1;
}
return currentLine;
}

private AttributedString addRightPrompt(AttributedString prompt, AttributedString line) {
int width = prompt.columnLength();
boolean endsWithNl = line.length() > 0 && line.charAt(line.length() - 1) == '\n';
Expand All @@ -4335,6 +4369,9 @@ private AttributedString addRightPrompt(AttributedString prompt, AttributedStrin
//

protected boolean insertTab() {
if (bindingReader.peekCharacter(10) != NonBlockingReader.READ_EXPIRED) {
return true;
}
return isSet(Option.INSERT_TAB)
&& getLastBinding().equals("\t")
&& buf.toString().matches("(^|[\\s\\S]*\n)[\r\n\t ]*");
Expand Down Expand Up @@ -4608,8 +4645,8 @@ else if (isSet(Option.RECOGNIZE_EXACT)) {
size.copy(terminal.getBufferSize());
}
}

protected static CompletingParsedLine wrap(ParsedLine line) {
// BMG protected static CompletingParsedLine wrap(ParsedLine line) {
protected CompletingParsedLine wrap(ParsedLine line) {
if (line instanceof CompletingParsedLine) {
return (CompletingParsedLine) line;
} else {
Expand Down Expand Up @@ -5622,6 +5659,9 @@ protected boolean moveHistory(final boolean next, int count) {
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
protected boolean moveHistory(final boolean next) {
if (maskingCallback != null) {
return false;
}
if (!buf.toString().equals(history.current())) {
modifiedHistory.put(history.index(), buf.toString());
}
Expand Down Expand Up @@ -5982,6 +6022,11 @@ public boolean beep() {
return true;
}

public boolean redrawDisplay() {
redisplay(true, true);
return true;
}

//
// Helpers
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public boolean isActive() {
return !dead;
} // isClosed

/****** Event handling ****************/
/* ***** Event handling *************** */

/**
* Method that registers a ConnectionListener with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class TelnetIO {
*/
protected static final int AO = 245;

/**** Implementation of OutputStream ****************************************************/
/* *** Implementation of OutputStream *************************************************** */
/**
* Are You There
*/
Expand Down Expand Up @@ -187,9 +187,9 @@ public class TelnetIO {
*/
protected static final int SEND = 1;

/**** End implementation of OutputStream ***********************************************/
/* *** End implementation of OutputStream ********************************************** */

/**** Implementation of InputStream ****************************************************/
/* *** Implementation of InputStream *************************************************** */
/**
* Telnet Option: Logout<br>
* This allows nice goodbye to time-outed or unwanted clients.
Expand All @@ -206,7 +206,7 @@ public class TelnetIO {
protected static final int LM_EDIT = 1;
protected static final int LM_TRAPSIG = 2;

/**** Implementation of InputStream ****************************************************/
/* *** Implementation of InputStream *************************************************** */

/****
* Following methods implement init/request/answer procedures for telnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public static boolean isWindowsSystemStream(SystemStream stream) {
inMode,
outConsole,
outMode);
startWinchMonitor();
}

@Override
Expand Down Expand Up @@ -229,6 +230,28 @@ protected boolean processConsoleInput() throws IOException {
return flush;
}

private void startWinchMonitor() {
Size startSize = getSize();
Thread winchMonitor = new Thread(() -> {
Size size = startSize;
boolean proceed = true;
while (proceed) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
proceed = false;
}
Size newSize = getSize();
if (size.getRows() != newSize.getRows() || size.getColumns() != newSize.getColumns()) {
size = newSize;
raise(Signal.WINCH);
}
}
});
winchMonitor.setDaemon(true);
winchMonitor.start();
}

private char[] focus = new char[] {'\033', '[', ' '};

private void processFocusEvent(boolean hasFocus) throws IOException {
Expand Down Expand Up @@ -282,7 +305,7 @@ public Cursor getCursorPosition(IntConsumer discarded) {
if (GetConsoleScreenBufferInfo(outConsole, info) == 0) {
throw new IOError(new IOException("Could not get the cursor position: " + getLastErrorMessage()));
}
return new Cursor(info.cursorPosition.x, info.cursorPosition.y);
return new Cursor(info.cursorPosition.x, info.cursorPosition.y - info.window.top);
}

public void disableScrolling() {
Expand Down
Loading