@sentry/wizard
Version:
Sentry wizard helping you to configure your project
137 lines • 8.59 kB
JavaScript
"use strict";
// Vendored and adjusted from: https://github.com/natemoo-re/clack/blob/593f93d06c1a53c8424e9aaf0c1c63fbf6975527/packages/prompts/src/index.ts
// Upstream PR: https://github.com/natemoo-re/clack/pull/129
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.windowedSelect = void 0;
// MIT License
// Copyright (c) Nate Moore
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---
// `ansi-regex` is adapted from https://github.com/chalk/ansi-regex
// MIT License
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---
// @ts-ignore
var clackCore = __importStar(require("@clack/core"));
var picocolors_1 = __importDefault(require("picocolors"));
var is_unicorn_supported_1 = require("./is-unicorn-supported");
var unicode = (0, is_unicorn_supported_1.isUnicodeSupported)();
var s = function (c, fallback) { return (unicode ? c : fallback); };
var S_RADIO_ACTIVE = s('●', '>');
var S_RADIO_INACTIVE = s('○', ' ');
var S_BAR = s('│', '|');
var S_STEP_ACTIVE = s('◆', '*');
var S_STEP_CANCEL = s('■', 'x');
var S_STEP_ERROR = s('▲', 'x');
var S_STEP_SUBMIT = s('◇', 'o');
var S_BAR_END = s('└', '—');
var symbol = function (state) {
switch (state) {
case 'initial':
case 'active':
return picocolors_1.default.cyan(S_STEP_ACTIVE);
case 'cancel':
return picocolors_1.default.red(S_STEP_CANCEL);
case 'error':
return picocolors_1.default.yellow(S_STEP_ERROR);
case 'submit':
return picocolors_1.default.green(S_STEP_SUBMIT);
}
};
/**
* Like the normal clack select prompt but with a `maxItems` option.
*/
var windowedSelect = function (opts) {
var opt = function (option, state) {
var _a;
var label = (_a = option.label) !== null && _a !== void 0 ? _a : String(option.value);
if (state === 'active') {
return "".concat(picocolors_1.default.green(S_RADIO_ACTIVE), " ").concat(label, " ").concat(option.hint ? picocolors_1.default.dim("(".concat(option.hint, ")")) : '');
}
else if (state === 'selected') {
return "".concat(picocolors_1.default.dim(label));
}
else if (state === 'cancelled') {
return "".concat(picocolors_1.default.strikethrough(picocolors_1.default.dim(label)));
}
return "".concat(picocolors_1.default.dim(S_RADIO_INACTIVE), " ").concat(picocolors_1.default.dim(label));
};
var slidingWindowLocation = 0;
return new clackCore.SelectPrompt({
options: opts.options,
initialValue: opts.initialValue,
render: function () {
var _this = this;
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
var title = "".concat(picocolors_1.default.gray(S_BAR), "\n").concat(symbol(this.state), " ").concat(opts.message, "\n");
switch (this.state) {
case 'submit':
return "".concat(title).concat(picocolors_1.default.gray(S_BAR), " ").concat(opt(this.options[this.cursor], 'selected'));
case 'cancel':
return "".concat(title).concat(picocolors_1.default.gray(S_BAR), " ").concat(opt(this.options[this.cursor], 'cancelled'), "\n").concat(picocolors_1.default.gray(S_BAR));
default: {
// We clamp to minimum 5 because anything less doesn't make sense UX wise
var maxItems = opts.maxItems === undefined ? Infinity : Math.max(opts.maxItems, 5);
if (this.cursor >= slidingWindowLocation + maxItems - 3) {
slidingWindowLocation = Math.max(Math.min(this.cursor - maxItems + 3, this.options.length - maxItems), 0);
}
else if (this.cursor < slidingWindowLocation + 2) {
slidingWindowLocation = Math.max(this.cursor - 2, 0);
}
var shouldRenderTopEllipsis_1 = maxItems < this.options.length && slidingWindowLocation > 0;
var shouldRenderBottomEllipsis_1 = maxItems < this.options.length &&
slidingWindowLocation + maxItems < this.options.length;
return "".concat(title).concat(picocolors_1.default.cyan(S_BAR), " ").concat(this.options
.slice(slidingWindowLocation, slidingWindowLocation + maxItems)
.map(function (option, i, arr) {
if (i === 0 && shouldRenderTopEllipsis_1) {
return picocolors_1.default.dim('...');
}
else if (i === arr.length - 1 && shouldRenderBottomEllipsis_1) {
return picocolors_1.default.dim('...');
}
else {
return opt(option, i + slidingWindowLocation === _this.cursor
? 'active'
: 'inactive');
}
})
.join("\n".concat(picocolors_1.default.cyan(S_BAR), " ")), "\n").concat(picocolors_1.default.cyan(S_BAR_END), "\n");
}
}
},
}).prompt();
};
exports.windowedSelect = windowedSelect;
//# sourceMappingURL=clack-custom-select.js.map