// noinspection JSUnresolvedVariable process.title = "-strawberry"; global.fs = require('fs'); global.color = require('chalk'); console.clear(); process.stdin.setRawMode(true); const readline = require('readline'); readline.emitKeypressEvents(process.stdin); Launcher = require("../Launcher"); process.stdin.on('keypress', (str, key) => { for (let func of Strawberry.KeyboardEvents) { func(key.sequence); } if (key.sequence === '\u0003') { require('show-terminal-cursor')(); process.exit(); } if (!Strawberry.ProcessKeyboard) return; if (!global._STRAWBERRY_APPMENU_OPEN) { try { Strawberry.MenuBar.Reset(); } catch (e) {} } else { if (key.sequence === "\x1B[A") { Launcher.GoUp(); } if (key.sequence === "\x1B[B") { Launcher.GoDown(); } if (key.sequence === "\r") { Launcher.Open(); } } process.stdout.cursorTo(0, process.stdout.rows - 1); process.stdout.clearLine(); process.stdout.write("0x" + Buffer.from(key.sequence).toString("hex").toUpperCase()); if (key.sequence === "\x1B[P") { throw new Error("User pressed interrupt button"); } if ((key.sequence === '\x1BOP' || key.sequence === "\x1B[[A") && !global._STRAWBERRY_APPMENU_OPEN) { process.stdout.cursorTo(1, 0); process.stdout.write(color.bgYellow.blue(" O ")); Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); if (Strawberry.System) { global._STRAWBERRY_APPMENU_OPEN = true; Launcher.Init(); Launcher.Spawn(); return; } else { load("Strawberry.AppManager"); Strawberry.MenuBar.BlinkAndQuit(); } } if ((key.sequence === '\x1B' && global._STRAWBERRY_APPMENU_OPEN) || ((key.sequence === '\x1BOP' || key.sequence === "\x1B[[A") && global._STRAWBERRY_APPMENU_OPEN)) { Strawberry.Audio.SystemSound("Strawberry.Menu.Close"); global._STRAWBERRY_APPMENU_OPEN = false; console.clear(); Strawberry.WhenLoaded(); Strawberry.MenuBar.Reset(); } if (key.sequence === '\x1BOQ' || key.sequence === "\x1B[[B") { if (Strawberry.Menus.length > 0) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(0); setTimeout(() => { if (Strawberry.MenuAction[0]) { Strawberry.MenuBar.Blink(0); Strawberry.MenuAction[0](); } else { Strawberry.MenuBar.Blink(0); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1BOR' || key.sequence === "\x1B[[C") { if (Strawberry.Menus.length > 1) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(1); setTimeout(() => { if (Strawberry.MenuAction[1]) { Strawberry.MenuBar.Blink(1); Strawberry.MenuAction[1](); } else { Strawberry.MenuBar.Blink(1); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1BOS' || key.sequence === "\x1B[[D") { if (Strawberry.Menus.length > 2) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(2); setTimeout(() => { if (Strawberry.MenuAction[2]) { Strawberry.MenuBar.Blink(2); Strawberry.MenuAction[2](); } else { Strawberry.MenuBar.Blink(2); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[15~' || key.sequence === "\x1B[[E") { if (Strawberry.Menus.length > 3) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(3); setTimeout(() => { if (Strawberry.MenuAction[3]) { Strawberry.MenuBar.Blink(3); Strawberry.MenuAction[3](); } else { Strawberry.MenuBar.Blink(3); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[16~') { if (Strawberry.Menus.length > 4) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(4); setTimeout(() => { if (Strawberry.MenuAction[4]) { Strawberry.MenuBar.Blink(4); Strawberry.MenuAction[4](); } else { Strawberry.MenuBar.Blink(4); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[17~') { if (Strawberry.Menus.length > 5) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(5); setTimeout(() => { if (Strawberry.MenuAction[5]) { Strawberry.MenuBar.Blink(5); Strawberry.MenuAction[5](); } else { Strawberry.MenuBar.Blink(5); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[18~') { if (Strawberry.Menus.length > 6) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(6); setTimeout(() => { if (Strawberry.MenuAction[6]) { Strawberry.MenuBar.Blink(6); Strawberry.MenuAction[6](); } else { Strawberry.MenuBar.Blink(6); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[19~') { if (Strawberry.Menus.length > 7) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(7); setTimeout(() => { if (Strawberry.MenuAction[7]) { Strawberry.MenuBar.Blink(7); Strawberry.MenuAction[7](); } else { Strawberry.MenuBar.Blink(7); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[20~') { if (Strawberry.Menus.length > 8) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(8); setTimeout(() => { if (Strawberry.MenuAction[8]) { Strawberry.MenuBar.Blink(8); Strawberry.MenuAction[8](); } else { Strawberry.MenuBar.Blink(8); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[21~') { if (Strawberry.Menus.length > 9) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(9); setTimeout(() => { if (Strawberry.MenuAction[9]) { Strawberry.MenuBar.Blink(9); Strawberry.MenuAction[9](); } else { Strawberry.MenuBar.Blink(9); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[23~') { if (Strawberry.Menus.length > 10) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(10); setTimeout(() => { if (Strawberry.MenuAction[10]) { Strawberry.MenuBar.Blink(10); Strawberry.MenuAction[10](); } else { Strawberry.MenuBar.Blink(10); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[24~') { if (Strawberry.Menus.length > 10) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(11); setTimeout(() => { if (Strawberry.MenuAction[11]) { Strawberry.MenuBar.Blink(11); Strawberry.MenuAction[11](); } else { Strawberry.MenuBar.Blink(11); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); return; } } if (key.sequence === '\x1B[24~') { if (Strawberry.Menus.length > 10) { Strawberry.Audio.SystemSound("Strawberry.Menu.Open"); Strawberry.MenuBar.Active(12); setTimeout(() => { if (Strawberry.MenuAction[12]) { Strawberry.MenuBar.Blink(12); Strawberry.MenuAction[12](); } else { Strawberry.MenuBar.Blink(12); } }, 75) } else { Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid"); } } if (key.sequence === "\x1B\x1B[B") { if (Strawberry.CurrentPane + 1 < Strawberry.Panes.length) { Strawberry.CurrentPane++; } else { Strawberry.CurrentPane = 0; } Strawberry.UpdatePanes(); } if (key.sequence === "\x1B\x1B[A") { if (Strawberry.CurrentPane > 0) { Strawberry.CurrentPane--; } else { Strawberry.CurrentPane = Strawberry.Panes.length - 1; } Strawberry.UpdatePanes(); } }) global._STRAWBERRY_INIT_APP = () => { global.Strawberry = { App: "Strawberry", MultiPanes: false, System: false, Window: true, Menus: [], Panes: [], CurrentPane: 0, MenuAction: [], KeyboardEvents: [], Tick: { Events: [], Timer: setInterval(() => { for (let i in Strawberry.Tick.Events) { Strawberry.Tick.Events[i](); } }) }, UpdatePanes: () => { let line = 8; let index = 0; for (let pane of Strawberry.Panes) { let name = pane.name; process.stdout.cursorTo(3, line); if (index === Strawberry.CurrentPane) { process.stdout.write(chalk.bgBlue.white(" " + name + " ".repeat(44 - name.length))); } else { if (index === Strawberry.CurrentPane + 1) { process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 9) + chalk.blue("Opt+Down") + " ")); } else if (index === Strawberry.CurrentPane - 1) { process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 7) + chalk.blue("Opt+Up") + " ")); } else if (Strawberry.CurrentPane === 0 && index === Strawberry.Panes.length - 1) { process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 7) + chalk.blue("Opt+Up") + " ")); } else if (Strawberry.CurrentPane === Strawberry.Panes.length - 1 && index === 0) { process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 9) + chalk.blue("Opt+Down") + " ")); } else { process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length))); } } line++; index++; } for (let i = 3; i < process.stdout.rows - 1; i++) { process.stdout.cursorTo(52, i); process.stdout.write(chalk.bgWhite.black(" ".repeat(process.stdout.columns - 53))); Strawberry.Panes[Strawberry.CurrentPane].load(); } }, ProcessKeyboard: true, WhenLoaded: () => {}, StartLoad: (skipCoolLoading) => { load("Strawberry.Audio"); if (!skipCoolLoading) skipCoolLoading = false; console.clear(); if (Strawberry.System) { let horizontal = Math.round(process.stdout.columns / 2 - (1 + (Strawberry.App.length / 2))); process.stdout.write(color.bgBlue.white(" ".repeat(horizontal + Strawberry.App.length) + " ".repeat(process.stdout.columns - horizontal - Strawberry.App.length))); } else { let horizontal = Math.round(process.stdout.columns / 2 - (1 + (Strawberry.App.length / 2))); process.stdout.write(color.bgBlue.white(" ".repeat(horizontal) + Strawberry.App + " ".repeat(process.stdout.columns - horizontal - Strawberry.App.length))); } setTimeout(() => { if (Strawberry.System && !skipCoolLoading) { Strawberry.Audio.SystemSound("Strawberry.System.Login"); } Strawberry.ProcessKeyboard = true; if (!Strawberry.System && Strawberry.Window) { process.stdout.cursorTo(0, 2); process.stdout.write(chalk.bgWhite.blue("┏" + "━".repeat(process.stdout.columns - 2) + "┓")) for (let i = 3; i < process.stdout.rows - 1; i++) { process.stdout.cursorTo(0, i); process.stdout.write(chalk.bgWhite.blue("┃" + " ".repeat(process.stdout.columns - 2) + "┃")) } process.stdout.cursorTo(0, process.stdout.rows); process.stdout.write(chalk.bgWhite.blue("┗" + "━".repeat(process.stdout.columns - 2) + "┛")) Strawberry.Audio.SystemSound("Strawberry.System.Window"); } if (Strawberry.MultiPanes) { process.stdout.cursorTo(0, 2); process.stdout.write(chalk.bgWhite.blue("┏" + "━".repeat(50) + "┳" + "━".repeat(process.stdout.columns - 53) + "┓")) for (let i = 3; i < process.stdout.rows - 1; i++) { process.stdout.cursorTo(0, i); process.stdout.write(chalk.bgWhite.blue("┃" + " ".repeat(50) + "┃" + " ".repeat(process.stdout.columns - 53) + "┃")) } process.stdout.cursorTo(0, process.stdout.rows); process.stdout.write(chalk.bgWhite.blue("┗" + "━".repeat(50) + "┻" + "━".repeat(process.stdout.columns - 53) + "┛")) process.stdout.cursorTo(0, 6); process.stdout.write(chalk.bgWhite.blue("┣" + "━".repeat(50) + "┫")) process.stdout.cursorTo(0, 4); process.stdout.write(chalk.bgWhite.blue("┃") + chalk.bgWhite.black(" ".repeat((50 - Strawberry.App.length) / 2) + Strawberry.App)) } Strawberry.WhenLoaded(); if (Strawberry.MultiPanes) { Strawberry.UpdatePanes(); } try { Strawberry.MenuBar.Initialize(); Strawberry.MenuBar.Reset(); } catch (e) {} }, (skipCoolLoading ? 500 : 2000)) } } } global._STRAWBERRY_INIT_APP(); global.load = (module) => { if (module.includes("/")) throw new Error("Invalid module: " + module); if (!fs.existsSync(__dirname + "/Modules/" + module + ".js")) throw new Error("Invalid module: " + module); let parts = module.split("."); if (parts.length > 2) { Strawberry[parts[1]] = {}; Strawberry[parts[1]][parts[2]] = require("./Modules/" + module); } else if (parts.length > 3) { Strawberry[parts[1]][parts[2]] = {}; Strawberry[parts[1]][parts[2]][parts[3]] = require("./Modules/" + module); } else { Strawberry[parts[1]] = require("./Modules/" + module); } if (module === "Strawberry.Menubar") { load("Strawberry.MenuBar"); } }