Skip to content

Commit

Permalink
fix(terminal): fix terminal output times
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Oct 1, 2017
1 parent 583c9b6 commit 6e2445b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
28 changes: 15 additions & 13 deletions src/app/components/app-terminal/app-terminal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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) => {
Expand All @@ -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;
}
Expand Down

0 comments on commit 6e2445b

Please sign in to comment.