Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

ability to modify previous messages #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions jquery.console.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
var continuedText = '';
var fadeOnReset = config.fadeOnReset !== undefined ? config.fadeOnReset : true;
// Prompt history stack
var history = [];
var commandHistory = [];
var ringn = 0;
// For reasons unknown to The Sword of Michael himself, Opera
// triggers and sends a key character when you hit various
Expand All @@ -143,6 +143,42 @@
// External exports object
var extern = {};

//Object returned on history.get(nFromLast) to allow limited modification of a previous entry.
function MessageHandle(mesg){
this.setText=function(msg){
mesg.filledText(msg);
};
}
//History of mesg added to the console.
var history = new (function(){
var self = this;
var list = [];
this.add = function(mesg){
list.push(mesg);
};
this.clear=function(){
list=[];
};
this.get=function(nFromLast)//nFromLast is indices from last mesg added.
{
if(list.length<=0)
return;
if(nFromLast==undefined)
var index=0;
else{
if(nFromLast<0)
nFromLast=0;
var index=list.length-(1+nFromLast);
if(index<0)
index=0;
}
return new MessageHandle(list[index]);
};
this.getExternMethods=function(){
return {get:self.get};
};
})();

////////////////////////////////////////////////////////////////////////
// Main entry point
(function(){
Expand All @@ -167,6 +203,7 @@
extern.report = report;
extern.showCompletion = showCompletion;
extern.clearScreen = clearScreen;
extern.history = history.getExternMethods();
})();

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -361,15 +398,15 @@
////////////////////////////////////////////////////////////////////////
// Rotate through the command history
function rotateHistory(n){
if (history.length == 0) return;
if (commandHistory.length == 0) return;
ringn += n;
if (ringn < 0) ringn = history.length;
else if (ringn > history.length) ringn = 0;
if (ringn < 0) ringn = commandHistory.length;
else if (ringn > commandHistory.length) ringn = 0;
var prevText = promptText;
if (ringn == 0) {
promptText = restoreText;
} else {
promptText = history[ringn - 1];
promptText = commandHistory[ringn - 1];
}
if (config.historyPreserveColumn) {
if (promptText.length < column + 1) {
Expand All @@ -393,7 +430,7 @@

// Add something to the history ring
function addToHistory(line){
history.push(line);
commandHistory.push(line);
restoreText = '';
};

Expand Down Expand Up @@ -435,6 +472,7 @@
inner.children(".jquery-console-prompt-box, .jquery-console-message").slice(0, -1).remove();
extern.report(" ");
extern.focus();
history.clear();
};

function deleteNextWord() {
Expand Down Expand Up @@ -590,6 +628,7 @@
if (className) mesg.addClass(className);
mesg.filledText(msg).hide();
inner.append(mesg);
history.add(mesg);
mesg.show();
};

Expand Down Expand Up @@ -832,4 +871,5 @@
$(this).focus();
window.scrollTo(x, y);
};

})(jQuery);