sm shiiii

stable
Valerie 2022-03-04 05:17:15 -05:00
parent 611a1a9d29
commit ba9aea4ad5
5 changed files with 116 additions and 19 deletions

View File

@ -1,12 +1,14 @@
{ {
"name": "renjs", "name": "renjs",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "out/index.js",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@types/node": "^17.0.21", "@types/node": "^17.0.21",
"@types/prompts": "^2.0.14",
"chalk": "^5.0.0", "chalk": "^5.0.0",
"prompts": "^2.4.2",
"sisteransi": "^1.0.5", "sisteransi": "^1.0.5",
"typescript": "^4.6.2" "typescript": "^4.6.2"
}, },

View File

@ -14,7 +14,14 @@ const sleep = (n: number) => new Promise(res => setTimeout(res, n));
async function glitchText(string: string) { async function glitchText(string: string) {
const rchar = () => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM".charAt(Math.floor(Math.random() * 52)); const rchar = () => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM".charAt(Math.floor(Math.random() * 52));
const rcolor = () => chalk.ansi256(Math.floor(Math.random() * 240) + 16); const rcolor = () => chalk.ansi256(Math.floor(Math.random() * 240) + 16);
let inEscape = false;
for(const char of string) { for(const char of string) {
if (char === '\x1b') inEscape = true;
else if (char.match(/[a-zA-Z]/)) inEscape = false;
if(inEscape) {
process.stdout.write(char);
continue;
}
const r = 5 + Math.random() * 5; const r = 5 + Math.random() * 5;
for(let i = 0; i < r; i ++) { for(let i = 0; i < r; i ++) {
process.stdout.write(rcolor()(rchar())); process.stdout.write(rcolor()(rchar()));
@ -29,7 +36,7 @@ async function glitchText(string: string) {
async function slowText(string: string) { async function slowText(string: string) {
for(const char of string) { for(const char of string) {
process.stdout.write(char); process.stdout.write(char);
await sleep(50); await sleep(10);
} }
} }
@ -54,17 +61,4 @@ export class Character {
await slowText(chalk.italic(str)); await slowText(chalk.italic(str));
console.log(); console.log();
} }
} }
const claire = new Character({
name: "Claire",
color: 173
});
console.clear();
process.stdout.write(ansi.cursor.down(process.stdout.rows * 2) + ansi.cursor.hide);
(async () => {
await claire.say("Nice weather we're having!");
await claire.think("Nice weather we're having!");
})();

View File

@ -1,3 +1,83 @@
import ansi from 'sisteransi';
import prompts from 'prompts';
export class Engine { export class Engine {
constructor() {
process.on('beforeExit', () => {
this.prepScreenTop();
})
}
async prompt(question: string, choices: { [key: number]: string } | { [key: string]: string }) {
const _choices = [];
for(const key in choices) {
// * idk how to TS this properly man
_choices.push({ title: (choices as any)[key] as string, value: key})
}
const value = (await prompts({
type: 'select',
name: 'value',
message: question,
choices: _choices,
initial: 1,
hint: ' '
})).value;
process.stdout.write(ansi.cursor.hide);
return value;
}
prepScreen() {
console.clear();
process.stdout.write(
ansi.cursor.down(process.stdout.rows * 2) +
ansi.cursor.hide
);
}
play(fn: Function) {
setTimeout(() => {
fn();
}, 0);
}
emptyLine() {
console.log();
}
prepScreenTop() {
console.clear();
process.stdout.write(
ansi.cursor.down(process.stdout.rows * 2) +
ansi.cursor.hide +
ansi.cursor.up(Math.floor(process.stdout.rows))
);
}
async sceneChange(place: string, time?: string) {
console.log('');
console.log(padCenterWithMargin(place));
console.log('');
}
async timePass(s = 9) {
let bar = [' ', ' '];
for(let i = 0; i < s; i ++) {
const str = bar.join('*');
process.stdout.write('\n' + padCenter(str) + '\n' + ansi.cursor.up(2));
await new Promise(res => setTimeout(res, 300));
bar.push(' ');
}
process.stdout.write(ansi.cursor.down(2));
}
}
function padCenter(str: string, chr = ' ', w = process.stdout.columns) {
const left = Math.floor((w - str.length) / 2);
const right = w - str.length - left;
return chr.repeat(left) + str + chr.repeat(right);
}
function padCenterWithMargin(str: string) {
return padCenter(padCenter(`\u2528 ${str} \u2520`, '\u2500', Math.max(process.stdout.columns - 8, 0)))
} }

View File

@ -1 +1,2 @@
export { Engine } from './Engine'; export { Engine } from './Engine.js';
export { Character } from './Character.js'

View File

@ -2,16 +2,36 @@
# yarn lockfile v1 # yarn lockfile v1
"@types/node@^17.0.21": "@types/node@*", "@types/node@^17.0.21":
version "17.0.21" version "17.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644" resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644"
integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ== integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==
"@types/prompts@^2.0.14":
version "2.0.14"
resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.0.14.tgz#10cb8899844bb0771cabe57c1becaaaca9a3b521"
integrity sha512-HZBd99fKxRWpYCErtm2/yxUZv6/PBI9J7N4TNFffl5JbrYMHBwF25DjQGTW3b3jmXq+9P6/8fCIb2ee57BFfYA==
dependencies:
"@types/node" "*"
chalk@^5.0.0: chalk@^5.0.0:
version "5.0.0" version "5.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.0.tgz#bd96c6bb8e02b96e08c0c3ee2a9d90e050c7b832" resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.0.tgz#bd96c6bb8e02b96e08c0c3ee2a9d90e050c7b832"
integrity sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ== integrity sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ==
kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
prompts@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069"
integrity sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==
dependencies:
kleur "^3.0.3"
sisteransi "^1.0.5"
sisteransi@^1.0.5: sisteransi@^1.0.5:
version "1.0.5" version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"