Permalink
Browse files

fix(terminal): fix terminal output times

  • Loading branch information...
jkuri committed Oct 1, 2017
1 parent 583c9b6 commit 6e2445b73a3759078625311344c71f99cf4ca0d8

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -136,7 +136,7 @@
"mocha": "^3.5.3",
"monaco-editor": "^0.10.0",
"multer": "^1.3.0",
"ng2-datepicker": "^2.1.0",
"ng2-datepicker": "^2.1.1",
"ngx-slimscroll": "^3.3.3",
"ngx-uploader": "^4.0.0",
"node-sass": "^4.5.3",
@@ -6,7 +6,7 @@ import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { NgUploaderModule } from 'ngx-uploader';
import { NgSlimScrollModule } from 'ngx-slimscroll';
import { NgDatepickerModule } from 'ng2-datepicker';
import { NgDatepickerModule } from 'ng2-datepicker/ng2-datepicker';
import { ConfigServiceProvider } from './services/config.service';
import { ApiServiceProvider } from './services/api.service';
import { TimeServiceProvider } from './services/time.service';
@@ -104,7 +104,6 @@ <h4>General Settings</h4>
<div class="form-field">
<label class="form-label">Is Public</label>
<app-toggle [(ngModel)]="form.public" name="public"></app-toggle>
<p class="helper">Visibility of builds.</p>
</div>
</div>
</div>
@@ -1,4 +1,4 @@
<div class="window-terminal-container dracula-ansi-theme" *ngIf="!noData" slimScroll [options]="scrollOptions" [scrollEvents]="scrollEvents">
<div class="window-terminal-container dracula-ansi-theme" [class.is-hidden]="noData" slimScroll [options]="scrollOptions" [scrollEvents]="scrollEvents">
<div class="terminal" *ngFor="let cmd of commands; let i = index;" [id]="i">
<div class="command-line" (click)="toggleCommand(i)" [class.is-opened]="cmd.visible">
<span class="command" [innerHTML]="cmd.command"></span>
@@ -61,7 +61,7 @@ export class AppTerminalComponent implements OnInit {
if (typeof this.data.clear !== 'undefined') {
this.commands = [];
} else {
const output: string = this.au.ansi_to_html(this.data);
let output: string = this.au.ansi_to_html(this.data);
const regex = /==[&gt;|>](.*)/g;
let match;
let commands: string[] = [];
@@ -75,11 +75,11 @@ export class AppTerminalComponent implements OnInit {
this.commands = [];
}

let retime = new RegExp('exectime.*(\\d)', 'igm');
let retime = new RegExp('\\[exectime\\]: \\d*', 'igm');
let times = [];
while (match = retime.exec(output)) {
let t = match[0].replace('exectime]: ', '').replace(/<span.*/, '');
times.push(t);
let t = match[0].replace(/\[exectime\]: /igm, '');
times.push((t / 10).toFixed(0));
}

this.commands = commands.reduce((acc, curr, i) => {
@@ -90,32 +90,34 @@ export class AppTerminalComponent implements OnInit {
if (!output.match(re)) {
re = new RegExp('(' + c + ')' + '[\\s\\S]+');
}
let retime = new RegExp('exectime.*(\\d)', 'igm');
let t = times[i] ? parseFloat(<any>(times[i] / 10)).toFixed(0) : null;
let time = t && parseInt(<any>t, 10);
let time = times[i] ? Number(times[i]) : null;

let out = output.match(re) && output.match(re)[2] ? output.match(re)[2].trim() : '';
out = out.replace(/\[exectime\]: [0-9.,]+/g, '');
out = out.replace(retime, '');

out = out.replace(/(\[success\]: .*)/igm, '<span class="ansi-green-fg">$1</span>');
out = out.replace(/(\[error\]: .*)/igm, '<span class="ansi-red-fg">$1</span>');

return acc.concat({
command: curr.replace('==&gt;', '').trim(),
visible: i === commands.length - 1 ? true : false,
output: out,
time: times[i] ? this.getDuration(time) : null
time: time ? this.getDuration(time) : ''
});
}, this.commands);
} else {
if (output.includes('[exectime]')) {
let retime = new RegExp('exectime.*(\\d)', 'igm');
let retime = new RegExp('\\[exectime\]: \\d*', 'igm');
let match = output.match(retime);
let t = match[0].replace('exectime]: ', '').replace(/<span.*/, '');
t = t ? parseFloat(<any>(<any>t / 10)).toFixed(0) : null;
let time = t && parseInt(<any>t, 10);
let time = Number((Number(match[0].replace('[exectime]: ', '')) / 10).toFixed(0));

if (this.commands[this.commands.length - 1]) {
this.commands[this.commands.length - 1].time = time ? this.getDuration(time) : '0ms';
}
} else {
output = output.replace(/(\[success\]: .*)/igm, '<span class="ansi-green-fg">$1</span>');
output = output.replace(/(\[error\]: .*)/igm, '<span class="ansi-red-fg">$1</span>');

if (this.commands[this.commands.length - 1]) {
this.commands[this.commands.length - 1].output += output;
}

0 comments on commit 6e2445b

Please sign in to comment.