Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds CommandClearCli which allows the User to clear the current CLI Display #280

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/executor/command/CommandClearCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package executor.command;

import storage.StorageManager;
import ui.UiCode;

public class CommandClearCli extends Command {

/**
* Constructor for CommandClearCli class.
*/
public CommandClearCli(String userInput) {
super();
this.userInput = userInput;
this.commandType = CommandType.CLEAR;
this.description = "Clears the current CLI window.";
}

@Override
public void execute(StorageManager storageManager) {
this.infoCapsule.setUiCode(UiCode.CLEAR_CLI);
this.infoCapsule.setOutputStr("Command Clear Executed.");
}
}
3 changes: 2 additions & 1 deletion src/main/java/executor/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public enum CommandType {
DIV(CommandDiv.class),
MUL(CommandMul.class),
TRACK(CommandTrackTag.class),
UNTRACK(CommandUntrackTag.class);
UNTRACK(CommandUntrackTag.class),
CLEAR(CommandClearCli.class);

private final Class commandClass;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ui/UiCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package ui;

public enum UiCode {
TOAST, CLI, UPDATE, ERROR, EXIT, DISPLAY_HOME, DISPLAY_CLI;
TOAST, CLI, UPDATE, ERROR, EXIT, DISPLAY_HOME, DISPLAY_CLI, CLEAR_CLI;
}
17 changes: 12 additions & 5 deletions src/main/java/ui/gui/CommandLineDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@ public class CommandLineDisplay {
@FXML
VBox container;

public static final String LINE = "________________________________________________";
private static final String LINE = "________________________________________________";

/**
* Prints string to CLI Display.
* @param outputStr String to be printed onto the display
*/
public void printToDisplay(String outputStr) {
void printToDisplay(String outputStr) {
Text newOutput = new Text(outputStr);
container.getChildren().add(newOutput);
}

public void setStyle() {
void setStyle() {
this.cliDisplay.vvalueProperty().bind(container.heightProperty());
}

/**
* Helper method to indicate duke is saying something.
* @param string The message duke wants to say
*/
public void dukeSays(String string) {
void dukeSays(String string) {
printToDisplay("Duke: " + string + "\n");
}

/**
* Helper method to print Line Separator.
*/
public void printSeparator() {
void printSeparator() {
this.printToDisplay(LINE);
}

/**
* Clears the current CLI display.
*/
void clearCliDisplay() {
this.container.getChildren().clear();
}
}
3 changes: 3 additions & 0 deletions src/main/java/ui/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private void updateGui(InfoCapsule infoCapsule) {
case DISPLAY_CLI:
this.showCliDisplay();
break;
case CLEAR_CLI:
this.cliController.clearCliDisplay();
break;
case UPDATE:
break;
default:
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/ui/CommandClearCliTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ui;

import executor.command.CommandClearCli;
import org.junit.jupiter.api.Test;
import storage.StorageManager;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class CommandClearCliTest {
@Test
void executeTest() {
StorageManager storageManager = new StorageManager();
CommandClearCli genericTest = new CommandClearCli("");
genericTest.execute(storageManager);
assertEquals(UiCode.CLEAR_CLI, genericTest.getInfoCapsule().getUiCode());
assertEquals("Command Clear Executed.", genericTest.getInfoCapsule().getOutputStr());
}
}