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

[T4A3][T11-A1]FENYI YE #1093

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions src/seedu/addressbook/ui/ShowMessageManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.addressbook.ui;

import static seedu.addressbook.common.Messages.MESSAGE_GOODBYE;
import static seedu.addressbook.common.Messages.MESSAGE_INIT_FAILED;
import static seedu.addressbook.common.Messages.MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE;
import static seedu.addressbook.common.Messages.MESSAGE_USING_STORAGE_FILE;
import static seedu.addressbook.common.Messages.MESSAGE_WELCOME;

import java.io.PrintStream;

public class ShowMessageManager {
private final PrintStream out;
private static final String LINE_PREFIX = "|| ";
private static final String LS = System.lineSeparator();
private static final String DIVIDER = "===================================================";

public ShowMessageManager(PrintStream out){
this.out = out;
}
public void showToUser(String... message) {
for (String m : message) {
out.println(LINE_PREFIX + m.replace("\n", LS + LINE_PREFIX));
}
}

public void showWelcomeMessage(String version, String storageFilePath) {
String storageFileInfo = String.format(MESSAGE_USING_STORAGE_FILE, storageFilePath);
showToUser(
DIVIDER,
DIVIDER,
MESSAGE_WELCOME,
version,
MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE,
storageFileInfo,
DIVIDER);
}

public void showGoodbyeMessage() {
showToUser(MESSAGE_GOODBYE, DIVIDER, DIVIDER);
}


public void showInitFailedMessage() {
showToUser(MESSAGE_INIT_FAILED, DIVIDER, DIVIDER);
}

}
35 changes: 15 additions & 20 deletions src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.addressbook.commands.CommandResult;
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.ui.ShowMessageManager;

import java.io.InputStream;
import java.io.PrintStream;
Expand All @@ -27,6 +28,8 @@ public class TextUi {

/** Format of indexed list item */
private static final String MESSAGE_INDEXED_LIST_ITEM = "\t%1$d. %2$s";

private ShowMessageManager smm;


/** Offset required to convert between 1-indexing and 0-indexing. */
Expand All @@ -40,6 +43,7 @@ public class TextUi {

public TextUi() {
this(System.in, System.out);
smm = new ShowMessageManager(this.out);
}

public TextUi(InputStream in, PrintStream out) {
Expand Down Expand Up @@ -83,38 +87,29 @@ public String getUserCommand() {
fullInputLine = in.nextLine();
}

showToUser("[Command entered:" + fullInputLine + "]");
smm.showToUser("[Command entered:" + fullInputLine + "]");
return fullInputLine;
}


public void showWelcomeMessage(String version, String storageFilePath) {
String storageFileInfo = String.format(MESSAGE_USING_STORAGE_FILE, storageFilePath);
showToUser(
DIVIDER,
DIVIDER,
MESSAGE_WELCOME,
version,
MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE,
storageFileInfo,
DIVIDER);
smm.showWelcomeMessage(version, storageFilePath);
}

public void showGoodbyeMessage() {
showToUser(MESSAGE_GOODBYE, DIVIDER, DIVIDER);
smm.showToUser(MESSAGE_GOODBYE, DIVIDER, DIVIDER);
}


public void showInitFailedMessage() {
showToUser(MESSAGE_INIT_FAILED, DIVIDER, DIVIDER);
smm.showToUser(MESSAGE_INIT_FAILED, DIVIDER, DIVIDER);
}


/** Shows message(s) to the user */
public void showToUser(String... message) {
for (String m : message) {
out.println(LINE_PREFIX + m.replace("\n", LS + LINE_PREFIX));
}
}
/** Shows message(s) to the user */
public void showToUser(String... message) {
smm.showToUser(message);
}

/**
* Shows the result of a command execution to the user. Includes additional formatting to demarcate different
Expand All @@ -125,7 +120,7 @@ public void showResultToUser(CommandResult result) {
if (resultPersons.isPresent()) {
showPersonListView(resultPersons.get());
}
showToUser(result.feedbackToUser, DIVIDER);
smm.showToUser(result.feedbackToUser, DIVIDER);
}

/**
Expand All @@ -142,7 +137,7 @@ private void showPersonListView(List<? extends ReadOnlyPerson> persons) {

/** Shows a list of strings to the user, formatted as an indexed list. */
private void showToUserAsIndexedList(List<String> list) {
showToUser(getIndexedListForViewing(list));
smm.showToUser(getIndexedListForViewing(list));
}

/** Formats a list of strings as a viewable indexed list. */
Expand Down