1
0
forked from osmarks/potatOS
potatOS/copy-cat/resources-e74d4ac3.js

13 lines
829 KiB
JavaScript
Raw Permalink Normal View History

2023-11-12 14:57:16 +00:00
/**
* copy-cat: Copyright SquidDev 2023
*
* - @squid-dev/cc-web-term: Copyright SquidDev (BSD-3-Clause)
* - jszip: Copyright Stuart Knightley ((MIT OR GPL-3.0-or-later))
* - preact: Copyright (MIT)
* - setimmediate: Copyright YuzuJS (MIT)
* - style-inject: Copyright EGOIST (MIT)
* - tslib: Copyright Microsoft Corp. (0BSD)
*
* @license
*/define(["exports"],function(e){"use strict";e.resources={"bios.lua":'-- SPDX-FileCopyrightText: 2017 Daniel Ratcliffe\n--\n-- SPDX-License-Identifier: LicenseRef-CCPL\n\n-- Load in expect from the module path.\n--\n-- Ideally we\'d use require, but that is part of the shell, and so is not\n-- available to the BIOS or any APIs. All APIs load this using dofile, but that\n-- has not been defined at this point.\nlocal expect\n\ndo\n local h = fs.open("rom/modules/main/cc/expect.lua", "r")\n local f, err = loadstring(h.readAll(), "@/rom/modules/main/cc/expect.lua")\n h.close()\n\n if not f then error(err) end\n expect = f().expect\nend\n\nif _VERSION == "Lua 5.1" then\n -- If we\'re on Lua 5.1, install parts of the Lua 5.2/5.3 API so that programs can be written against it\n local nativeload = load\n\n function load(x, name, mode, env)\n expect(1, x, "function", "string")\n expect(2, name, "string", "nil")\n expect(3, mode, "string", "nil")\n expect(4, env, "table", "nil")\n\n local ok, p1, p2 = pcall(function()\n local result, err = nativeload(x, name, mode, env)\n if result and env then\n env._ENV = env\n end\n return result, err\n end)\n if ok then\n return p1, p2\n else\n error(p1, 2)\n end\n end\n\n loadstring = function(string, chunkname) return nativeload(string, chunkname) end\nend\n\n-- Inject a stub for the old bit library\n_G.bit = {\n bnot = bit32.bnot,\n band = bit32.band,\n bor = bit32.bor,\n bxor = bit32.bxor,\n brshift = bit32.arshift,\n blshift = bit32.lshift,\n blogic_rshift = bit32.rshift,\n}\n\n-- Install lua parts of the os api\nfunction os.version()\n return "CraftOS 1.8"\nend\n\nfunction os.pullEventRaw(sFilter)\n return coroutine.yield(sFilter)\nend\n\nfunction os.pullEvent(sFilter)\n local eventData = table.pack(os.pullEventRaw(sFilter))\n if eventData[1] == "terminate" then\n error("Terminated", 0)\n end\n return table.unpack(eventData, 1, eventData.n)\nend\n\n-- Install globals\nfunction sleep(nTime)\n expect(1, nTime, "number", "nil")\n local timer = os.startTimer(nTime or 0)\n repeat\n local _, param = os.pullEvent("timer")\n until param == timer\nend\n\nfunction write(sText)\n expect(1, sText, "string", "number")\n\n local w, h = term.getSize()\n local x, y = term.getCursorPos()\n\n local nLinesPrinted = 0\n local function newLine()\n if y + 1 <= h then\n term.setCursorPos(1, y + 1)\n else\n term.setCursorPos(1, h)\n term.scroll(1)\n end\n x, y = term.getCursorPos()\n nLinesPrinted = nLinesPrinted + 1\n end\n\n -- Print the line with proper word wrapping\n sText = tostring(sText)\n while #sText > 0 do\n local whitespace = string.match(sText, "^[ \\t]+")\n if whitespace then\n -- Print whitespace\n term.write(whitespace)\n x, y = term.getCursorPos()\n sText = string.sub(sText, #whitespace + 1)\n end\n\n local newline = string.match(sText, "^\\n")\n if newline then\n -- Print newlines\n newLine()\n sText = string.sub(sText, 2)\n end\n\n local text = string.match(sText, "^[^ \\t\\n]+")\n if text then\n sText = string.sub(sText, #text + 1)\n if #text > w then\n -- Print a multiline word\n while #text > 0 do\n if x > w then\n newLine()\n end\n term.write(text)\n text = string.sub(text, w - x + 2)\n x, y = term.getCursorPos()\n end\n else\n -- Print a word normally\n if x + #text - 1 > w then\n newLine()\n end\n term.write(text)\n x, y = term.getCursorPos(