diff options
author | Minteck <contact@minteck.org> | 2022-07-03 14:23:25 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-07-03 14:23:25 +0200 |
commit | d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc (patch) | |
tree | a8e538a8e32b66fece6a10c198fe700866d1e233 /Library/SDK/Modules/Strawberry.Dialog.js | |
download | strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.gz strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.bz2 strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.zip |
Initial commit
Diffstat (limited to 'Library/SDK/Modules/Strawberry.Dialog.js')
-rw-r--r-- | Library/SDK/Modules/Strawberry.Dialog.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Library/SDK/Modules/Strawberry.Dialog.js b/Library/SDK/Modules/Strawberry.Dialog.js new file mode 100644 index 0000000..95b0d9d --- /dev/null +++ b/Library/SDK/Modules/Strawberry.Dialog.js @@ -0,0 +1,92 @@ +let self = { + Basic: (message, col) => { + console.clear(); + process.stdout.cursorTo(0, 0); + + global.vertical = Math.round(process.stdout.rows / 2 + 1) - 3; + let horizontal = Math.round(process.stdout.columns / 2 - (1 + ((message.length + 8) / 2))); + + for (let n = 0; n < vertical; n++) { + process.stdout.write("\n"); + } + + console.log(" ".repeat(horizontal) + color.bgWhite[col]("╭───" + "─".repeat(message.length) + "───╮")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("│ " + " ".repeat(message.length) + " │")); + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("│") + " " + message + " " + color[col]("│"))); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("│ " + " ".repeat(message.length) + " │")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("╰───" + "─".repeat(message.length) + "───╯")); + + for (let n = 0; n < (vertical - 3); n++) { + process.stdout.write("\n"); + } + }, + + ConfirmLines: (lines, confirm, col) => { + process.stdout.cursorTo(0, 1); + let longest = lines.reduce(function(a, b) { + return a.length > b.length ? a : b + }, ''); + + global.vertical = Math.round(process.stdout.rows / 2 + 1) - 5; + let horizontal = Math.round(process.stdout.columns / 2 - (1 + ((longest.length + 8) / 2))); + + for (let n = 0; n < vertical; n++) { + process.stdout.write("\n"); + } + + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┏━━━" + "━".repeat(longest.length) + "━━━┓")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + + for (let line of lines) { + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + line + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + } + + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length - (confirm.length + 2)) + chalk.bgBlack.white(" " + confirm + " ") + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┗━━━" + "━".repeat(longest.length) + "━━━┛")); + + for (let n = 0; n < (vertical - 3); n++) { + process.stdout.write("\n"); + } + + Strawberry.KeyboardEvents.push(Strawberry.Dialog._KeyboardHandler); + }, + + Confirm: (message, confirm, col) => { + process.stdout.cursorTo(0, 1); + + global.vertical = Math.round(process.stdout.rows / 2 + 1) - 5; + let horizontal = Math.round(process.stdout.columns / 2 - (1 + ((message.length + 8) / 2))); + + for (let n = 0; n < vertical; n++) { + process.stdout.write("\n"); + } + + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┏━━━" + "━".repeat(message.length) + "━━━┓")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + message + " " + color[col]("┃"))); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length - (confirm.length + 2)) + chalk.bgBlack.white(" " + confirm + " ") + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┗━━━" + "━".repeat(message.length) + "━━━┛")); + + for (let n = 0; n < (vertical - 3); n++) { + process.stdout.write("\n"); + } + + Strawberry.KeyboardEvents.push(Strawberry.Dialog._KeyboardHandler); + }, + + WhenConfirmed: () => {}, + + _KeyboardHandler: (sequence) => { + if (sequence === "\r") { + Strawberry.Audio.SystemSound("Strawberry.UI.Button"); + Strawberry.KeyboardEvents.splice(Strawberry.KeyboardEvents.indexOf(Strawberry.Dialog._KeyboardHandler), 1); + Strawberry.Dialog.WhenConfirmed(); + } + } +} + +module.exports = self;
\ No newline at end of file |