Skip to content

Commit

Permalink
history added and cool colors
Browse files Browse the repository at this point in the history
  • Loading branch information
kanalj authored and kanalj committed Mar 8, 2010
1 parent 62c3ae6 commit 8224074
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ghci.html
Expand Up @@ -18,6 +18,9 @@
<link rel="stylesheet" type="text/css" href="hiji.css">
</head>
<body>

<h1>HIJi</h1>
<h2>Bringing you the power of GHCI to the interwebs</h2>
<div id="hiji" class="ghci-look"></div>
</body>
</html>
57 changes: 55 additions & 2 deletions haskell.hiji.js
Expand Up @@ -13,17 +13,39 @@

};
var makeInput = function(modules){
return "<li class='input'>" + makeModules(modules) + "<input type='text'></li>";
return "<li class='input'>" + makeModules(modules) + "<input type='text' name='inputBox'></li>";
};
var makeOutput = function(output) {
console.log("%o", output);
return $("<li class='output'></li>").text(output.ast.toString());
};

$.fn.startHiji = function() {
var modules = new Array();
var hist = new Array();

// history
var hiss = new historry;

modules[0] = "Prelude";
modules[1] = "Control.Monad";
this.html("<ol>" + makeInput(modules) + "</ol>");


// pressing keyUP and keyDown
// history-related
document.onkeydown = function(e){
var input = $('input', this);
var line = input.attr("value");
// keyUp
if(e.keyCode=='38'){
input.attr("value", hiss.older());
}
if(e.keyCode=='40'){
input.attr("value", hiss.newer());
}
}

this.keypress(function(e){
if (e.keyCode=='13'){
var input = $('input', this);
Expand All @@ -33,7 +55,38 @@
var output = makeOutput(evaluateHaskell(line,{}));
$('.input', this).after(output).replaceWith(newLine);
$("ol",this).append(makeInput(modules));

hiss.addHistory(line);
}
});
};
})(jQuery);
})(jQuery);


// historry-class with nice name
// !!!WARNING!!! NICE NAME
historry = function (){
this.pointer = 0;
this.history_array = new Array();
this.addHistory = function(input){
this.history_array.unshift(input);
this.pointer = -1;
};

this.older = function(){
this.pointer++;
if(this.pointer >= this.history_array.length){
this.pointer = this.history_array.length-1
}
return this.history_array[this.pointer];
};

this.newer = function(){
this.pointer--;
if(this.pointer < 0){
this.pointer = 0
return "";
}
return this.history_array[this.pointer];
};
};
8 changes: 7 additions & 1 deletion hiji.css
Expand Up @@ -11,15 +11,21 @@
.ghci-look ol{
width:800px;
height:400px;
background-color: #000;
overflow-x:auto;
overflow-y:scroll;
list-style-type:none;

color: #fff;
}

.ghci-look .input input {
border:none;
display:inline-block;
margin-left:-1px;
background-color: #000;

color: #fff;
}

.ghci-look .modules {
Expand All @@ -38,4 +44,4 @@
.ghci-look .modules:after {
content:">";
padding-right:0.5em;
}
}

0 comments on commit 8224074

Please sign in to comment.