Skip to content

Commit

Permalink
repl refactor and some bug fix
Browse files Browse the repository at this point in the history
bug fix: dynamic invocation with bool might fail
  • Loading branch information
wkgcass committed Mar 25, 2018
1 parent 030568f commit 1de6b28
Show file tree
Hide file tree
Showing 17 changed files with 657 additions and 514 deletions.
1 change: 1 addition & 0 deletions latte-build/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build/*
*.ipr
*.iws
out/*
8 changes: 4 additions & 4 deletions latte-build/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ('deploy' == ACTION) {
}
apply plugin: LatteBuild

mainClassName = 'lt.repl.REPL'
mainClassName = 'lt.repl.Entry'
applicationName = 'latte'

sourceCompatibility = 1.6
Expand Down Expand Up @@ -105,7 +105,7 @@ if (null == ACTION) {
jar {
manifest {
attributes("Manifest-Version": 1.0,
"Main-Class": "lt.repl.REPL")
"Main-Class": "lt.repl.Entry")
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
into('assets') {
Expand All @@ -123,14 +123,14 @@ if ('deploy' == ACTION) {
dependencies {
compile group: 'org.latte-lang', name: 'latte-compiler', version: VERSION
compile group: 'org.latte-lang', name: 'latte-library', version: VERSION
provided group: 'jline', name: 'jline', version: '2.14.2'
provided group: 'jline', name: 'jline', version: '2.14.5'
}

class LatteBuild implements Plugin<Project> {
@Override
void apply(Project project) {
def latteBuild = project.task('latteBuild')
latteBuild.dependsOn project.tasks['assemble']
latteBuild.dependsOn project.tasks['install']

project.task('latteTest') // do nothing

Expand Down
10 changes: 8 additions & 2 deletions latte-build/src/main/java/lt/repl/CtrlCHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* handle ctrl-c (INT) event
*/
public interface CtrlCHandler {
void handle();
interface ExitCallback {
void exit();
}

void setExitCallback(ExitCallback exitCallback);

void onAlert(Runnable alert);
void setAlert(Runnable alert);

void handle();
}
53 changes: 53 additions & 0 deletions latte-build/src/main/java/lt/repl/CtrlCHandlerImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package lt.repl;

import sun.misc.Signal;
import sun.misc.SignalHandler;

/**
* handle ctrl-c (INT) event
*/
public class CtrlCHandlerImpl implements CtrlCHandler {
private Runnable alert = null;
private ExitCallback exitCallback = null;
private final IO io;
private int count;

public CtrlCHandlerImpl(IO io) {
this.io = io;
}

@Override
public void setExitCallback(final ExitCallback exitCallback) {
this.exitCallback = exitCallback;
}

@Override
public void setAlert(Runnable alert) {
this.alert = alert;
}

@Override
public void handle() {
++count;
if (count == 2) {
io.out.println();
exitCallback.exit();
} else {
io.out.println("\n(To exit, press ^C again or type :q)");
if (alert != null) {
alert.run();
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace(io.err);
}
count = 0;
}
}).run();
}
}
}
52 changes: 0 additions & 52 deletions latte-build/src/main/java/lt/repl/CtrlCSignalHandler.java

This file was deleted.

Loading

0 comments on commit 1de6b28

Please sign in to comment.