initial commit
This commit is contained in:
87
processing3/virtualCommandline/virtualCommandline.pde
Normal file
87
processing3/virtualCommandline/virtualCommandline.pde
Normal file
@@ -0,0 +1,87 @@
|
||||
CommandLine commandLine;
|
||||
void setup() {
|
||||
size (800, 420);
|
||||
commandLine = new CommandLine();
|
||||
}
|
||||
int pfc;
|
||||
void draw() {
|
||||
background(0);
|
||||
fill(#FFFFFF);
|
||||
stroke(#FFFFFF);
|
||||
commandLine.update();
|
||||
commandLine.display();
|
||||
}
|
||||
|
||||
class CommandLine {
|
||||
String userInput = "";
|
||||
String inputString;
|
||||
String[] presentedLines;
|
||||
String[] possibleCommands = { "asd" };
|
||||
int idleFrameCount;
|
||||
boolean busy;
|
||||
CommandLine() {
|
||||
presentedLines = new String[30];
|
||||
for (int i = 0; i < presentedLines.length; i++) {
|
||||
presentedLines[i] = "";
|
||||
}
|
||||
}
|
||||
void getUserInput(int code, char c) {
|
||||
println(code, c);
|
||||
if (!busy) {
|
||||
if (code != 8 && code != 10 && code != 16 && code != 17 && code != 18 && code != 20)
|
||||
userInput = userInput + c;
|
||||
if (code == 8 && userInput.length() > 0) { //backspace
|
||||
userInput = userInput.substring(0, userInput.length()-1);
|
||||
} else if (code == 10) { //enter
|
||||
enterInput();
|
||||
userInput = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
void pushLineString(String bottomLine) {
|
||||
println("bottomline " + bottomLine);
|
||||
for (int i = presentedLines.length-1; i > 0; i--) {
|
||||
presentedLines[i] = presentedLines[i-1];
|
||||
}
|
||||
presentedLines[0] = bottomLine;
|
||||
}
|
||||
void enterInput() { //user Input DEFINE COMMANDS HERE THAT ARE DETECTED
|
||||
if (userInput.equals("asd")) {
|
||||
goOutside();
|
||||
} else {
|
||||
pushLineString(inputString);
|
||||
}
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (!busy) {
|
||||
inputString = "guest@iris ~ $ " + userInput;
|
||||
presentedLines[0] = inputString;
|
||||
} else {
|
||||
if (idleFrameCount + pfc < frameCount) {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
void display() {
|
||||
for (int i = 0; i < presentedLines.length; i++) {
|
||||
text(presentedLines[i], 13, height-25-(i*13));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void goOutside() {
|
||||
commandLine.busy = true;
|
||||
pfc = frameCount;
|
||||
// String[] stringList = {"Processing",};
|
||||
// l("processing user data...", 10);
|
||||
// pfc = frameCount;
|
||||
// pushLineString(input);
|
||||
// idleFrameCount += f;
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
//println(keyCode + " " + key);
|
||||
commandLine.getUserInput(keyCode, key);
|
||||
}
|
||||
Reference in New Issue
Block a user