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
2 changes: 1 addition & 1 deletion lib/readline/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Readline
module Version
VERSION = "1.3.6"
JLINE_VERSION = "2.14.6"
JLINE_VERSION = "3.21.0"
end
end
2 changes: 1 addition & 1 deletion readline.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.files = Dir['[A-Z]*'] + Dir['lib/**/*']
s.platform = 'java'
s.required_ruby_version = '>= 2.3'
s.requirements << "jar jline:jline, #{Readline::Version::JLINE_VERSION}"
s.requirements << "jar org.jline:jline, #{Readline::Version::JLINE_VERSION}"
end

# vim: syntax=Ruby
43 changes: 15 additions & 28 deletions src/main/java/org/jruby/demo/readline/TextAreaReadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.Join;
import org.jline.reader.Candidate;
import org.jline.reader.impl.DefaultParser;

public class TextAreaReadline implements KeyListener {
private static final String EMPTY_LINE = "";
Expand Down Expand Up @@ -315,7 +317,7 @@ protected void completeAction(KeyEvent event) {

if (completePopup.isVisible()) return;

List candidates = new LinkedList();
List<Candidate> candidates = new LinkedList<Candidate>();
String bufstr = null;
try {
bufstr = area.getText(startPos, area.getCaretPosition() - startPos);
Expand All @@ -325,25 +327,25 @@ protected void completeAction(KeyEvent event) {

int cursor = area.getCaretPosition() - startPos;

int position = Readline.getCompletor(Readline.getHolder(runtime)).complete(bufstr, cursor, candidates);
Readline.getCompletor(Readline.getHolder(runtime)).complete(Readline.getHolder(runtime).readline, new DefaultParser().parse(bufstr, cursor), candidates);

// no candidates? Fail.
if (candidates.isEmpty()) {
return;
}

if (candidates.size() == 1) {
replaceText(startPos + position, area.getCaretPosition(), (String) candidates.get(0));
replaceText(startPos, area.getCaretPosition(), candidates.get(0).value());
return;
}

start = startPos + position;
start = startPos;
end = area.getCaretPosition();

Point pos = area.getCaret().getMagicCaretPosition();

// bit risky if someone changes completor, but useful for method calls
int cutoff = bufstr.substring(position).lastIndexOf('.') + 1;
int cutoff = bufstr.lastIndexOf('.') + 1;
start += cutoff;

if (candidates.size() < 10) {
Expand All @@ -353,8 +355,8 @@ protected void completeAction(KeyEvent event) {
}

completeCombo.removeAllItems();
for (Iterator i = candidates.iterator(); i.hasNext();) {
String item = (String) i.next();
for (Candidate c : candidates) {
String item = c.value();
if (cutoff != 0) item = item.substring(cutoff);
completeCombo.addItem(item);
}
Expand All @@ -378,15 +380,8 @@ protected void upAction(KeyEvent event) {
return;
}

if (!Readline.getHistory(Readline.getHolder(runtime)).next()) {
currentLine = getLine(); // at end
} else {
Readline.getHistory(Readline.getHolder(runtime)).previous(); //undo check
}

if (!Readline.getHistory(Readline.getHolder(runtime)).previous()) return;

String oldLine = Readline.getHistory(Readline.getHolder(runtime)).current().toString().trim();
Readline.getHolder(runtime).readline.getHistory().previous();
String oldLine = Readline.getHolder(runtime).readline.getHistory().current().toString().trim();
replaceText(startPos, area.getDocument().getLength(), oldLine);
}

Expand All @@ -400,16 +395,8 @@ protected void downAction(KeyEvent event) {
return;
}

if (!Readline.getHistory(Readline.getHolder(runtime)).next()) return;

String oldLine;
if (!Readline.getHistory(Readline.getHolder(runtime)).next()) {
oldLine = currentLine; // at end
} else {
Readline.getHistory(Readline.getHolder(runtime)).previous(); // undo check
oldLine = Readline.getHistory(Readline.getHolder(runtime)).current().toString().trim();
}

Readline.getHolder(runtime).readline.getHistory().next();
String oldLine = Readline.getHolder(runtime).readline.getHistory().current().toString().trim();
replaceText(startPos, area.getDocument().getLength(), oldLine);
}

Expand Down Expand Up @@ -460,7 +447,7 @@ public void run() {
append(" ", inputStyle); // hack to get right style for input
area.setCaretPosition(area.getDocument().getLength());
startPos = area.getDocument().getLength();
Readline.getHistory(Readline.getHolder(runtime)).moveToEnd();
Readline.getHolder(runtime).readline.getHistory().moveToEnd();
}
});

Expand Down Expand Up @@ -616,4 +603,4 @@ public void write(byte[] b) {
writeLine(RubyEncoding.decodeUTF8(b));
}
}
}
}
Loading