summaryrefslogtreecommitdiff
path: root/Library/SDK/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Library/SDK/Modules')
-rw-r--r--Library/SDK/Modules/Strawberry.AppManager.js58
-rw-r--r--Library/SDK/Modules/Strawberry.Audio.js7
-rw-r--r--Library/SDK/Modules/Strawberry.Dialog.js92
-rw-r--r--Library/SDK/Modules/Strawberry.Display.js14
-rw-r--r--Library/SDK/Modules/Strawberry.DisplayRaw.js10
-rw-r--r--Library/SDK/Modules/Strawberry.MenuBar.js143
-rw-r--r--Library/SDK/Modules/Strawberry.SystemInfo.js204
7 files changed, 528 insertions, 0 deletions
diff --git a/Library/SDK/Modules/Strawberry.AppManager.js b/Library/SDK/Modules/Strawberry.AppManager.js
new file mode 100644
index 0000000..71f7079
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.AppManager.js
@@ -0,0 +1,58 @@
+const path = require('path');
+global._STRAWBERRY_CURRENT_APP = null;
+
+module.exports = {
+ Start: (app) => {
+ Strawberry.Tick.Events = [];
+ Strawberry.ProcessKeyboard = false;
+ let name = path.basename(app, ".app");
+
+ load("Strawberry.DisplayRaw");
+ console.clear();
+ let horizontal = Math.round(process.stdout.columns / 2 - (1 + (name.length / 2)));
+ process.stdout.write(color.bgBlue.white(" ".repeat(horizontal) + name + " ".repeat(process.stdout.columns - horizontal - name.length)));
+
+ global._STRAWBERRY_INIT_APP();
+ global._STRAWBERRY_CURRENT_APP = app;
+ require(app + "/Main.js")();
+ },
+
+ Quit: () => {
+ Strawberry.Tick.Events = [];
+ Strawberry.ProcessKeyboard = false;
+
+ load("Strawberry.DisplayRaw");
+ console.clear();
+ process.stdout.write(color.bgBlue.white(" ".repeat(process.stdout.columns)));
+
+ Object.keys(require.cache).map((i) => {
+ let ji = 0;
+ require.cache[i].children.map((j) => {
+ if (require.cache[i].children[ji] !== undefined) {
+ let ki = 0;
+ require.cache[i].children[ji].children.map((k) => {
+ if (j.id.startsWith(global._STRAWBERRY_CURRENT_APP)) {
+ delete require.cache[i].children[j].children[ki];
+ }
+
+ ki++;
+ })
+ }
+
+ if (j.id.startsWith(global._STRAWBERRY_CURRENT_APP)) {
+ delete require.cache[i].children[ji];
+ }
+
+ ji++;
+ })
+
+ if (i.startsWith(global._STRAWBERRY_CURRENT_APP)) {
+ delete require.cache[i];
+ }
+ })
+
+ global._STRAWBERRY_CURRENT_APP = null;
+ global._STRAWBERRY_INIT_APP();
+ global._STRAWBERRY_SYSTEMSOFTWARE_INIT();
+ }
+} \ No newline at end of file
diff --git a/Library/SDK/Modules/Strawberry.Audio.js b/Library/SDK/Modules/Strawberry.Audio.js
new file mode 100644
index 0000000..0b177a5
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.Audio.js
@@ -0,0 +1,7 @@
+const child_process = require('child_process');
+
+module.exports = {
+ SystemSound: (file) => {
+ child_process.exec((require('os').platform() === "darwin" ? "afplay" : "aplay") + " \"" + global._STRAWBERRY_SYSTEM_ROOT + "/Sounds/" + file + ".wav\"", () => {});
+ }
+} \ No newline at end of file
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
diff --git a/Library/SDK/Modules/Strawberry.Display.js b/Library/SDK/Modules/Strawberry.Display.js
new file mode 100644
index 0000000..847c658
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.Display.js
@@ -0,0 +1,14 @@
+module.exports = {
+ Write: (text, posX, posY) => {
+ if (posX > process.stdout.columns - 2) posX = process.stdout.columns - 2;
+ if (posY > process.stdout.rows - 2) posY = process.stdout.rows - 2;
+
+ if (Strawberry.MultiPanes) {
+ if (posX > process.stdout.columns - 52) posX = process.stdout.columns - 52;
+ process.stdout.cursorTo(posX + 54, posY + 4);
+ } else {
+ process.stdout.cursorTo(posX + 3, posY + 4);
+ }
+ process.stdout.write(color.black.bgWhite(text));
+ }
+} \ No newline at end of file
diff --git a/Library/SDK/Modules/Strawberry.DisplayRaw.js b/Library/SDK/Modules/Strawberry.DisplayRaw.js
new file mode 100644
index 0000000..5dd6860
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.DisplayRaw.js
@@ -0,0 +1,10 @@
+module.exports = {
+ Write: (text, posX, posY) => {
+ process.stdout.cursorTo(posX, posY);
+ process.stdout.write(text);
+ },
+ ClearLine: (posY) => {
+ process.stdout.cursorTo(0, posY);
+ process.stdout.clearLine();
+ }
+} \ No newline at end of file
diff --git a/Library/SDK/Modules/Strawberry.MenuBar.js b/Library/SDK/Modules/Strawberry.MenuBar.js
new file mode 100644
index 0000000..957dcf1
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.MenuBar.js
@@ -0,0 +1,143 @@
+// noinspection JSValidateTypes,JSUnresolvedVariable
+
+process.stdout.cursorTo(0, 0);
+
+let name;
+let menus = "";
+let menusText = "";
+
+self = {
+ Initialize: () => {
+ menus = "";
+ menusText = "";
+
+ if (Strawberry.System) {
+ name = color.bgCyan.black(" " + Strawberry.App + " ")
+ } else {
+ name = color.bgGreen.black(" " + Strawberry.App + " ")
+ }
+
+ for (let item of Strawberry.Menus) {
+ menus += color.bgBlue(" " + color.bgWhite.black(" " + item + " "));
+ menusText += " " + item + " ";
+ }
+
+ if (!Strawberry.Tick.Events.includes(self.UpdateClock)) {
+ Strawberry.Tick.Events.push(self.UpdateClock)
+ }
+ },
+ Reset: () => {
+ process.stdout.cursorTo(0, 0);
+ process.stdout.write(color.reset(color.bgBlue(" " + color.black.bgYellowBright(" O ") + " " + menus + " ".repeat(process.stdout.columns - (15 + Strawberry.App.length + menusText.length)) + new Date().toTimeString().substring(0, 5) + " " + name + " ")))
+ process.stdout.cursorTo(0, process.stdout.rows);
+ },
+ Active: (item) => {
+ let a = Strawberry.Menus.filter((_, i) => {
+ return i < item;
+ }).map((e) => {
+ return e.length + 3;
+ });
+
+ let b;
+ if (a.length === 0) {
+ b = 0
+ } else {
+ b = a.reduce((a, b) => {
+ return a + b;
+ })
+ }
+
+ process.stdout.cursorTo(6 + b, 0);
+ process.stdout.write(color.bgGray.white(" " + Strawberry.Menus[item] + " "));
+ },
+ Inactive: (item) => {
+ let a = Strawberry.Menus.filter((_, i) => {
+ return i < item;
+ }).map((e) => {
+ return e.length + 3;
+ });
+
+ let b;
+ if (a.length === 0) {
+ b = 0
+ } else {
+ b = a.reduce((a, b) => {
+ return a + b;
+ })
+ }
+
+ process.stdout.cursorTo(6 + b, 0);
+ process.stdout.write(color.bgWhite.black(" " + Strawberry.Menus[item] + " "));
+ },
+ Blink: (item) => {
+ process.stdout.cursorTo(0, 0);
+ process.stdout.write(color.reset(color.bgBlue(" " + color.black.bgYellowBright(" O ") + " " + menus + " ".repeat(process.stdout.columns - (15 + Strawberry.App.length + menusText.length)) + new Date().toTimeString().substring(0, 5) + " " + name + " ")))
+ process.stdout.cursorTo(0, process.stdout.rows);
+ setTimeout(() => {
+ self.Active(item);
+ setTimeout(() => {
+ self.Inactive(item);
+ setTimeout(() => {
+ self.Active(item);
+ setTimeout(() => {
+ self.Inactive(item);
+ setTimeout(() => {
+ self.Active(item);
+ setTimeout(() => {
+ self.Inactive(item);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ },
+
+ BlinkAndQuit: () => {
+ load("Strawberry.AppManager");
+ setTimeout(() => {
+ self.QuitActive();
+ setTimeout(() => {
+ self.QuitInactive();
+ setTimeout(() => {
+ self.QuitActive();
+ setTimeout(() => {
+ self.QuitInactive();
+ setTimeout(() => {
+ self.QuitActive();
+ setTimeout(() => {
+ self.QuitInactive();
+ setTimeout(() => {
+ Strawberry.AppManager.Quit();
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ }, 30);
+ },
+
+ QuitActive: () => {
+ process.stdout.cursorTo(1, 0);
+ process.stdout.write(chalk.bgYellow.black(" O "));
+ },
+
+ QuitInactive: () => {
+ process.stdout.cursorTo(1, 0);
+ process.stdout.write(chalk.bgYellowBright.black(" O "));
+ },
+
+ UpdateClock: () => {
+ process.stdout.cursorTo(process.stdout.columns - (10 + Strawberry.App.length), 0);
+ process.stdout.write(color.bgBlue(new Date().toTimeString().substring(0, 5)));
+ process.stdout.cursorTo(0, process.stdout.rows);
+ }
+}
+
+self.Initialize();
+self.Reset();
+
+Strawberry.Tick.Events.push(self.UpdateClock)
+
+module.exports = self; \ No newline at end of file
diff --git a/Library/SDK/Modules/Strawberry.SystemInfo.js b/Library/SDK/Modules/Strawberry.SystemInfo.js
new file mode 100644
index 0000000..b52b1c2
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.SystemInfo.js
@@ -0,0 +1,204 @@
+const os = require('os');
+const fs = require('fs');
+
+module.exports = {
+ GetHardwareMemory: () => {
+ return {
+ Total: os.totalmem(),
+ Free: os.freemem(),
+ Used: os.totalmem() - os.freemem(),
+ }
+ },
+
+ GetProcessors: () => {
+ let cpus = os.cpus();
+ return {
+ Count: cpus.length,
+ Model: cpus.map((i) => {
+ return i.model;
+ })
+ }
+ },
+
+ Version: () => {
+ return fs.readFileSync(_STRAWBERRY_SYSTEM_ROOT + "/Version").toString().trim().split("\n")[1].trim();
+ },
+
+ Processes: () => {
+ let list = [];
+
+ let p = Object.keys(require.cache).map((i) => {
+ let cid = -1;
+ return { name: i, children: [
+ ...(require.cache[i].children.map((j) => {
+ cid++;
+
+ if (require.cache[i].children[cid] === undefined) {
+ return { name: j.id, children: [] }
+ } else {
+ return { name: j.id, children: [
+ ...(require.cache[i].children[cid].children.map((k) => {
+ return { name: k.id, children: null }
+ }))
+ ]
+ }
+ }
+ }))
+ ] }
+ });
+
+ list.push("0000: " + chalk.magenta("strawberry-boot") + (global._STRAWBERRY_EMULATED ? chalk.gray(" (emulated)") : ""));
+
+ let index = 0;
+ let pid = 1;
+ for (let proc of p) {
+ if (proc === undefined) continue;
+
+ if (proc['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ proc['name'] = "/System" + proc['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (proc['name'].startsWith("/Strawberry")) {
+ proc['name'] = proc['name'].substring(11);
+ }
+ if (proc['name'].startsWith("/System/Library/SDK/")) {
+ proc['name'] = chalk.yellow(proc['name']);
+ }
+ if (proc['name'].startsWith("/System/StrawKit/")) {
+ proc['name'] = chalk.red(proc['name']);
+ }
+ if (proc['name'].startsWith("/System/Applications/")) {
+ proc['name'] = chalk.green(proc['name']);
+ }
+ if (!proc['name'].startsWith("/System")) {
+ proc['name'] = chalk.cyan(proc['name']);
+ }
+
+ let s = pid.toString();
+ let k = s;
+
+ if (s.length > 3) {
+ k = s;
+ } else if (s.length > 2) {
+ k = "0" + s;
+ } else if (s.length > 1) {
+ k = "00" + s;
+ } else {
+ k = "000" + s;
+ }
+
+ let childPrefix = " ";
+ if (index >= p.length - 1) {
+ list.push(" ┗ " + k + ": " + proc['name']);
+ childPrefix = " ";
+ } else {
+ list.push(" ┣ " + k + ": " + proc['name']);
+ childPrefix = "┃";
+ }
+
+ if (proc['children'].length > 0) {
+ let cIndex = 0;
+
+ for (let child of proc['children']) {
+ if (child === undefined) continue;
+
+ if (child['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ child['name'] = "/System" + child['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (child['name'].startsWith("/Strawberry")) {
+ child['name'] = child['name'].substring(11);
+ }
+ if (child['name'].startsWith("/System/Library/SDK/")) {
+ child['name'] = chalk.yellow(child['name']);
+ }
+ if (!child['name'].startsWith("/System")) {
+ child['name'] = chalk.cyan(child['name']);
+ }
+ if (child['name'].startsWith("/System/StrawKit/")) {
+ child['name'] = chalk.red(child['name']);
+ }
+ if (child['name'].startsWith("/System/Applications/")) {
+ child['name'] = chalk.green(child['name']);
+ }
+
+ pid++;
+ let o = pid.toString();
+ let j = o;
+
+ if (o.length > 3) {
+ j = o;
+ } else if (o.length > 2) {
+ j = "0" + o;
+ } else if (o.length > 1) {
+ j = "00" + o;
+ } else {
+ j = "000" + o;
+ }
+
+ let childChildPrefix = " ";
+ if (cIndex >= proc['children'].length - 1) {
+ childChildPrefix = " ";
+ list.push(" " + childPrefix + " ┗ " + j + ": " + child['name']);
+ } else {
+ childChildPrefix = "┃";
+ list.push(" " + childPrefix + " ┣ " + j + ": " + child['name']);
+ }
+
+ cIndex++;
+
+ if (child['children'].length > 0) {
+ let cIndex = 0;
+
+ for (let child2 of child['children']) {
+ if (child2 === undefined) continue;
+
+ if (child2['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ child2['name'] = "/System" + child2['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (child2['name'].startsWith("/Strawberry")) {
+ child2['name'] = child2['name'].substring(11);
+ }
+ if (child2['name'].startsWith("/System/Library/SDK/")) {
+ child2['name'] = chalk.yellow(child2['name']);
+ }
+ if (!child2['name'].startsWith("/System")) {
+ child2['name'] = chalk.cyan(child2['name']);
+ }
+ if (child2['name'].startsWith("/System/StrawKit/")) {
+ child2['name'] = chalk.red(child2['name']);
+ }
+ if (child2['name'].startsWith("/System/Applications/")) {
+ child2['name'] = chalk.green(child2['name']);
+ }
+
+ pid++;
+ let o = pid.toString();
+ let j = o;
+
+ if (o.length > 3) {
+ j = o;
+ } else if (o.length > 2) {
+ j = "0" + o;
+ } else if (o.length > 1) {
+ j = "00" + o;
+ } else {
+ j = "000" + o;
+ }
+
+ if (cIndex >= child['children'].length - 1) {
+ list.push(" " + childPrefix + " " + childChildPrefix + " ┗ " + j + ": " + child2['name']);
+ } else {
+ list.push(" " + childPrefix + " " + childChildPrefix + " ┣ " + j + ": " + child2['name']);
+ }
+
+ cIndex++;
+ }
+ }
+ }
+ }
+
+ pid++; index++;
+ }
+
+ return list;
+ }
+} \ No newline at end of file