Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. const ESC = '\x1B';
  3. const CSI = `${ESC}[`;
  4. const beep = '\u0007';
  5. const cursor = {
  6. to(x, y) {
  7. if (!y) return `${CSI}${x + 1}G`;
  8. return `${CSI}${y + 1};${x + 1}H`;
  9. },
  10. move(x, y) {
  11. let ret = '';
  12. if (x < 0) ret += `${CSI}${-x}D`;
  13. else if (x > 0) ret += `${CSI}${x}C`;
  14. if (y < 0) ret += `${CSI}${-y}A`;
  15. else if (y > 0) ret += `${CSI}${y}B`;
  16. return ret;
  17. },
  18. up: (count = 1) => `${CSI}${count}A`,
  19. down: (count = 1) => `${CSI}${count}B`,
  20. forward: (count = 1) => `${CSI}${count}C`,
  21. backward: (count = 1) => `${CSI}${count}D`,
  22. nextLine: (count = 1) => `${CSI}E`.repeat(count),
  23. prevLine: (count = 1) => `${CSI}F`.repeat(count),
  24. left: `${CSI}G`,
  25. hide: `${CSI}?25l`,
  26. show: `${CSI}?25h`,
  27. save: `${ESC}7`,
  28. restore: `${ESC}8`
  29. }
  30. const scroll = {
  31. up: (count = 1) => `${CSI}S`.repeat(count),
  32. down: (count = 1) => `${CSI}T`.repeat(count)
  33. }
  34. const erase = {
  35. screen: `${CSI}2J`,
  36. up: (count = 1) => `${CSI}1J`.repeat(count),
  37. down: (count = 1) => `${CSI}J`.repeat(count),
  38. line: `${CSI}2K`,
  39. lineEnd: `${CSI}K`,
  40. lineStart: `${CSI}1K`,
  41. lines(count) {
  42. let clear = '';
  43. for (let i = 0; i < count; i++)
  44. clear += this.line + (i < count - 1 ? cursor.up() : '');
  45. if (count)
  46. clear += cursor.left;
  47. return clear;
  48. }
  49. }
  50. module.exports = { cursor, scroll, erase, beep };