Skip to content

Commit

Permalink
Merge pull request #2063 from usethesource/migrate-jline3
Browse files Browse the repository at this point in the history
Migrate to jline3
  • Loading branch information
DavyLandman authored Jan 21, 2025
2 parents f7e8352 + f589f74 commit 0ccf803
Show file tree
Hide file tree
Showing 81 changed files with 4,198 additions and 2,671 deletions.
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
"request": "launch",
"mainClass": "org.rascalmpl.shell.RascalShell",
"projectName": "rascal",
"vmArgs": "-Xss80m -Xmx2g -ea"
"vmArgs": "-Xss80m -Xmx2g -ea",
"console": "integratedTerminal"
},
{
"type": "java",
"name": "Launch RascalShell Tutor",
"request": "launch",
"mainClass": "org.rascalmpl.shell.RascalShell",
"projectName": "rascal",
"cwd" : "${workspaceFolder}/../rascal-tutor",
"cwd": "${workspaceFolder}/../rascal-tutor",
"vmArgs": "-Xss80m -Xmx2g -ea"
},
{
Expand Down
87 changes: 32 additions & 55 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<rascal.test.memory>3</rascal.test.memory>
<maven.compiler.release>11</maven.compiler.release>
<rascal-maven.version>0.28.9-BOOT1</rascal-maven.version>
<jline.version>3.27.0</jline.version>
</properties>

<licenses>
Expand Down Expand Up @@ -235,6 +236,7 @@
<include>**/org/rascalmpl/test/AllSuiteParallel.java</include>
<include>**/org/rascalmpl/test/library/LibraryLangPaths.java</include>
<include>**/org/rascalmpl/test/value/AllTests.java</include>
<include>**/org/rascalmpl/test/repl/*Test.java</include>
<include>**/org/rascalmpl/*Test.java</include>
</includes>
</configuration>
Expand Down Expand Up @@ -331,19 +333,6 @@
<addHeader>false</addHeader>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.fusesource.jansi</pattern>
<shadedPattern>org.rascalmpl.fusesource.jansi</shadedPattern>
<excludes>
<exclude>org.fusesource.jansi.internal.*</exclude>
</excludes>
</relocation>
<relocation>
<pattern>jline</pattern>
<shadedPattern>org.rascalmpl.jline</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
Expand Down Expand Up @@ -471,10 +460,35 @@
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.6</version>
<dependency> <!-- line reader/completion/history support -->
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency> <!-- terminal API -->
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency> <!-- interaction with native APIs for console features, after jdk22 we can switch to FFM -->
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jni</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency> <!-- styling api -->
<groupId>org.jline</groupId>
<artifactId>jline-style</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency> <!-- command registyr and extra features -->
<groupId>org.jline</groupId>
<artifactId>jline-console</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency> <!-- raw ansi commands -->
<groupId>org.jline</groupId>
<artifactId>jansi-core</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down Expand Up @@ -563,44 +577,7 @@
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Name>rascal</Name>
<Main-Class>org.rascalmpl.shell.RascalShell</Main-Class>
<Specification-Version>${project.version}</Specification-Version>
<Specification-Vendor>http://www.usethesource.io</Specification-Vendor>
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.fusesource.jansi</pattern>
<shadedPattern>org.rascalmpl.fusesource.jansi</shadedPattern>
<excludes>
<exclude>org.fusesource.jansi.internal.*</exclude>
</excludes>
</relocation>
<relocation>
<pattern>jline</pattern>
<shadedPattern>org.rascalmpl.jline</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<includes>
<include>jline:*</include>
</includes>
</artifactSet>
<skip>true</skip>
</configuration>
</execution>
</executions>
Expand Down
125 changes: 0 additions & 125 deletions src/org/rascalmpl/checker/StaticChecker.java

This file was deleted.

20 changes: 8 additions & 12 deletions src/org/rascalmpl/debug/IRascalMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
*******************************************************************************/
package org.rascalmpl.debug;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;


import org.jline.terminal.Terminal;
import org.rascalmpl.interpreter.BatchProgressMonitor;
import org.rascalmpl.interpreter.NullRascalMonitor;
import org.rascalmpl.repl.TerminalProgressBarMonitor;

import io.usethesource.vallang.ISourceLocation;
import jline.Terminal;
import jline.TerminalFactory;

public interface IRascalMonitor {
/**
Expand Down Expand Up @@ -158,8 +155,8 @@ default void jobStep(String name, String message) {
* and otherwise default to a dumn terminal console progress logger.
* @return
*/
public static IRascalMonitor buildConsoleMonitor(InputStream in, OutputStream out) {
return buildConsoleMonitor(in, out, inBatchMode());
public static IRascalMonitor buildConsoleMonitor(Terminal term) {
return buildConsoleMonitor(term, inBatchMode());
}

public static boolean inBatchMode() {
Expand All @@ -168,12 +165,11 @@ public static boolean inBatchMode() {
;
}

public static IRascalMonitor buildConsoleMonitor(InputStream in, OutputStream out, boolean batchMode) {
Terminal terminal = TerminalFactory.get();
public static IRascalMonitor buildConsoleMonitor(Terminal terminal, boolean batchMode) {

return !batchMode && terminal.isAnsiSupported()
? new TerminalProgressBarMonitor(out, in, terminal)
: new BatchProgressMonitor(new PrintStream(out))
return !batchMode && TerminalProgressBarMonitor.shouldWorkIn(terminal)
? new TerminalProgressBarMonitor(terminal)
: new BatchProgressMonitor(terminal.writer())
;
}

Expand Down
11 changes: 10 additions & 1 deletion src/org/rascalmpl/ideservices/BasicIDEServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import org.jline.terminal.Terminal;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.uri.URIResolverRegistry;
import org.rascalmpl.uri.URIUtil;
Expand All @@ -34,16 +35,24 @@
public class BasicIDEServices implements IDEServices {
private final IRascalMonitor monitor;
private final PrintWriter stderr;
private final Terminal terminal;

public BasicIDEServices(PrintWriter stderr, IRascalMonitor monitor){
public BasicIDEServices(PrintWriter stderr, IRascalMonitor monitor, Terminal terminal){
this.stderr = stderr;
this.monitor = monitor;
this.terminal = terminal;
}

@Override
public PrintWriter stderr() {
return stderr;
}

@Override
public Terminal activeTerminal() {
return terminal;
}


public void browse(ISourceLocation loc, String title, int viewColumn){
browse(loc.getURI(), title, viewColumn);
Expand Down
11 changes: 11 additions & 0 deletions src/org/rascalmpl/ideservices/IDEServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.PrintWriter;
import java.net.URI;

import org.jline.terminal.Terminal;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.uri.LogicalMapResolver;
import org.rascalmpl.uri.URIResolverRegistry;
Expand Down Expand Up @@ -73,6 +74,16 @@ default void unregisterLanguage(IConstructor language) {
throw new UnsupportedOperationException("registerLanguage is not implemented in this environment.");
}

/**
* Get access to the current terminal. <br>
* used for features such as clearing the terminal, and starting a nested REPL. <br>
* Can return null if there is no active terminal.
* @return a terminal if there is one, null otherwise.
*/
default Terminal activeTerminal() {
return null;
}

/**
* Asks the IDE to apply document edits as defined in the standard library module
* analysis::diff::edits::TextEdits, according to the semantics defined in
Expand Down
8 changes: 6 additions & 2 deletions src/org/rascalmpl/interpreter/BatchProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public class BatchProgressMonitor implements IRascalMonitor {
PrintWriter out;

public BatchProgressMonitor() {
this.out = new PrintWriter(System.err);
this(new PrintWriter(System.err, true));
}

public BatchProgressMonitor(PrintStream out) {
this.out = new PrintWriter(out);
this(new PrintWriter(out, true));
}

public BatchProgressMonitor(PrintWriter out) {
this.out = out;
}

@Override
Expand Down
Loading

0 comments on commit 0ccf803

Please sign in to comment.