This commit is contained in:
Olivier Gagnon 2019-03-29 11:50:05 -04:00 committed by danielyxie
parent 36499ae9f2
commit cc0e6548ff
3 changed files with 58 additions and 60 deletions

@ -295,7 +295,7 @@ function saveAndCloseScriptEditor() {
//Checks that the string contains only valid characters for a filename, which are alphanumeric, //Checks that the string contains only valid characters for a filename, which are alphanumeric,
// underscores, hyphens, and dots // underscores, hyphens, and dots
function checkValidFilename(filename) { function checkValidFilename(filename) {
var regex = /^[.a-zA-Z0-9_-]+$/; var regex = /^[.a-zA-Z0-9\/_-]+$/;
if (filename.match(regex)) { if (filename.match(regex)) {
return true; return true;

@ -57,6 +57,7 @@ import {yesNoBoxCreate,
yesNoBoxGetYesButton, yesNoBoxGetYesButton,
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";
import { post, import { post,
postContent,
postError, postError,
hackProgressBarPost, hackProgressBarPost,
hackProgressPost } from "./ui/postToTerminal"; hackProgressPost } from "./ui/postToTerminal";
@ -550,6 +551,15 @@ function determineAllPossibilitiesForTabCompletion(input, index=0) {
allPos.push(currServ.scripts[i].filename); allPos.push(currServ.scripts[i].filename);
} }
} }
if (input.startsWith("ls ")) {
for (var i = 0; i < currServ.textFiles.length; ++i) {
allPos.push(currServ.textFiles[i].fn);
}
for (var i = 0; i < currServ.scripts.length; ++i) {
allPos.push(currServ.scripts[i].filename);
}
}
return allPos; return allPos;
} }
@ -1677,13 +1687,14 @@ let Terminal = {
}, },
executeListCommand: function(commandArray) { executeListCommand: function(commandArray) {
if (commandArray.length !== 1 && commandArray.length !== 4) { if (commandArray.length !== 1 && commandArray.length !== 2 && commandArray.length !== 4) {
postError("Incorrect usage of ls command. Usage: ls [| grep pattern]"); postError("Incorrect usage of ls command. Usage: ls [| grep pattern]");
return; return;
} }
// grep // grep
var filter = null; let filter = null;
let prefix = null;
if (commandArray.length === 4) { if (commandArray.length === 4) {
if (commandArray[1] === "|" && commandArray[2] === "grep") { if (commandArray[1] === "|" && commandArray[2] === "grep") {
if (commandArray[3] !== " ") { if (commandArray[3] !== " ") {
@ -1693,73 +1704,60 @@ let Terminal = {
postError("Incorrect usage of ls command. Usage: ls [| grep pattern]"); postError("Incorrect usage of ls command. Usage: ls [| grep pattern]");
return; return;
} }
} else if (commandArray.length === 2) { // want to ls a folder
prefix = commandArray[1];
if (!prefix.endsWith("/")) {
prefix += "/";
}
} }
//Display all programs and scripts //Display all programs and scripts
var allFiles = []; let allFiles = [];
let folders = [];
function handleFn(fn) {
if (filter && !fn.includes(filter)) {
return;
}
if (prefix) {
if (!fn.startsWith(prefix)) {
return;
} else {
fn = fn.slice(prefix.length, fn.length);
}
}
if (fn.includes("/")) {
fn = fn.split("/")[0]+"/";
if (folders.includes(fn)) {
return;
}
folders.push(fn);
}
allFiles.push(fn);
}
//Get all of the programs and scripts on the machine into one temporary array //Get all of the programs and scripts on the machine into one temporary array
const s = Player.getCurrentServer(); const s = Player.getCurrentServer();
for (const program of s.programs) { for (const program of s.programs) handleFn(program);
if (filter) { for (const script of s.scripts) handleFn(script.filename);
if (program.includes(filter)) { for (const txt of s.textFiles) handleFn(txt.fn);
allFiles.push(program); for (const contract of s.contracts) handleFn(contract.fn);
} for (const msgOrLit of s.messages) (msgOrLit instanceof Message) ? handleFn(msgOrLit.filename) : handleFn(msgOrLit);
} else {
allFiles.push(program);
}
}
for (const script of s.scripts) {
if (filter) {
if (script.filename.includes(filter)) {
allFiles.push(script.filename);
}
} else {
allFiles.push(script.filename);
}
}
for (const msgOrLit of s.messages) {
if (filter) {
if (msgOrLit instanceof Message) {
if (msgOrLit.filename.includes(filter)) {
allFiles.push(msgOrLit.filename);
}
} else if (msgOrLit.includes(filter)) {
allFiles.push(msgOrLit);
}
} else {
if (msgOrLit instanceof Message) {
allFiles.push(msgOrLit.filename);
} else {
allFiles.push(msgOrLit);
}
}
}
for (const txt of s.textFiles) {
if (filter) {
if (txt.fn.includes(filter)) {
allFiles.push(txt.fn);
}
} else {
allFiles.push(txt.fn);
}
}
for (const contract of s.contracts) {
if (filter) {
if (contract.fn.includes(filter)) {
allFiles.push(contract.fn);
}
} else {
allFiles.push(contract.fn);
}
}
//Sort the files alphabetically then print each //Sort the files alphabetically then print each
allFiles.sort(); allFiles.sort();
for (var i = 0; i < allFiles.length; i++) { for (var i = 0; i < allFiles.length; i++) {
post(allFiles[i]); let config = {};
if (allFiles[i].endsWith("/")) {
// Don't let the colorblind chose the color. I believe that's
// ubuntu folder color but what the fuck do I know.
config.color = "#58698c";
}
postContent(allFiles[i], config);
} }
}, },

@ -33,7 +33,7 @@ interface IPostContentConfig {
color?: string; // Additional class for terminal-line. Does NOT replace color?: string; // Additional class for terminal-line. Does NOT replace
} }
function postContent(input: string, config: IPostContentConfig = {}) { export function postContent(input: string, config: IPostContentConfig = {}) {
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length
const style: string = `color: ${config.color != null ? config.color : "var(--my-font-color)"}; background-color:var(--my-background-color);${config.id === undefined ? " white-space:pre-wrap;" : ""}`; const style: string = `color: ${config.color != null ? config.color : "var(--my-font-color)"}; background-color:var(--my-background-color);${config.id === undefined ? " white-space:pre-wrap;" : ""}`;
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length