diff --git a/miss.yarn b/miss.yarn index f5e021d..4ca0b6a 100644 --- a/miss.yarn +++ b/miss.yarn @@ -1 +1 @@ -{"protected":false,"mode":"f","metadata":{"name":"miss","author":"Luna Magdalena :3","version":[1],"dependencies":[],"paths":{"miss.js":"%B/miss.js"}},"content":"{\"miss.js\":{\"protected\":true,\"metadata\":{\"runner\":[]},\"mode\":\"f\",\"content\":\" // check if there is a config file\\nlet config = {}\\n\\nif (fs.getNode(fs.resolve(itty.env.dir_conf || \\\"/conf/\\\") + \\\"miss.conf\\\")) {\\n try {\\n const configFile = io.open(fs.resolve(itty.env.dir_conf || \\\"/conf/\\\") + \\\"miss.conf\\\")\\n config = configFile.read()\\n config = JSON.parse(config)\\n } catch (e) {\\n io.error([1, \\\"Error parsing config\\\"])\\n config = {}\\n }\\n}\\n\\nlet history = []\\nlet historyIndex = 0\\n\\nfunction onInput(key) {\\n switch (key) {\\n case \\\"%^\\\":\\n historyIndex = Math.max(historyIndex - 1, 0)\\n if (history[historyIndex]) {\\n program.read.input = history[historyIndex]\\n program.read.cursor = program.read.input.length\\n }\\n break\\n case \\\"%v\\\":\\n historyIndex = Math.min(historyIndex + 1, history.length)\\n if (history[historyIndex]) {\\n program.read.input = history[historyIndex]\\n program.read.cursor = program.read.input.length\\n } else if (historyIndex === history.length) {\\n program.read.input = \\\"\\\"\\n program.read.cursor = 0\\n }\\n break\\n }\\n}\\n\\nlet running = false\\n// this runs on every new line\\nasync function line() {\\n // promt! %D gets replaced by the active dir\\n const prompt = config.prompt || [[\\\"%D\\\", 0xc000], [\\\" > \\\", 0xd000]]\\n\\n for (let p of prompt)\\n p[0] = p[0].replace(/%D/g, program.currentDir)\\n\\n // parse arguments\\n let command = await io.read(prompt)\\n if (command !== \\\"\\\" && command !== history[history.length - 1]) {\\n history.push(command)\\n historyIndex = history.length\\n }\\n command = command.replace(/%%/g, \\\"%\\\")\\n let args = command.match(/\\\"([^\\\"%]*(%.[^\\\"%]*)*)\\\"|'([^'%]*(%.[^'%]*)*)'|\\\\S+/g)\\n\\n if (args) {\\n for (let i=0; i < args.length; i++) {\\n args[i] = args[i].replace(/^'(.*)'$|^\\\"(.*)\\\"$/, \\\"$1$2\\\")\\n args[i] = args[i].replace(/%(['\\\"])/g, \\\"$1\\\")\\n }\\n\\n // split into multiple commands\\n const commands = []\\n let redir\\n let c = []\\n for (let a of args) {\\n if (a !== \\\"|\\\") {\\n c.push(a)\\n } else {\\n commands.push(c.slice())\\n c = []\\n }\\n }\\n commands.push(c)\\n\\n let redirIndex = commands[commands.length - 1].indexOf(\\\">\\\")\\n if (redirIndex !== -1) {\\n redir = commands[commands.length - 1][redirIndex + 1]\\n commands[commands.length - 1] = commands[commands.length - 1].slice(0, redirIndex)\\n }\\n\\n running = true\\n let output = \\\"\\\"\\n for (let c = 0; c < commands.length; c++) {\\n const hidden = (c < commands.length - 1 || redir ? true : false)\\n output = await run(commands[c], output, hidden)\\n }\\n \\n if (redir) {\\n let file\\n try {\\n file = io.open(redir, \\\"a\\\")\\n } catch (e) {\\n display.print(\\\"Cannot open file\\\", 0x9000) \\n }\\n if (file) {\\n file.write(output)\\n try {\\n file.writeOut()\\n } catch (e) {\\n display.print(\\\"Cannot open file\\\", 0x9000) \\n }\\n }\\n }\\n\\n running = false\\n \\n if (itty.cursorX !== 0)\\n itty.cursorY++\\n\\n line()\\n } else {\\n line()\\n }\\n}\\n\\n// attempt to run autorun functions!\\nif (program.uid === 0) {\\n for (let a of [\\\"/autorun\\\", \\\"/autorun.js\\\", \\\"/.autorun\\\", \\\"/.autorun.js\\\"]) {\\n try {\\n exec.runProgram(a, [], \\\"\\\", false)\\n } catch {}\\n }\\n}\\n\\nline()\\n\\nasync function run(arg, input, hidden) {\\n const program = arg[0]\\n if (arg.length > 1)\\n arg.splice(0, 1)\\n else\\n arg = []\\n let file = null\\n\\n switch (program) {\\n // built in \\\"programs\\\"\\n case \\\"cd\\\":\\n try {\\n fs.changeDir(arg[0] || itty.env.home)\\n } catch (e) {\\n display.print(\\\"Not a directory\\\")\\n }\\n break\\n case \\\"exit\\\":\\n quit()\\n display.print(\\\"Cannot quit init process\\\", 0xf000)\\n return\\n break\\n // otherwise, call\\n default:\\n let output\\n try {\\n output = await exec.runProgram(program, arg, input, hidden)\\n } catch (e) {\\n if (e[0] !== 0) {\\n if (e[0] === -1 && e[1] === \\\"Cannot find program file\\\") {\\n display.print(`${program}: command not found.`, 0x2000)\\n return\\n } else\\n display.print(\\\"Error running program\\\", 0x9000)\\n }\\n }\\n\\n return output\\n }\\n}\\n\\nfunction onReturn() {\\n if (running)\\n return\\n\\n program.visible = true\\n program.focused = true\\n historyIndex = history.length\\n if (itty.cursorX !== 0)\\n itty.cursorY++\\n onError()\\n}\\n\\nfunction onError() {\\n if (program.visible) {\\n for (let e of io.getErrors()) {\\n display.write(`[${e[0]}] `, 0x9010)\\n display.print(e[1] || \\\"\\\")\\n }\\n }\\n}\\n\\nfunction onResize() {\\n if (program.focused) {\\n program.read.line = 0\\n display.clear()\\n }\\n}\"}}"} \ No newline at end of file +{"protected":false,"mode":"f","metadata":{"name":"miss","author":"Luna Magdalena :3","version":[1,1],"dependencies":[],"paths":{"miss.js":"%B/miss.js","miss":"%D/miss"}},"content":"{\"miss.js\":{\"protected\":true,\"metadata\":{\"runner\":[]},\"mode\":\"f\",\"content\":\" // check if there is a config file\\nlet config = {}\\n\\nif (fs.getNode(fs.resolve(itty.env.dir_conf || \\\"/conf/\\\") + \\\"miss.conf\\\")) {\\n try {\\n const configFile = io.open(fs.resolve(itty.env.dir_conf || \\\"/conf/\\\") + \\\"miss.conf\\\")\\n config = configFile.read()\\n config = JSON.parse(config)\\n } catch (e) {\\n io.error([1, \\\"Error parsing config\\\"])\\n config = {}\\n }\\n}\\n\\n// promt! %D gets replaced by the active dir\\nconst prompt = config.prompt || [[\\\"%D\\\", 0xc000], [\\\" > \\\", 0xd000]]\\n\\nlet history = []\\nlet historyIndex = 0\\n\\nfunction onInput(key) {\\n switch (key) {\\n case \\\"%^\\\":\\n historyIndex = Math.max(historyIndex - 1, 0)\\n if (history[historyIndex]) {\\n program.read.input = history[historyIndex]\\n program.read.cursor = program.read.input.length\\n }\\n break\\n case \\\"%v\\\":\\n historyIndex = Math.min(historyIndex + 1, history.length)\\n if (history[historyIndex]) {\\n program.read.input = history[historyIndex]\\n program.read.cursor = program.read.input.length\\n } else if (historyIndex === history.length) {\\n program.read.input = \\\"\\\"\\n program.read.cursor = 0\\n }\\n break\\n }\\n}\\n\\nlet running = false\\n// this runs on every new line\\nasync function line() {\\n itty.baseStyle = config.style || 0x7000 \\n\\n for (let p of prompt)\\n p[0] = p[0].replace(/%D/g, program.currentDir)\\n\\n // parse arguments\\n let command = await io.read(prompt)\\n if (command !== \\\"\\\" && command !== history[history.length - 1]) {\\n history.push(command)\\n historyIndex = history.length\\n }\\n\\n let args = command.match(/\\\"([^\\\"\\\\\\\\]*(\\\\\\\\.[^\\\"\\\\\\\\]*)*)\\\"|'([^'\\\\\\\\]*(\\\\\\\\.[^'\\\\\\\\]*)*)'|\\\\S+/g)\\n\\n if (args) {\\n for (let i=0; i < args.length; i++) {\\n args[i] = args[i].replace(/\\\\\\\\\\\\\\\\/g, \\\"\\\\x14b\\\")\\n args[i] = args[i].replace(/^'(.*)'$|^\\\"(.*)\\\"$/, \\\"$1$2\\\")\\n args[i] = args[i].replace(/\\\\\\\\(['\\\"])/g, \\\"$1\\\")\\n }\\n\\n // split into multiple commands\\n const commands = []\\n let redir\\n let c = []\\n for (let a of args) {\\n if (a !== \\\"|\\\") {\\n c.push(a)\\n } else {\\n commands.push(c.slice())\\n c = []\\n }\\n }\\n commands.push(c)\\n\\n let redirIndex = commands[commands.length - 1].indexOf(\\\">\\\")\\n if (redirIndex !== -1) {\\n redir = commands[commands.length - 1][redirIndex + 1]\\n commands[commands.length - 1] = commands[commands.length - 1].slice(0, redirIndex)\\n }\\n\\n running = true\\n let output = \\\"\\\"\\n for (let c = 0; c < commands.length; c++) {\\n const hidden = (c < commands.length - 1 || redir ? true : false)\\n output = await run(commands[c], output, hidden)\\n }\\n \\n if (redir) {\\n let file\\n redir = redir.replace(/\\\\x14b/g, \\\"\\\\\\\\\\\")\\n try {\\n file = io.open(redir, \\\"a\\\")\\n } catch (e) {\\n display.print(\\\"Cannot open file\\\", 0x9000) \\n }\\n if (file) {\\n file.write(output)\\n try {\\n file.writeOut()\\n } catch (e) {\\n display.print(\\\"Cannot open file\\\", 0x9000) \\n }\\n }\\n }\\n\\n running = false\\n \\n if (itty.cursorX !== 0)\\n itty.cursorY++\\n\\n line()\\n } else {\\n line()\\n }\\n}\\n\\n// attempt to run autorun functions!\\nif (program.uid === 0) {\\n for (let a of [\\\"/autorun\\\", \\\"/autorun.js\\\", \\\"/.autorun\\\", \\\"/.autorun.js\\\"]) {\\n try {\\n exec.runProgram(a, [], \\\"\\\", false)\\n } catch {}\\n }\\n}\\n\\nline()\\n\\nasync function run(arg, input, hidden) {\\n const program = arg[0]\\n if (arg.length > 1)\\n arg.splice(0, 1)\\n else\\n arg = []\\n let file = null\\n\\n // do a bit of cleanup on the args\\n for (let i = 0; i < arg.length; i++) {\\n arg[i] = arg[i].replace(/\\\\\\\\([|>])/g, \\\"$1\\\")\\n arg[i] = arg[i].replace(/\\\\x14b/g, \\\"\\\\\\\\\\\")\\n }\\n\\n switch (program) {\\n // built in \\\"programs\\\"\\n case \\\"cd\\\":\\n try {\\n fs.changeDir(arg[0] || itty.env.home)\\n } catch (e) {\\n display.print(\\\"Not a directory\\\")\\n }\\n break\\n case \\\"exit\\\":\\n quit()\\n display.print(\\\"Cannot quit init process\\\", 0xf000)\\n return\\n break\\n // otherwise, call\\n default:\\n let output\\n try {\\n output = await exec.runProgram(program, arg, input, hidden)\\n } catch (e) {\\n if (e[0] !== 0) {\\n if (e[0] === -1 && e[1] === \\\"Cannot find program file\\\") {\\n display.print(`${program}: command not found.`, 0x2000)\\n return\\n } else\\n display.print(\\\"Error running program\\\", 0x9000)\\n }\\n }\\n\\n return output\\n }\\n}\\n\\nfunction onReturn() {\\n if (running)\\n return\\n\\n program.visible = true\\n program.focused = true\\n historyIndex = history.length\\n if (itty.cursorX !== 0)\\n itty.cursorY++\\n onError()\\n}\\n\\nfunction onError() {\\n if (program.visible) {\\n for (let e of io.getErrors()) {\\n display.write(`[${e[0]}] `, 0x9010)\\n display.print(e[1] || \\\"\\\")\\n }\\n }\\n}\"},\"miss\":{\"protected\":false,\"metadata\":{},\"mode\":\"f\",\"content\":\"\\u0011[sD050]MISS - Magdalena's Init and Simple Shell\\u0011[s7000]\\n\\nmiss is a simple shell and init system for itty\\n\\n\\u0011[s5040]Usage\\u0011[s7000]\\n\\tmiss\\n\\n\\u0011[s5040]Binds\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s6020]Arrow up\\u0011[s7000]: move up in command history\\n\\u0011[sC000]- \\u0011[s6020]Arrow down\\u0011[s7000]: move down in command history\\n\\u0011[sC000]- \\u0011[s6020]Enter\\u0011[s7000]: input command\\n\\u0011[sC000]- \\u0011[s6020]Control + v\\u0011[s7000]: paste from clipboard\\n\\n\\u0011[s5040]Prompt\\u0011[s7000]\\nthe prompt will separate arguments by spaces, unless they are surrounded by single (\\u0011[sA000]'\\u0011[s7000]) or double (\\u0011[sA000]\\\"\\u0011[s7000]) quotes\\n\\nby using the \\u0011[sA000]|\\u0011[s7000] character, you can send one program's output to a different program. the \\u0011[sA000]>\\u0011[s7000] sign will instead redirect the program's output to a file\\n\\na backslash (\\u0011[sA000]\\\\\\u0011[s7000]) can be used to escape special characters\\n\\n\\u0011[s5040]Environment\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s6020]dir_conf\\u0011[s7000] (\\u0011[sE000]string\\u0011[s7000]): the config directory that miss will look for a config file in\\n\\n\\u0011[s5040]Configuration\\u0011[s7000]\\nmiss will read configuration from a \\u0011[s2040]miss.conf\\u0011[s7000] file located in the config directory. this file must be valid JSON\\n\\nthe file contains the following values:\\n\\n\\u0011[sC000]- \\u0011[s6020]prompt\\u0011[s7000]: the prompt to start every line with. it is an array, whose elements are arrays containing a string and itty style info. the \\u0011[sA000]%D\\u0011[s7000] string will be replaced by the current working directory\\n\\u0011[sC000]- \\u0011[s6020]style\\u0011[s7000]: the default itty style to use for text\\n\\n\\u0011[s5040]Files\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s2040]miss.conf\\u0011[s7000]: must be in the config directory. miss will read this file for configuration\\n\\non startup, before the first prompt, miss will attempt to execute the following files:\\n\\u0011[sC000]- \\u0011[s2040]/autorun\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s2040]/autorun.js\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s2040]/.autorun\\u0011[s7000]\\n\\u0011[sC000]- \\u0011[s2040]/.autorun.js\\u0011[s7000]\"}}"} \ No newline at end of file