1
0

main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2024-present Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. "use strict";
  20. import('./js/InstanceManager.mjs').then(module => {
  21. const InstanceManager = module.default;
  22. process.stdin.setRawMode(true);
  23. process.stdin.resume();
  24. process.stdin.setEncoding("utf8");
  25. console.log("Now booting, please stand by ...");
  26. const manager = new InstanceManager({ screen: false, term: false, spawnRoot: undefined });
  27. manager.getInstanceByinstName("Host").then(result => {
  28. const hostvm = result.vm;
  29. hostvm.add_listener("emulator-started", () => {
  30. process.stdout.write("Welcome to psl!");
  31. hostvm.serial0_send("\n");
  32. });
  33. hostvm.add_listener("serial0-output-byte", (byte) => {
  34. var chr = String.fromCharCode(byte);
  35. if (chr <= "~") {
  36. process.stdout.write(chr);
  37. }
  38. });
  39. process.stdin.on("data", (c) => {
  40. if (c === "\u0004") {
  41. hostvm.stop();
  42. process.stdin.pause();
  43. }
  44. else {
  45. hostvm.serial0_send(c);
  46. }
  47. });
  48. }).catch(error => {
  49. console.error(error);
  50. throw Error("Error in getting host inastance, quitting");
  51. });
  52. }).catch(error => {
  53. console.error('Error loading InstanceManager:', error);
  54. });