Skip to content

Commit

Permalink
Configurable delay
Browse files Browse the repository at this point in the history
  • Loading branch information
vtortola committed Aug 12, 2014
1 parent 4628b78 commit f3742d4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
16 changes: 11 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<link href="https://fonts.googleapis.com/css?family=Architects+Daughter" rel="stylesheet" type="text/css">
<link href="example/content/example.css" rel="stylesheet" />
</head>
<body ng-app="ng-terminal-example" ng-controller="console">
<body ng-app="ng-terminal-example">
<section class="console-section">
<section class="container">
<section class="head">
Expand All @@ -32,10 +32,16 @@ <h4>A terminal emulator in Javascript with AngularJS </h4>
GitHub
</a>
</section>
<terminal terminal-class="vintage-terminal">
<p class="click-me">Click me to start commanding !</p>
</terminal>

<div ng-controller="console">
<terminal terminal-class="vintage-terminal">
<p class="click-me">Click me to start commanding !</p>
</terminal>
</div>
<!--<div ng-controller="console">
<terminal>
<p class="click-me">Click me to start commanding !</p>
</terminal>
</div>-->
<a class="unit-tests" href="tests" ng-click="unitTests()">Unit tests</a>

</section>
Expand Down
76 changes: 48 additions & 28 deletions src/vtortola.ng-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
},
getPromptConfiguration: function () {
return me.promptConfiguration;
}
},
outputDelay : 10
};
}];

Expand Down Expand Up @@ -134,6 +135,8 @@
var commandHistory = [];
var commandIndex = -1;

$scope.outputDelay = terminalConfiguration.outputDelay;

terminalConfiguration.getTypeEffect().then(function (effect) {
$scope.typeSound = effect;
});
Expand Down Expand Up @@ -349,7 +352,7 @@
}
else if (endCallback)
endCallback();
}, 10);
}, scope.outputDelay);
}

scope.$watchCollection(function () { return scope.results; }, function (newValues, oldValues) {
Expand All @@ -369,41 +372,58 @@
}];

for (var j = 0; j < newValues.length; j++) {

var newValue = newValues[j];
if (newValue.displayed)
continue;

newValue.displayed = true;

for (var i = newValue.text.length-1; i >= 0; i--) {
var line = document.createElement('pre');
line.className = 'terminal-line';
var textLine = newValue.text[i];

if (newValue.output) {
line.textContent = ' ';
var fi = f.length - 1;
var wrapper = function () {
var wline = line;
var wtextLine = textLine;
var wf = f[fi];
var wbreak = i == newValue.text.length -1 && newValue.breakLine;
f.push(function () {
results[0].appendChild(wline); type(wline, wtextLine, 0, wf);
consoleView[0].scrollTop = consoleView[0].scrollHeight;
if (wbreak) {
var breakLine = document.createElement('br');
results[0].appendChild(breakLine);
}
});
}();
if (scope.outputDelay) {

for (var i = newValue.text.length - 1; i >= 0; i--) {
var line = document.createElement('pre');
line.className = 'terminal-line';

var textLine = newValue.text[i];

if (scope.outputDelay && newValue.output) {
line.textContent = ' ';
var fi = f.length - 1;
var wrapper = function () {
var wline = line;
var wtextLine = textLine;
var wf = f[fi];
var wbreak = i == newValue.text.length - 1 && newValue.breakLine;
f.push(function () {
results[0].appendChild(wline); type(wline, wtextLine, 0, wf);
consoleView[0].scrollTop = consoleView[0].scrollHeight;
if (wbreak) {
var breakLine = document.createElement('br');
results[0].appendChild(breakLine);
}
});
}();
}
else {
line.textContent = textLine;
results[0].appendChild(line)
}

}
else {
line.textContent = textLine;
}
else {
for (var i = 0; i < newValue.text.length; i++) {
var line = document.createElement('pre');
line.textContent = newValue.output?' ':'';
line.className = 'terminal-line';
line.textContent += newValue.text[i];
results[0].appendChild(line)
}

if (!!newValue.breakLine) {
var breakLine = document.createElement('br');
results[0].appendChild(breakLine);
}
}

}
Expand Down

0 comments on commit f3742d4

Please sign in to comment.