Skip to content

Commit 57a05f5

Browse files
committed
Added support for web console in local repl (fixes #110)
1 parent 55abe44 commit 57a05f5

File tree

167 files changed

+144
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+144
-29
lines changed

src/javarepl/Main.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ private static boolean handleTerminalCommand(EvaluationLog log) {
9797
return false;
9898
}
9999

100-
101-
102100
private static String welcomeMessage() {
103101
return format("Welcome to JavaREPL version %s (%s, Java %s)",
104102
applicationVersion(),
105103
getProperty("java.vm.name"),
106104
getProperty("java.version"));
107105
}
108106

107+
private static String welcomeInstructions() {
108+
return "Type expression to evaluate, \u001B[32m:help\u001B[0m for more options or press \u001B[32mtab\u001B[0m to auto-complete.";
109+
}
110+
109111
private static JavaREPLClient clientFor(Option<String> hostname, Option<Integer> port) throws Exception {
110112
console.printInfo(welcomeMessage());
111113

@@ -146,6 +148,8 @@ private static JavaREPLClient startNewLocalInstance(String hostname, Integer por
146148
ProcessBuilder builder = new ProcessBuilder("java", "-cp", System.getProperty("java.class.path"), Repl.class.getCanonicalName(), "--port=" + port);
147149
builder.redirectErrorStream(true);
148150

151+
console.printInfo("Connected to local instance at http://" + hostname + ":" + port);
152+
149153
process = some(builder.start());
150154
Runtime.getRuntime().addShutdownHook(new Thread() {
151155
public void run() {
@@ -163,10 +167,6 @@ public void run() {
163167
return replClient;
164168
}
165169

166-
private static String welcomeInstructions() {
167-
return "Type expression to evaluate, \u001B[32m:help\u001B[0m for more options or press \u001B[32mtab\u001B[0m to auto-complete.";
168-
}
169-
170170
private static boolean waitUntilInstanceStarted(JavaREPLClient client) throws Exception {
171171
for (int i = 0; i < 500; i++) {
172172
Thread.sleep(10);

src/javarepl/console/rest/RestConsoleApplication.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.googlecode.utterlyidle.BasePath;
44
import com.googlecode.utterlyidle.RestApplication;
5+
import javarepl.console.ui.ConsoleUiModule;
56

67
import static com.googlecode.utterlyidle.annotations.AnnotatedBindings.annotatedClass;
78
import static com.googlecode.utterlyidle.modules.Modules.applicationInstance;
@@ -14,6 +15,8 @@ public RestConsoleApplication(BasePath basePath, RestConsole console) {
1415
applicationInstance(console),
1516
applicationInstance(new RestConsoleExpressionReader()));
1617

18+
add(new ConsoleUiModule());
1719
add(new RestConsoleModule());
20+
1821
}
1922
}

src/javarepl/console/rest/RestConsoleResource.java

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.googlecode.totallylazy.Option;
44
import com.googlecode.totallylazy.functions.Function1;
55
import com.googlecode.utterlyidle.MediaType;
6+
import com.googlecode.utterlyidle.Response;
67
import com.googlecode.utterlyidle.annotations.*;
78
import javarepl.console.ConsoleLog;
89
import javarepl.console.ConsoleResult;
@@ -11,6 +12,9 @@
1112
import java.util.Map;
1213

1314
import static com.googlecode.totallylazy.collections.PersistentMap.constructors.emptyMap;
15+
import static com.googlecode.utterlyidle.Response.seeOther;
16+
import static java.lang.String.format;
17+
import static java.lang.System.getProperty;
1418
import static javarepl.Utils.applicationVersion;
1519
import static javarepl.completion.CompletionResult.methods.toJson;
1620

@@ -23,6 +27,21 @@ public RestConsoleResource(RestConsole console, RestConsoleExpressionReader expr
2327
this.expressionReader = expressionReader;
2428
}
2529

30+
@GET
31+
@Path("")
32+
public Response main() {
33+
return seeOther("/ui/console.html");
34+
}
35+
36+
@POST
37+
@Path("create")
38+
@Produces(MediaType.APPLICATION_JSON)
39+
public Map<String, Object> create() throws Exception {
40+
return emptyMap(String.class, Object.class)
41+
.insert("id", this.hashCode()+"")
42+
.insert("welcomeMessage", welcomeMessage()+"\n"+welcomeInstructions());
43+
}
44+
2645
@GET
2746
@Path("version")
2847
@Produces(MediaType.APPLICATION_JSON)
@@ -91,4 +110,15 @@ private static Function1<ConsoleLog, Map<String, Object>> toCommandResultMap() {
91110
.insert("type", consoleLog.type())
92111
.insert("message", consoleLog.message());
93112
}
113+
114+
private String welcomeMessage() {
115+
return format("Welcome to JavaREPL version %s (%s, Java %s)",
116+
applicationVersion(),
117+
getProperty("java.vm.name"),
118+
getProperty("java.version"));
119+
}
120+
121+
private String welcomeInstructions() {
122+
return "Type expression to evaluate, :help for more options or press tab to auto-complete.";
123+
}
94124
}

src/javarepl/console/rest/favicon.ico

1.12 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package javarepl.console.ui;
2+
3+
import com.googlecode.utterlyidle.Resources;
4+
import com.googlecode.utterlyidle.modules.ResourcesModule;
5+
6+
import static com.googlecode.totallylazy.io.URLs.packageUrl;
7+
import static com.googlecode.utterlyidle.dsl.DslBindings.bindings;
8+
import static com.googlecode.utterlyidle.dsl.StaticBindingBuilder.in;
9+
10+
public class ConsoleUiModule implements ResourcesModule {
11+
@Override
12+
public Resources addResources(Resources resources) throws Exception {
13+
return resources.add(bindings(in(packageUrl(ConsoleUiModule.class)).path("/ui")));
14+
}
15+
}

src/javarepl/web/bower_components/jquery/src/core/ready.js src/javarepl/console/ui/bower_components/jquery/src/core/ready.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define( [
22
"../core",
33
"../var/document",
4-
"../core/init",
4+
"./init",
55
"../deferred"
66
], function( jQuery, document ) {
77

src/javarepl/web/bower_components/jquery/src/var/rcssNum.js src/javarepl/console/ui/bower_components/jquery/src/var/rcssNum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
define( [
2-
"../var/pnum"
2+
"./pnum"
33
], function( pnum ) {
44

55
return new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" );

src/javarepl/console/ui/console.html

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
<html>
4+
<head>
5+
<title>Java REPL</title>
6+
<meta name="Content-Type" content="text/html; charset=UTF-8">
7+
8+
<script src="/ui/bower_components/underscore/underscore.js" type="text/javascript"></script>
9+
<script src="/ui/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
10+
<script src="/ui/bower_components/jquery.terminal/js/jquery.terminal.min.js" type="text/javascript"></script>
11+
<script src="/ui/bower_components/jquery.terminal/js/jquery.mousewheel-min.js" type="text/javascript"></script>
12+
13+
<link href="/ui/bower_components/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
14+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.css" rel="stylesheet" type="text/css">
15+
16+
<!--[if lt IE 9]>
17+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css" rel="stylesheet" type="text/css">
18+
<![endif]-->
19+
20+
21+
<link href="term.css" rel="stylesheet" type="text/css">
22+
23+
<script type="text/javascript">
24+
(function (i, s, o, g, r, a, m) {
25+
i['GoogleAnalyticsObject'] = r;
26+
i[r] = i[r] || function () {
27+
(i[r].q = i[r].q || []).push(arguments)
28+
}, i[r].l = 1 * new Date();
29+
a = s.createElement(o),
30+
m = s.getElementsByTagName(o)[0];
31+
a.async = 1;
32+
a.src = g;
33+
m.parentNode.insertBefore(a, m)
34+
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
35+
36+
ga('create', 'UA-40421018-1', 'javarepl.com');
37+
ga('send', 'pageview');
38+
</script>
39+
40+
41+
<script type="text/javascript">
42+
var _gaq = _gaq || [];
43+
_gaq.push(['_setAccount', 'UA-40421018-1']);
44+
_gaq.push(['_trackPageview']);
45+
46+
(function () {
47+
var ga = document.createElement('script');
48+
ga.type = 'text/javascript';
49+
ga.async = true;
50+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
51+
var s = document.getElementsByTagName('script')[0];
52+
s.parentNode.insertBefore(ga, s);
53+
})();
54+
55+
</script>
56+
</head>
57+
58+
59+
<body>
60+
61+
62+
<script type="text/javascript" src="/ui/term.js"></script>
63+
64+
</body>
65+
</html>

src/javarepl/console/ui/favicon.ico

1.12 KB
Binary file not shown.
File renamed without changes.

src/javarepl/web/term.css src/javarepl/console/ui/term.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ body {
3939
height: 72px;
4040
margin: 20px 10px 20px;
4141
line-height: 72px;
42-
background: url(javarepl-icon.png) no-repeat;
42+
background: url(/ui/javarepl-icon.png) no-repeat;
4343
padding: 0;
4444
padding-left: 75px;
4545

File renamed without changes.

src/javarepl/web/WebConsoleApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.googlecode.utterlyidle.BasePath;
44
import com.googlecode.utterlyidle.RestApplication;
5+
import javarepl.console.ui.ConsoleUiModule;
56

67
import static com.googlecode.utterlyidle.annotations.AnnotatedBindings.annotatedClass;
78
import static com.googlecode.utterlyidle.modules.Modules.applicationInstance;
@@ -14,6 +15,7 @@ public WebConsoleApplication(BasePath basePath) {
1415
applicationInstance(new WebConsole())
1516
);
1617

18+
add(new ConsoleUiModule());
1719
add(new WebConsoleModule());
1820
}
1921
}

src/javarepl/web/embed.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
<title>Java REPL</title>
66
<meta name="Content-Type" content="text/html; charset=UTF-8">
77

8-
<script src="/bower_components/underscore/underscore.js" type="text/javascript"></script>
9-
<script src="/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
10-
<script src="/bower_components/jquery.terminal/js/jquery.terminal.min.js" type="text/javascript"></script>
11-
<script src="/bower_components/jquery.terminal/js/jquery.mousewheel-min.js" type="text/javascript"></script>
8+
<script src="/ui/bower_components/underscore/underscore.js" type="text/javascript"></script>
9+
<script src="/ui/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
10+
<script src="/ui/bower_components/jquery.terminal/js/jquery.terminal.min.js" type="text/javascript"></script>
11+
<script src="/ui/bower_components/jquery.terminal/js/jquery.mousewheel-min.js" type="text/javascript"></script>
1212

13-
<link href="/bower_components/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
14-
<link href="/bower_components/github-fork-ribbon-css/gh-fork-ribbon.css" rel="stylesheet" type="text/css">
13+
<link href="/ui/bower_components/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
14+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.css" rel="stylesheet" type="text/css">
1515

1616
<!--[if lt IE 9]>
17-
<link href="/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css" rel="stylesheet" type="text/css">
17+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css" rel="stylesheet" type="text/css">
1818
<![endif]-->
1919

2020

@@ -24,10 +24,10 @@
2424
(function (i, s, o, g, r, a, m) {
2525
i['GoogleAnalyticsObject'] = r;
2626
i[r] = i[r] || function () {
27-
(i[r].q = i[r].q || []).push(arguments)
28-
}, i[r].l = 1 * new Date();
27+
(i[r].q = i[r].q || []).push(arguments)
28+
}, i[r].l = 1 * new Date();
2929
a = s.createElement(o),
30-
m = s.getElementsByTagName(o)[0];
30+
m = s.getElementsByTagName(o)[0];
3131
a.async = 1;
3232
a.src = g;
3333
m.parentNode.insertBefore(a, m)
@@ -59,7 +59,7 @@
5959
<body>
6060

6161

62-
<script type="text/javascript" src="term.js"></script>
62+
<script type="text/javascript" src="/ui/term.js"></script>
6363

6464
</body>
6565
</html>

src/javarepl/web/term.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
<title>Java REPL</title>
66
<meta name="Content-Type" content="text/html; charset=UTF-8">
77

8-
<script src="/bower_components/underscore/underscore.js" type="text/javascript"></script>
9-
<script src="/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
10-
<script src="/bower_components/jquery.terminal/js/jquery.terminal.min.js" type="text/javascript"></script>
11-
<script src="/bower_components/jquery.terminal/js/jquery.mousewheel-min.js" type="text/javascript"></script>
8+
<script src="/ui/bower_components/underscore/underscore.js" type="text/javascript"></script>
9+
<script src="/ui/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
10+
<script src="/ui/bower_components/jquery.terminal/js/jquery.terminal.min.js" type="text/javascript"></script>
11+
<script src="/ui/bower_components/jquery.terminal/js/jquery.mousewheel-min.js" type="text/javascript"></script>
1212

13-
<link href="/bower_components/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
14-
<link href="/bower_components/github-fork-ribbon-css/gh-fork-ribbon.css" rel="stylesheet" type="text/css">
13+
<link href="/ui/bower_components/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
14+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.css" rel="stylesheet" type="text/css">
1515

1616
<!--[if lt IE 9]>
17-
<link href="/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css" rel="stylesheet" type="text/css">
17+
<link href="/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css" rel="stylesheet" type="text/css">
1818
<![endif]-->
1919

2020

21-
<link href="term.css" rel="stylesheet" type="text/css">
21+
<link href="/ui/term.css" rel="stylesheet" type="text/css">
2222

2323
<script type="text/javascript">
2424
(function (i, s, o, g, r, a, m) {
@@ -77,7 +77,7 @@ <h1><span class="logo-javarepl">Java REPL</span></h1>
7777
</div>
7878
</header>
7979

80-
<script type="text/javascript" src="term.js"></script>
80+
<script type="text/javascript" src="/ui/term.js"></script>
8181

8282
<footer class="terminal-footer">
8383
<p class="bottom">

0 commit comments

Comments
 (0)