decova-gotcha
Version:
It's my personal trial for automating daunting tasks
81 lines • 4.02 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TerminalAgent = void 0;
const decova_environment_1 = require("decova-environment");
const decova_terminal_1 = require("decova-terminal");
const decova_terminal_2 = require("decova-terminal");
const CommonMenu_1 = require("../local-tools-impl/Techies/CommonMenu");
const Intellisense_1 = require("./Intellisense");
var YesOrNo;
(function (YesOrNo) {
YesOrNo["Yes"] = "1- Yes";
YesOrNo["No"] = "0- No";
})(YesOrNo || (YesOrNo = {}));
class TerminalAgent {
static ShowSuccess(text) {
decova_terminal_1.CurrentTerminal.Echo(` ${text} `, decova_terminal_2.Foreground.black, decova_terminal_2.Background.bgGreen, 2, true, true, false, false);
}
static Instruct(text) {
decova_terminal_1.CurrentTerminal.Echo(`██►► ${text}`, decova_terminal_2.Foreground.yellow, decova_terminal_2.Background.bgBlack, 2, true, true, false, true);
}
static Exec(cmdText) {
decova_terminal_1.CurrentTerminal.Exec(cmdText);
}
static HintCurrentDir() {
this.Hint(`@DIR: [${decova_environment_1.Process.Current.CurrentWorkingDirectory.FullName}]`);
}
static Hint(hint) {
decova_terminal_1.CurrentTerminal.Echo(`HINT: ${hint}`, decova_terminal_2.Foreground.yellow, decova_terminal_2.Background.bgBlack, 1, true, false, false, true);
}
static ShowError(error) {
decova_terminal_1.CurrentTerminal.Echo(`! ${error}`, decova_terminal_2.Foreground.redBright, decova_terminal_2.Background.bgBlack, 1, true, true, false, true);
}
static ShowQuestion(question) {
decova_terminal_1.CurrentTerminal.Echo(question, decova_terminal_2.Foreground.magentaBright, decova_terminal_2.Background.bgBlack, 1, true, true, false, true);
}
static YesNoQuestionAsync(question) {
return __awaiter(this, void 0, void 0, function* () {
const promptContinue = new Intellisense_1.Intellisense([YesOrNo.Yes, YesOrNo.No], op => op);
const answer = (yield promptContinue.PromptAsync(question)) == YesOrNo.Yes;
return answer;
});
}
static AskForTextAsync(promptHint) {
return __awaiter(this, void 0, void 0, function* () {
this.ShowQuestion(promptHint);
return yield decova_terminal_1.CurrentTerminal.AskForTextAsync('>>>');
});
}
static AskToRunCommandAsync(cmd) {
return __awaiter(this, void 0, void 0, function* () {
if (!cmd) {
this.ShowError('cmd argument cannot be null! 45277');
}
const run = yield CommonMenu_1.CommonMenu.ShowContinueSkipAsync('>>>');
if (run) {
TerminalAgent.Exec(cmd);
}
else {
TerminalAgent.ShowError('Command was cancelled by user!');
}
});
}
static PickOneAsync(hint, options) {
return __awaiter(this, void 0, void 0, function* () {
const opsMap = {};
options.xForeach(op => opsMap[op] = op);
return yield decova_terminal_1.CurrentTerminal.McqAsync(hint, opsMap);
});
}
}
exports.TerminalAgent = TerminalAgent;
//# sourceMappingURL=TerminalAgent.js.map