Skip to content

Commit 80ed331

Browse files
committed
hacked version for syntax highlighting
1 parent f1ef4b0 commit 80ed331

File tree

5 files changed

+86
-7
lines changed

5 files changed

+86
-7
lines changed

terminal/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Application.prototype.setRectification = function(argument)
129129

130130
Application.prototype.setInversion = function(argument)
131131
{
132-
this.harmony.setInversion(parseInt(argument));
132+
this.harmony_.setInversion(parseInt(argument));
133133
this.rebuild();
134134
return "";
135135
}

terminal/index-edit.html

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,43 @@
2626
border-bottom-right-radius: 0px;
2727
margin-top: 5px;
2828
}
29-
.myMarker {
30-
position:absolute;
31-
background:rgba(100,200,100,0.5);
32-
z-index:20
29+
.warning
30+
{
31+
background: rgba(255, 50, 50, 0.5);
32+
position: absolute;
33+
width: 100% !important;
34+
left: 0 !important;
3335
}
3436
</style>
3537

3638
<script src="terminal/js/jquery-1.7.1.min.js"></script>
39+
<script src="terminal/js/peg-0.10.0.min.js"></script>
3740
<script src="terminal/js/ace/min/ace.js" type="text/javascript" charset="utf-8"></script>
3841
<script>
42+
3943
var Range = ace.require('ace/range').Range;
44+
var parser;
45+
var lastMarkerRow;
46+
var lastMarkerID;
47+
48+
function buildErrorMessage(e) {
49+
return e.location !== undefined
50+
? "Line " + e.location.start.line + ", column " + e.location.start.column + ": " + e.message
51+
: e.message;
52+
}
53+
54+
function testParser(string)
55+
{
56+
try {
57+
parser.parse(string);
58+
return true;
59+
}
60+
catch(e)
61+
{
62+
// console.log(buildErrorMessage(e));
63+
return false;
64+
}
65+
}
4066

4167
function processCommand(log, command)
4268
{
@@ -71,10 +97,14 @@
7197
}
7298
}
7399

74-
$( document ).ready(function() {
100+
$( document ).ready(function()
101+
{
102+
// listen to server events
103+
75104
setTimeout(pollServerEvents, 10);
76105
console.log( "ready!" );
77106

107+
// Setup editor and log
78108
var editor = ace.edit("editor");
79109
editor.setTheme("ace/theme/monokai");
80110
editor.getSession().setMode("ace/mode/text");
@@ -100,6 +130,35 @@
100130
readOnly: true
101131
});
102132

133+
editor.getSession().selection.on('changeCursor', function() {
134+
var currline = editor.getCursorPosition().row;
135+
var lineText = editor.session.getLine(currline);
136+
if (lineText.trim().length > 0)
137+
{
138+
var success = testParser(lineText);
139+
if (lastMarkerID)
140+
{
141+
editor.getSession().removeMarker(lastMarkerID);
142+
}
143+
if (!success)
144+
{
145+
lastMarkerID = editor.getSession().addMarker(new Range(currline, 0, currline, 1), "warning", "line", true);
146+
}
147+
}
148+
});
149+
// Setup local parser
150+
151+
$.get('/grammar.txt', function(data)
152+
{
153+
var parserSource = peg.generate(data, {
154+
cache: $("#option-cache").is(":checked"),
155+
optimize: $("#option-optimize").val(),
156+
output: "source"
157+
});
158+
159+
parser = eval(parserSource);
160+
161+
});
103162
});
104163
</script>
105164
</head>

terminal/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var app = require('./application.js');
99
var devices =
1010
{
1111
dar: "iac",
12-
win: "microsoft",
12+
win: "loop",
1313
lin: "through"
1414
}
1515

terminal/server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ Server.prototype.init = function(application)
6565
}
6666
});
6767

68+
this.server_.route({
69+
method: 'GET',
70+
path: '/grammar.txt',
71+
handler: function (request, reply) {
72+
reply.file('terminal/grammar.txt');
73+
}
74+
});
75+
6876
this.server_.route({
6977
method: 'GET',
7078
path: '/terminal/{file*}',

terminal/terminal/js/peg-0.10.0.min.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)