main.js 1.8 KB

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