forked from nus-cs2113-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
TextUi.java
86 lines (71 loc) · 2.27 KB
/
TextUi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package seedu.smarthomebot.ui;
import seedu.smarthomebot.logic.commands.CommandResult;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
import static seedu.smarthomebot.commons.Messages.DIVIDER;
import static seedu.smarthomebot.commons.Messages.LINE;
import static seedu.smarthomebot.commons.Messages.MESSAGE_EXPORT;
import static seedu.smarthomebot.commons.Messages.MESSAGE_GOODBYE;
import static seedu.smarthomebot.commons.Messages.MESSAGE_WELCOME;
//@@author Ang-Cheng-Jun
//Solution below adapted from https://github.com/nus-cs2113-AY2021S1/personbook
/**
* Text UI of the application.
*/
public class TextUi {
private static final String ENTER_COMMAND = "Enter command: ";
private final Scanner in;
private final PrintStream out;
public TextUi() {
this(System.in, System.out);
}
public TextUi(InputStream in, PrintStream out) {
this.in = new Scanner(System.in);
this.out = out;
}
/**
* Prints message(s) to the user.
*/
public void printToUser(String message) {
assert !message.isEmpty() : "Message must not be empty";
out.println(message);
}
/**
* Prints result(s) of the command to the user.
*/
public void printResultToUser(CommandResult result) {
assert !result.feedbackToUser.isEmpty() : "The feedback for result cannot be empty";
printToUser(LINE + result.feedbackToUser);
}
/**
* Prints a divider.
*/
private void printDivider() {
printToUser(DIVIDER);
}
/**
* Prompts for the command and reads the text entered by the user.
* @return command (full line) entered by the user.
*/
public String getUserCommand() {
printDivider();
out.print(ENTER_COMMAND);
String fullInputLine = in.nextLine();
return fullInputLine.trim();
}
/**
* Generates and prints the Welcome message upon the end of the application.
*/
public void showWelcomeMessage() {
printDivider();
printToUser(MESSAGE_WELCOME);
}
/**
* Generates and prints the Goodbye message upon the end of the application.
*/
public void showGoodByeMessage() {
printToUser(MESSAGE_EXPORT);
printToUser(MESSAGE_GOODBYE);
}
}