A fake command line interface written in p5.js and Processing 3 https://www.victorgiers.com/cwi
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.

virtualCommandline.pde 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. CommandLine commandLine;
  2. void setup() {
  3. size (800, 420);
  4. commandLine = new CommandLine();
  5. }
  6. int pfc;
  7. void draw() {
  8. background(0);
  9. fill(#FFFFFF);
  10. stroke(#FFFFFF);
  11. commandLine.update();
  12. commandLine.display();
  13. }
  14. class CommandLine {
  15. String userInput = "";
  16. String inputString;
  17. String[] presentedLines;
  18. String[] possibleCommands = { "asd" };
  19. int idleFrameCount;
  20. boolean busy;
  21. CommandLine() {
  22. presentedLines = new String[30];
  23. for (int i = 0; i < presentedLines.length; i++) {
  24. presentedLines[i] = "";
  25. }
  26. }
  27. void getUserInput(int code, char c) {
  28. println(code, c);
  29. if (!busy) {
  30. if (code != 8 && code != 10 && code != 16 && code != 17 && code != 18 && code != 20)
  31. userInput = userInput + c;
  32. if (code == 8 && userInput.length() > 0) { //backspace
  33. userInput = userInput.substring(0, userInput.length()-1);
  34. } else if (code == 10) { //enter
  35. enterInput();
  36. userInput = "";
  37. }
  38. }
  39. }
  40. void pushLineString(String bottomLine) {
  41. println("bottomline " + bottomLine);
  42. for (int i = presentedLines.length-1; i > 0; i--) {
  43. presentedLines[i] = presentedLines[i-1];
  44. }
  45. presentedLines[0] = bottomLine;
  46. }
  47. void enterInput() { //user Input DEFINE COMMANDS HERE THAT ARE DETECTED
  48. if (userInput.equals("asd")) {
  49. goOutside();
  50. } else {
  51. pushLineString(inputString);
  52. }
  53. }
  54. void update() {
  55. if (!busy) {
  56. inputString = "guest@iris ~ $ " + userInput;
  57. presentedLines[0] = inputString;
  58. } else {
  59. if (idleFrameCount + pfc < frameCount) {
  60. busy = false;
  61. }
  62. }
  63. }
  64. void display() {
  65. for (int i = 0; i < presentedLines.length; i++) {
  66. text(presentedLines[i], 13, height-25-(i*13));
  67. }
  68. }
  69. }
  70. void goOutside() {
  71. commandLine.busy = true;
  72. pfc = frameCount;
  73. // String[] stringList = {"Processing",};
  74. // l("processing user data...", 10);
  75. // pfc = frameCount;
  76. // pushLineString(input);
  77. // idleFrameCount += f;
  78. }
  79. void keyPressed() {
  80. //println(keyCode + " " + key);
  81. commandLine.getUserInput(keyCode, key);
  82. }