1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.Live = void 0;
|
7 | const ElementFactory_1 = require("yaml-scene/src/elements/ElementFactory");
|
8 | const UserInput_1 = __importDefault(require("yaml-scene/src/elements/UserInput"));
|
9 | const AutoCompleteSuggestion_1 = require("yaml-scene/src/elements/UserInput/question/AutoCompleteSuggestion");
|
10 | const VariableManager_1 = require("yaml-scene/src/singleton/VariableManager");
|
11 | const Functional_1 = require("yaml-scene/src/tags/model/Functional");
|
12 | const Cached_1 = require("./Cached");
|
13 | const Redis_1 = require("./Redis");
|
14 | class Live extends Redis_1.Redis {
|
15 | history;
|
16 | limit;
|
17 | _cmdCaches;
|
18 | constructor() {
|
19 | super();
|
20 | if (this.history === undefined)
|
21 | this.history = true;
|
22 | if (this.limit === undefined)
|
23 | this.limit = 3;
|
24 | }
|
25 | init(props) {
|
26 | super.init(props);
|
27 | if (this.history === undefined)
|
28 | this.history = true;
|
29 | if (this.limit === undefined)
|
30 | this.limit = 3;
|
31 | }
|
32 | async prepare() {
|
33 | await this.proxy.applyVars(this, 'history', 'limit');
|
34 | await super.prepare();
|
35 | }
|
36 | async exec() {
|
37 | if (this.title)
|
38 | this.proxy.logger.info(this.title);
|
39 | this.proxy.logger.debug(VariableManager_1.VariableManager.Instance.vars.$$text.gray.underline(this.uri));
|
40 | if (this.title)
|
41 | console.group();
|
42 | try {
|
43 | if (!this._cmdCaches && this.history) {
|
44 | this._cmdCaches = new Cached_1.Cached(this.uri, this.history);
|
45 | await this._cmdCaches.load();
|
46 | }
|
47 | while (true) {
|
48 | const inputCmd = ElementFactory_1.ElementFactory.CreateTheElement(UserInput_1.default);
|
49 | inputCmd.init({
|
50 | title: 'Enter command',
|
51 | fallback: ' ',
|
52 | type: 'autocomplete',
|
53 | limit: this.limit,
|
54 | choices: Array.from(this._cmdCaches?.data || []).map(e => {
|
55 | return {
|
56 | title: e,
|
57 | value: e
|
58 | };
|
59 | }),
|
60 | suggest: AutoCompleteSuggestion_1.AutoCompleteSuggestion.INCLUDE_AND_ALLOW_NEW,
|
61 | required: true,
|
62 | var: 'cmd'
|
63 | });
|
64 | await inputCmd.prepare();
|
65 | const { cmd } = await inputCmd.exec();
|
66 | try {
|
67 | const newCmd = await this.runCommand({
|
68 | cmd
|
69 | });
|
70 | if (!(newCmd instanceof Functional_1.Functional))
|
71 | this._cmdCaches?.push(cmd);
|
72 | this.proxy.logger.info('');
|
73 | }
|
74 | catch (err) {
|
75 | this.proxy.logger.error(VariableManager_1.VariableManager.Instance.vars.$$text.red(err.message));
|
76 | }
|
77 | finally {
|
78 | await inputCmd.dispose();
|
79 | }
|
80 | }
|
81 | }
|
82 | finally {
|
83 | if (this.title)
|
84 | console.groupEnd();
|
85 | }
|
86 | }
|
87 | }
|
88 | exports.Live = Live;
|
89 |
|
\ | No newline at end of file |