Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
menu: final
Browse files Browse the repository at this point in the history
  • Loading branch information
algorov committed Aug 16, 2023
1 parent 63daf8a commit 1233c5e
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/main/java/org/semul/budny/menu/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

public class Menu extends Thread {
public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Menu.class);
private Budny app;
private BufferedReader reader;
private final Budny app;
private final BufferedReader reader;
private boolean flag;

public static Menu getInstance(Budny app) {
public static void getInstance(Budny app) {
Menu menu = new Menu(app);
menu.start();
ThreadsController.pool.add(menu);

return menu;
}

public Menu(Budny app) {
Expand All @@ -34,16 +32,21 @@ public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
printMenu();
System.out.print(">>> ");

switch (reader.readLine()) {
case "1" -> {
if (!flag) {
addAccount();
} else {
quit();
}
}
case "2" -> {
if (!flag) {
quit();
}
}
case "2" -> quit();
}

}
} catch (IOException ex) {
throw new RuntimeException(ex);
Expand All @@ -53,7 +56,7 @@ public void run() {
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println(Thread.currentThread().getName() + " is interrupted!");

Thread.currentThread().interrupt();
}

Expand All @@ -65,37 +68,45 @@ public void run() {
}

private void greetings() {
System.out.println("HI!");
System.out.println("▬▬▬▬▬▬ WELCOME! ▬▬▬▬▬▬");
}

private void printMenu() {
System.out.println("Список команд:");
System.out.println("\nCommand List:");
System.out.print("[1] ");
if (!flag) {
System.out.println("1 - начать");
System.out.println("- sign in.");
} else {
System.out.println("- exit.");
}

System.out.println("2 - выйти");
if (!flag) {
System.out.println("[2] - exit.");
}

System.out.print("\n[●] -> ");
}

private void addAccount() {
try {
logger.info("Input data.");
System.out.print("Enter the login >>> ");
logger.info("Input data");

System.out.print("\n▬ Enter the login [●] -> ");
String login = this.reader.readLine();
System.out.print("Enter the password >>> ");
System.out.print("Enter the password [●] -> ");
String password = this.reader.readLine();
this.app.signIn(login, password);
System.out.println();

this.app.signIn(login, password);
this.flag = true;
System.out.println("Всё начнется или нет");
} catch (IOException e) {
logger.error(e);
throw new RuntimeException(e);
}
}

private void quit() throws InterruptedException {
System.out.println("Bye");
logger.info("Exit");
this.app.complete();
throw new InterruptedException();
}
Expand Down

0 comments on commit 1233c5e

Please sign in to comment.