Skip to content

Commit

Permalink
Document everything
Browse files Browse the repository at this point in the history
And I mean everything
(Also, updates to todo.txt, README.md and mode.properties)
  • Loading branch information
joelmoniz committed Jul 14, 2015
1 parent b520de2 commit 81e9423
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To build REPL Mode from source (recommended), do the following:
* `processing.modes` : Represents the path to the folder where the mode is to be installed (usually the `modes` folder inside the sketchbook)
* `processing.executable` : Represents the path to the processing executable

2. In the command prompt or terminal, simply run `ant full` from the resources directory (where the build.xml and build.properties files are present).
2. In the command prompt or terminal, simply run `ant run` from the resources directory (where the build.xml and build.properties files are present).

Using the hot-swapper
---------------------
Expand Down
8 changes: 4 additions & 4 deletions resources/mode.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name = REPL Mode
authors = [Joel Moniz](http://joelmoniz.com)
url = https://github.com/joelmoniz/REPLmode
sentence = Adds an REPL Console to view the output of code typed into it immediately.
paragraph = This mode adds in a Read-Evaluate-Print-Loop console to processing in the form of a tab at the bottom. The console enables users to type in processing code and to view the output of this code immediately. Each subsequent line of code shows the output incrementally, much like how an REPL Console for any interpretive language (like Python, and the Linux bash terminal) would. The console also provides options to undo commands, to convert the valid commands entered so far into a function, and so on.
version = 1
prettyVersion = 0.2a
sentence = Adds an REPL Console to view the output of code typed into it immediately. Also gives the PDE the ability to hot swap code.
paragraph = This mode adds in a Read-Evaluate-Print-Loop console to processing in the form of a tab at the bottom. The console enables users to type in processing code and to view the output of this code immediately. Each subsequent line of code shows the output incrementally, much like how an REPL Console for any interpretive language (like Python, and the Linux bash terminal) would. The console also provides options to undo commands, to convert the valid commands entered so far into a function, and so on. Ths mode also gives the PDE the ability to hot swap code, wherein the output corresponding to changes made in a running sketch can be viewed by simply saving the sketch, without restarting it.
version = 3
prettyVersion = 1.3a
imports = processing.mode.java.JavaMode
#minRevision = 0238
69 changes: 60 additions & 9 deletions src/jm/mode/replmode/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/**
* Class to store the list of commands that the user has entered so far.
*
* @author Joel
*
* @author Joel Moniz
*/
public class CommandHistory {

Expand All @@ -17,8 +16,10 @@ public class CommandHistory {
int currentCycleCommand;

/**
* Store the line number of the previous <b>clear</b> command entered by the
* user.
* Store the line number of the previous <code>clear</code> command entered by
* the user.
* @deprecated This variable is no longer needed,
* but is kept for old time's sake.
*/
int previousClearLine;

Expand All @@ -42,59 +43,109 @@ public CommandHistory() {
commandHistList = new ArrayList<>();
}

/**
* Returns the previous command. Remembers where the user is in the
* cycling process.
* @param currCommand What the user typed in just before cycling
* @return The previous command in the cycling process
*/
public String getPreviousCommand(String currCommand) {
currentCycleCommand--;

/*
* either there is nothing to cycle through, or the user has reached the
* very first command, or the user has just begun cycling
*/
if (currentCycleCommand < 0) {
if (commandHistList.size() == 0) {
/* no commands to cycle through */
currentCycleCommand = UNDEFINED_COMMAND_STEP;
return "";
} else if (currentCycleCommand == UNDEFINED_COMMAND_STEP - 1) {
/*
* this happens the first time the user tries to access a previous
* command- at the start of the cycling process
*/
currentCycleCommand = commandHistList.size() - 1;
this.currentCommand = currCommand;
return commandHistList.get(currentCycleCommand);
} else {
// avoid multiple up-arrow pressing after reaching
// top of list from causing problems
/*
* avoid multiple up-arrow pressing after reaching top of list from
* causing problems
*/
currentCycleCommand = 0;
return commandHistList.get(0);
}
} else {
if (currentCycleCommand == commandHistList.size() - 1) {
/*
* done so that when the user modifies something, and decides that
* (s)he wants to cycle again, the modifications aren't lost
*/
this.currentCommand = currCommand;
}
return commandHistList.get(currentCycleCommand);
}
}

/**
* Returns the next command. Remembers where the user is in the
* cycling process.
* @param currCommand What the user typed in just before cycling
* @return The next command in the cycling process
*/
public String getNextCommand(String currCommand) {
currentCycleCommand++;
/*
* when crossing the last command in history
*/
if (currentCycleCommand >= commandHistList.size()) {
if (commandHistList.size() == 0) {
/* no commands entered yet */
currentCycleCommand = UNDEFINED_COMMAND_STEP;
return "";
} else {
if (currentCycleCommand > commandHistList.size()) {
/*
* done so that when the user modifies something, and presses the
* down arrow key, the modifications aren't lost
*/
this.currentCommand = currCommand;
}
// avoid multiple down-arrow pressing after reaching
// bottom of list from causing problems
/*
* avoid multiple down-arrow pressing after reaching bottom of list from
* causing problems
*/
currentCycleCommand = commandHistList.size();
return currentCommand;
}
} else if (currentCycleCommand == 0) { // first step of cycle, non-empty list
} else if (currentCycleCommand == 0) {
/* first step of cycle, non-empty list */
this.currentCommand = currCommand;
currentCycleCommand = commandHistList.size();
return currCommand;
} else {
/* cycling somewhere in the middle of command history */
return commandHistList.get(currentCycleCommand);
}
}

/**
* Resets the cycling process, so that the previous command in the cycle will
* be the last command entered by the user.
*/
public void resetCommandCycle() {
currentCycleCommand = UNDEFINED_COMMAND_STEP;
currentCommand = "";
}

/**
* Inserts a command into the command history. To be called, for example, when
* the user hits the enter key.
*
* @param cmd The command/code to be inserted into the history
*/
public void insertCommand(String cmd) {
resetCommandCycle();

Expand Down
Loading

0 comments on commit 81e9423

Please sign in to comment.