main.js 2.5 KB

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