mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
add ability to up-arrow thru commands, a couple css fixes
This commit is contained in:
parent
679ae64be2
commit
58cf016410
21 changed files with 251 additions and 138 deletions
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
require 'train'
|
||||
|
||||
commands = { 'inspec_exec' => 'inspec exec examples/profile/controls/example.rb', 'inspec_version' => 'inspec version' }
|
||||
commands = { 'inspec_exec' => 'inspec exec examples/profile/controls/example.rb', 'inspec_version' => 'inspec version', 'help' => 'inspec help' }
|
||||
|
||||
backend = Train.create('local')
|
||||
conn = backend.connection
|
||||
|
@ -13,10 +13,15 @@ commands.each do |keyname, command|
|
|||
|
||||
# save the result and put it in inspec/www/app/results with the keyname as filename
|
||||
result = cmd.stdout
|
||||
dir = 'www/app/responses/'
|
||||
out_file = File.new(File.join(dir, "#{keyname}.txt"), 'w')
|
||||
out_file.puts(result)
|
||||
dir = 'www/tutorial/app/responses/'
|
||||
filename = File.join(dir, "#{keyname}.txt")
|
||||
out_file = File.new(filename, 'w')
|
||||
result.lines.each do |line|
|
||||
line_to_write = "#{line.chomp}\r\n"
|
||||
out_file.write(line_to_write)
|
||||
end
|
||||
out_file.close
|
||||
puts "Wrote #{filename}"
|
||||
end
|
||||
|
||||
conn.close
|
||||
|
|
6
www/tutorial/.gitignore
vendored
6
www/tutorial/.gitignore
vendored
|
@ -7,5 +7,7 @@
|
|||
/node_modules
|
||||
npm-debug.log
|
||||
|
||||
*.js
|
||||
*.js.map
|
||||
app/*.js
|
||||
app/*.map
|
||||
app/**/*.js
|
||||
app/**/*.map
|
|
@ -1,4 +1,7 @@
|
|||
## InSpec Demo
|
||||
|
||||
run `npm install` to load dependencies
|
||||
run `npm start` to load demo in your browser
|
||||
run `npm start` to load demo in your browser
|
||||
|
||||
To generate content for the app/responses folder,
|
||||
run `bundle exec rake update demo` from the root of inspec project.
|
|
@ -31,6 +31,11 @@
|
|||
background-color: #444;
|
||||
}
|
||||
|
||||
a {
|
||||
color: lightskyblue;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.cli {
|
||||
font-family: monospace;
|
||||
font-size: 1.2rem;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<div class="terminal-nav">
|
||||
<!--TODO: make these functional-->
|
||||
<span> < </span>
|
||||
<span> > </span>
|
||||
<span (click)="updateInstructions('prev')"> < </span>
|
||||
<span (click)="updateInstructions('next')"> > </span>
|
||||
<span> x </span>
|
||||
</div>
|
||||
|
||||
|
@ -20,9 +19,9 @@
|
|||
</div>
|
||||
|
||||
<div class="guide" *ngIf="counter > 0">
|
||||
<pre > {{ instructions }} </pre>
|
||||
<pre> {{ instructions }} </pre>
|
||||
</div>
|
||||
|
||||
<div class="cli">
|
||||
<xterm-terminal (stepNumber)="updateInstructions(stepNumber=$event)" [responsesArray]="responsesArray"></xterm-terminal>
|
||||
<xterm-terminal (command)="evalCommand(command=$event)" [responsesArray]="responsesArray" [response]="response" [shell]="shell"></xterm-terminal>
|
||||
</div>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"app.component.js","sourceRoot":"","sources":["app.component.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAAkC,eAAe,CAAC,CAAA;AAClD,qBAA+B,eAAe,CAAC,CAAA;AAC/C,mBAA2B,SAAS,CAAC,CAAA;AACrC,qBAA+B,eAAe,CAAC,CAAA;AAC/C,yCAAuC,2CAA2C,CAAC,CAAA;AAUnF;IAME,sBAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAI,CAAC;IAEnC,+BAAQ,GAAR;QACE,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,yCAAkB,GAAlB,UAAmB,IAAI;QACrB,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;YACb,IAAI,GAAG,CAAC,CAAA;QACV,CAAC;QACD,IAAI,CAAC,OA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,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,wBAAwB;YACrC,SAAS,EAAE,CAAC,uBAAuB,CAAC;YACpC,SAAS,EAAE,CAAE,qBAAc,CAAE;YAC7B,UAAU,EAAE,CAAE,iDAAsB,CAAE;SACvC,CAAC;;oBAAA;IAmDF,mBAAC;AAAD,CAAC,AAjDD,IAiDC;AAjDY,oBAAY,eAiDxB,CAAA"}
|
|
@ -16,7 +16,9 @@ export class AppComponent implements OnInit {
|
|||
instructions: any;
|
||||
instructionsArray: any;
|
||||
responsesArray: any;
|
||||
counter: number;
|
||||
counter: number = 0;
|
||||
response: string;
|
||||
shell: string;
|
||||
|
||||
constructor(private http: Http) { }
|
||||
|
||||
|
@ -26,11 +28,78 @@ export class AppComponent implements OnInit {
|
|||
}
|
||||
|
||||
updateInstructions(step) {
|
||||
if (step < 0) {
|
||||
step = 0
|
||||
let totalSteps = this.instructionsArray.length - 1;
|
||||
if (step === 'next' && this.counter < totalSteps) {
|
||||
this.counter += 1;
|
||||
}
|
||||
else if (step === 'prev' && this.counter > 0) {
|
||||
this.counter -= 1;
|
||||
}
|
||||
else {
|
||||
this.counter = 0;
|
||||
}
|
||||
|
||||
this.instructions = this.instructionsArray[this.counter]['_body'];
|
||||
}
|
||||
|
||||
evalCommand(command) {
|
||||
// play with inspec shell
|
||||
if (this.shell === 'inspec-shell') {
|
||||
this.parseInspecShell(command);
|
||||
}
|
||||
// match on various commands or print inspec help
|
||||
else {
|
||||
if (command === 'inspec shell') {
|
||||
this.shell = 'inspec-shell'
|
||||
this.response = 'Welcome to the InSpec Shell\n To find out how to use it, type: help\n';
|
||||
}
|
||||
// TODO: cat readme.md less readme.md "Only a few commands are implemented in this terminal."
|
||||
else if (command.match(/^inspec\s*exec\s*.*/)) {
|
||||
this.parseInspecExec(command);
|
||||
}
|
||||
else if (command.match(/^inspec\s*version\s*/)) {
|
||||
this.response = this.responsesArray[4]['_body'];
|
||||
}
|
||||
else if (command.match(/^next\s*/)) {
|
||||
this.updateInstructions('next');
|
||||
}
|
||||
else if (command.match(/^prev\s*/)) {
|
||||
this.updateInstructions('prev');
|
||||
}
|
||||
else if (command.match(/^ls\s*/)) {
|
||||
this.response = this.responsesArray[1]['_body'];
|
||||
}
|
||||
else if (command.match(/^pwd\s*/)) {
|
||||
this.response = this.responsesArray[2]['_body'];
|
||||
}
|
||||
else {
|
||||
this.response = this.responsesArray[0]['_body'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parseInspecExec(command) {
|
||||
let target = command.match(/^inspec exec\s*(.*)/);
|
||||
if (target[1] === 'examples/profile') {
|
||||
this.response = this.responsesArray[3]['_body'];
|
||||
} else {
|
||||
this.response = "Could not fetch inspec profile in '" + target[1] + "' ";
|
||||
}
|
||||
}
|
||||
|
||||
parseInspecShell(command) {
|
||||
// exit inspec shell
|
||||
if (command.match(/^exit\s*/)) {
|
||||
this.shell = '';
|
||||
this.response = '';
|
||||
}
|
||||
else if (command.match(/^ls\s*/)) {
|
||||
this.response = this.responsesArray[5]['_body'];
|
||||
}
|
||||
// TODO: functionality for inspec Shell
|
||||
else {
|
||||
this.response = 'soon this will work, but not yet :) '
|
||||
}
|
||||
this.counter = step;
|
||||
this.instructions = this.instructionsArray[step]['_body'];
|
||||
}
|
||||
|
||||
getInstructions() {
|
||||
|
@ -53,7 +122,8 @@ export class AppComponent implements OnInit {
|
|||
this.http.get('/app/responses/ls.txt'), // 1
|
||||
this.http.get('/app/responses/pwd.txt'), // 2
|
||||
this.http.get('/app/responses/inspec_exec.txt'), // 3
|
||||
this.http.get('/app/responses/inspec_version.txt') // 4
|
||||
this.http.get('/app/responses/inspec_version.txt'), // 4
|
||||
this.http.get('/app/responses/pwd_inspec_shell.txt') // 5
|
||||
).subscribe(
|
||||
data => {
|
||||
this.responsesArray = data;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["app.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAA8B,eAAe,CAAC,CAAA;AAC9C,iCAA8B,2BAA2B,CAAC,CAAA;AAE1D,8BAA8B,iBAAiB,CAAC,CAAA;AAOhD;IAAA;IAAyB,CAAC;IAL1B;QAAC,eAAQ,CAAC;YACR,OAAO,EAAO,CAAE,gCAAa,CAAE;YAC/B,YAAY,EAAE,CAAE,4BAAY,CAAE;YAC9B,SAAS,EAAK,CAAE,4BAAY,CAAE;SAC/B,CAAC;;iBAAA;IACuB,gBAAC;AAAD,CAAC,AAA1B,IAA0B;AAAb,iBAAS,YAAI,CAAA"}
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";AAAA,yCAAuC,mCAAmC,CAAC,CAAA;AAE3E,2BAA0B,cAAc,CAAC,CAAA;AAEzC,iDAAsB,EAAE,CAAC,eAAe,CAAC,sBAAS,CAAC,CAAC"}
|
|
@ -1,18 +1,20 @@
|
|||
Commands:
|
||||
inspec archive PATH # archive a profile to tar.gz (default) or zip
|
||||
inspec check PATH # verify all tests at the specified PATH
|
||||
inspec compliance SUBCOMMAND ... # Chef Compliance commands
|
||||
inspec detect # detect the target OS
|
||||
inspec env # Output shell-appropriate completion configuration
|
||||
inspec exec PATHS # run all test files at the specified PATH.
|
||||
inspec help [COMMAND] # Describe available commands or one specific command
|
||||
inspec init TEMPLATE ... # Scaffolds a new project
|
||||
inspec json PATH # read all tests in PATH and generate a JSON summary
|
||||
inspec msccm SUBCOMMAND ... # Microsoft Systems Center Configuration Manager commands
|
||||
inspec scap SUBCOMMAND ... # SCAP commands
|
||||
inspec shell # open an interactive debugging shell
|
||||
inspec supermarket SUBCOMMAND ... # Supermarket commands
|
||||
inspec version # prints the version of this tool
|
||||
|
||||
Options:
|
||||
[--diagnose], [--no-diagnose] # Show diagnostics (versions, configurations)
|
||||
Commands:
|
||||
inspec archive PATH # archive a profile to tar.gz (default) ...
|
||||
inspec check PATH # verify all tests at the specified PATH
|
||||
inspec compliance SUBCOMMAND ... # Chef Compliance commands
|
||||
inspec detect # detect the target OS
|
||||
inspec env # Output shell-appropriate completion co...
|
||||
inspec exec PATHS # run all test files at the specified PATH.
|
||||
inspec help [COMMAND] # Describe available commands or one spe...
|
||||
inspec init TEMPLATE ... # Scaffolds a new project
|
||||
inspec json PATH # read all tests in PATH and generate a ...
|
||||
inspec shell # open an interactive debugging shell
|
||||
inspec supermarket SUBCOMMAND ... # Supermarket commands
|
||||
inspec vendor # Download all dependencies and generate...
|
||||
inspec version # prints the version of this tool
|
||||
|
||||
Options:
|
||||
l, [--log-level=LOG_LEVEL] # Set the log level: info (default), debug, warn, error
|
||||
[--log-location=LOG_LOCATION] # Location to send diagnostic log messages to. (default: STDOUT or STDERR)
|
||||
[--diagnose], [--no-diagnose] # Show diagnostics (versions, configurations)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
Target: local://
|
||||
|
||||
[32m ✔ tmp-1.0: Create /tmp directory[0m
|
||||
[32m File /tmp should be directory[0m
|
||||
|
||||
File /tmp
|
||||
[32m ✔ should be directory[0m
|
||||
|
||||
Summary: [32m2 successful[0m, [31m0 failures[0m, [37m0 skipped[0m
|
||||
|
||||
Target: local://
|
||||
|
||||
[32m ✔ tmp-1.0: Create /tmp directory[0m
|
||||
[32m File /tmp should be directory[0m
|
||||
|
||||
File /tmp
|
||||
[32m ✔ should be directory[0m
|
||||
|
||||
Summary: [32m2 successful[0m, [31m0 failures[0m, [37m0 skipped[0m
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.32.0
|
||||
0.32.0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Berksfile Dockerfile LICENSE Rakefile docs lib test
|
||||
Berksfile.lock Gemfile MAINTAINERS.md appveyor.yml examples omnibus www
|
||||
CHANGELOG.md Gemfile.lock MAINTAINERS.toml bin inspec-0.30.0.gem profile.tar.gz
|
||||
CONTRIBUTING.md ISSUE_TEMPLATE.md README.md coverage inspec.gemspec tasks
|
||||
Berksfile CONTRIBUTING.md Gemfile.lock MAINTAINERS.md Rakefile coverage inspec-0.30.0.gem
|
||||
omnibus test Berksfile.lock Dockerfile ISSUE_TEMPLATE.md MAINTAINERS.toml appveyor.yml
|
||||
docs inspec.gemspec profile.tar.gz www CHANGELOG.md Gemfile LICENSE
|
||||
README.md bin examples lib tasks
|
1
www/tutorial/app/responses/pwd_inspec_shell.txt
Normal file
1
www/tutorial/app/responses/pwd_inspec_shell.txt
Normal file
|
@ -0,0 +1 @@
|
|||
anonymous-web-user/inspec-shell
|
|
@ -12,6 +12,7 @@ classes, so i added a host and /deep/ call to ensure they get set*/
|
|||
background-color: black;
|
||||
color: #fafafa;
|
||||
padding: 2px;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
:host /deep/ .terminal:focus .terminal-cursor {
|
||||
|
@ -20,4 +21,4 @@ classes, so i added a host and /deep/ call to ensure they get set*/
|
|||
|
||||
:host /deep/ .xterm-helpers {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
<!--try to bring in xterm-->
|
||||
<div (keyup)="onKey($event)" id="terminal-container"></div>
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"xterm-terminal.component.js","sourceRoot":"","sources":["xterm-terminal.component.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAA+D,eAAe,CAAC,CAAA;AAQ/E;IAAA;QAEY,eAAU,GAAyB,IAAI,mBAAY,EAAU,CAAC;QACxE,SAAI,GAAW,CAAC,CAAC;QAEjB,WAAM,GAAW,EAAE,CAAC;IAwItB,CAAC;IAjIA,yCAAQ,GAAR;QACG,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC;YACtE,IAAI,CAAC,cAAc,GAAG;gBACpB,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,sBAAsB,CAAC;aAC5D;YACD,IAAI,CAAC,IAAI,GAAG,IAAI;YAChB,IAAI,CAAC,IAAI,GAAG,IAAI,C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A;IACR;QAAC,aAAM,EAAE;;8DAAA;IAPX;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,kDAAkD;YAC/D,SAAS,EAAE,CAAC,iDAAiD,CAAC;SAC/D,CAAC;;8BAAA;IA8IF,6BAAC;AAAD,CAAC,AA7ID,IA6IC;AA7IY,8BAAsB,yBA6IlC,CAAA"}
|
|
@ -1,4 +1,4 @@
|
|||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { Component, OnInit, Input, Output, EventEmitter, SimpleChange } from '@angular/core';
|
||||
declare var Terminal: any;
|
||||
|
||||
@Component({
|
||||
|
@ -7,27 +7,43 @@ declare var Terminal: any;
|
|||
styleUrls: ['app/xterm-terminal/xterm-terminal.component.css']
|
||||
})
|
||||
export class XtermTerminalComponent implements OnInit {
|
||||
@Input() response: string;
|
||||
@Input() responsesArray: any;
|
||||
@Output() stepNumber: EventEmitter<number> = new EventEmitter<number>();
|
||||
step: number = 0;
|
||||
shellprompt: string;
|
||||
@Input() shell: string;
|
||||
@Output() command: EventEmitter<string> = new EventEmitter<string>();
|
||||
previousCommands: any = [];
|
||||
last: number;
|
||||
currentResponse: string;
|
||||
shellStatus: string;
|
||||
buffer: string = '';
|
||||
|
||||
// xterm variables
|
||||
terminalContainer: any;
|
||||
term: any;
|
||||
optionElements: any;
|
||||
cols: any;
|
||||
rows: any;
|
||||
cols: string;
|
||||
rows: string;
|
||||
shellprompt: string = '$ ';
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.terminalContainer = document.getElementById('terminal-container'),
|
||||
this.optionElements = {
|
||||
cursorBlink: document.querySelector('#option-cursor-blink')
|
||||
cursorBlink: true
|
||||
},
|
||||
this.cols = '70',
|
||||
this.rows = '70';
|
||||
this.createTerminal();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
|
||||
if (changes['response'] && this.term) {
|
||||
this.currentResponse = changes['response'].currentValue;
|
||||
this.term.writeln(this.currentResponse);
|
||||
this.setPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
createTerminal() {
|
||||
while (this.terminalContainer.children.length) {
|
||||
this.terminalContainer.removeChild(this.terminalContainer.children[0]);
|
||||
|
@ -52,99 +68,67 @@ export class XtermTerminalComponent implements OnInit {
|
|||
if (this.term._initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.term._initialized = true;
|
||||
this.setPrompt();
|
||||
|
||||
this.term.writeln('WELCOME TO YOUR INSPEC DEMO SHELL FOOL!');
|
||||
this.term.writeln('');
|
||||
this.setPrompt();
|
||||
}
|
||||
|
||||
setPrompt() {
|
||||
this.buffer = ''
|
||||
this.shellprompt = '$ ';
|
||||
this.term.write('\r\n' + this.shellprompt);
|
||||
}
|
||||
|
||||
setInspecShellPrompt() {
|
||||
this.term.write('\r\ninspec> ');
|
||||
this.setPrompt();
|
||||
this.buffer = '';
|
||||
if (this.shell === 'inspec-shell') {
|
||||
this.term.write('\r\ninspec> ');
|
||||
} else {
|
||||
this.term.write('\r\n' + this.shellprompt);
|
||||
}
|
||||
}
|
||||
|
||||
onKey(ev) {
|
||||
var shell = null
|
||||
var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey)
|
||||
var printable = ['Alt', 'Control', 'Meta', 'Shift', 'CapsLock', 'Tab', 'Escape'].indexOf(ev.key) == -1
|
||||
|
||||
// on enter, check buffer and print response
|
||||
// on enter, save command to array and send current value of buffer
|
||||
// to parent component (app). if the command is the same as the previous command
|
||||
// entered, we just diplay the currentResponse. the reason this is being done here and
|
||||
// not in the app component is because the ngOnChanges that tracks the value of the
|
||||
// emitted event won't recognize that there has been a change if it is the same
|
||||
if (ev.keyCode == 13) {
|
||||
this.previousCommands.push(this.buffer);
|
||||
this.term.write('\r\n');
|
||||
|
||||
// play with inspec shell
|
||||
if (this.buffer == 'inspec shell') {
|
||||
shell = 'inspec-shell'
|
||||
this.term.writeln('Welcome to the interactive InSpec Shell');
|
||||
this.term.writeln('To find out how to use it, type: help')
|
||||
this.setInspecShellPrompt();
|
||||
if (this.previousCommands.length > 1) {
|
||||
this.last = this.previousCommands.length - 2
|
||||
}
|
||||
|
||||
// exit inspec shell
|
||||
if (this.buffer == 'exit' && shell == 'inspec-shell' ) {
|
||||
shell = null
|
||||
if (this.buffer === this.previousCommands[this.last]) {
|
||||
this.term.writeln(this.currentResponse);
|
||||
this.setPrompt();
|
||||
}
|
||||
|
||||
// TODO: functionality for inspec shell
|
||||
if (shell == 'inspec-shell') {
|
||||
if (this.buffer == 'os.params') {
|
||||
this.term.writeln('print file content for shell');
|
||||
}
|
||||
|
||||
} else {
|
||||
// match on various commands or print inspec help
|
||||
if (this.buffer.match(/^inspec\s*exec\s*.*/)) {
|
||||
this.parseInspecExec(this.buffer);
|
||||
}
|
||||
else if (this.buffer.match(/^inspec\s*version\s*/)) {
|
||||
this.term.writeln(this.responsesArray[4]['_body']);
|
||||
this.setPrompt();
|
||||
}
|
||||
else if (this.buffer.match(/^next\s*/)) {
|
||||
this.step += 1;
|
||||
this.stepNumber.emit(this.step);
|
||||
this.setPrompt();
|
||||
}
|
||||
else if (this.buffer.match(/^previous\s*/)) {
|
||||
this.step -= 1;
|
||||
this.stepNumber.emit(this.step);
|
||||
this.setPrompt();
|
||||
}
|
||||
else {
|
||||
this.term.writeln(this.responsesArray[0]['_body']);
|
||||
this.setPrompt();
|
||||
}
|
||||
else {
|
||||
this.command.emit(this.buffer);
|
||||
}
|
||||
|
||||
}
|
||||
// on backspace, pop characters from buffer
|
||||
} else if (ev.keyCode == 8) {
|
||||
else if (ev.keyCode == 8) {
|
||||
if (this.term.x > 2) {
|
||||
this.buffer = this.buffer.substr(0, this.buffer.length-1)
|
||||
this.buffer = this.buffer.substr(0, this.buffer.length-1);
|
||||
this.term.write('\b \b');
|
||||
}
|
||||
} else if (printable) {
|
||||
}
|
||||
// on up arrow, delete anything on line and print previous command
|
||||
else if (ev.keyCode === 38) {
|
||||
let last;
|
||||
if (this.previousCommands.length > 0) {
|
||||
last = this.previousCommands.pop();
|
||||
} else {
|
||||
last = '';
|
||||
}
|
||||
let letters = this.term.x - 2;
|
||||
for (var i = 0; i < letters; i++) {
|
||||
this.term.write('\b \b');
|
||||
}
|
||||
this.term.write(last);
|
||||
}
|
||||
// write each character on prompt line
|
||||
else if (printable) {
|
||||
this.term.write(ev.key);
|
||||
this.buffer += ev.key;
|
||||
}
|
||||
}
|
||||
|
||||
parseInspecExec(value) {
|
||||
let target = value.match(/^inspec exec\s*(.*)/);
|
||||
if (target[1] === 'examples/profile') {
|
||||
this.term.writeln(this.responsesArray[3]['_body']);
|
||||
this.setPrompt();
|
||||
} else {
|
||||
this.term.writeln("Could not fetch inspec profile in '" + target[1] + "' ");
|
||||
this.setPrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
"reflect-metadata": "^0.1.3",
|
||||
"rxjs": "5.0.0-beta.6",
|
||||
"systemjs": "0.19.27",
|
||||
"xterm": "git://github.com/sourcelair/xterm.js.git",
|
||||
"xterm": "git://github.com/sourcelair/xterm.js.git#1.1.2",
|
||||
"zone.js": "^0.6.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -3,6 +3,4 @@
|
|||
body {
|
||||
color: white;
|
||||
background-color: black;
|
||||
margin: 2em;
|
||||
font-weight: 100;
|
||||
}
|
48
www/tutorial/systemjs.config.js
Normal file
48
www/tutorial/systemjs.config.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* System configuration for Angular 2 samples
|
||||
* Adjust as necessary for your application needs.
|
||||
*/
|
||||
(function(global) {
|
||||
// map tells the System loader where to look for things
|
||||
var map = {
|
||||
'app': 'app', // 'dist',
|
||||
'@angular': 'node_modules/@angular',
|
||||
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
|
||||
'rxjs': 'node_modules/rxjs'
|
||||
};
|
||||
// packages tells the System loader how to load when no filename and/or no extension
|
||||
var packages = {
|
||||
'app': { main: 'main.js', defaultExtension: 'js' },
|
||||
'rxjs': { defaultExtension: 'js' },
|
||||
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
|
||||
};
|
||||
var ngPackageNames = [
|
||||
'common',
|
||||
'compiler',
|
||||
'core',
|
||||
'forms',
|
||||
'http',
|
||||
'platform-browser',
|
||||
'platform-browser-dynamic',
|
||||
'router',
|
||||
'router-deprecated',
|
||||
'upgrade',
|
||||
];
|
||||
// Individual files (~300 requests):
|
||||
function packIndex(pkgName) {
|
||||
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
|
||||
}
|
||||
// Bundled (~40 requests):
|
||||
function packUmd(pkgName) {
|
||||
packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
|
||||
}
|
||||
// Most environments should use UMD; some (Karma) need the individual index files
|
||||
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
|
||||
// Add package entries for angular packages
|
||||
ngPackageNames.forEach(setPackageConfig);
|
||||
var config = {
|
||||
map: map,
|
||||
packages: packages
|
||||
};
|
||||
System.config(config);
|
||||
})(this);
|
Loading…
Reference in a new issue