diff --git a/src/interfaces/Index.java b/src/interfaces/Index.java new file mode 100644 index 0000000..c679da6 --- /dev/null +++ b/src/interfaces/Index.java @@ -0,0 +1,44 @@ +package interfaces; + +import quick.Action; +import quick.View; +import quick.Color; + +public class Index extends View { + private boolean yes = false; + + public Boolean init() { + return true; + } + + public void draw() { + terminal.print(Color.ANSI_CYAN + "Index View" + Color.ANSI_RESET); + terminal.print("\n"); + terminal.print("This is the index view. Use commands to navigate.\n"); + terminal.print("\n"); + terminal.print("Available commands:\n"); + terminal.print(" - test: go test view\n"); + terminal.print(" - confirm: confirm\n"); + + if (yes) { + terminal.print(Color.ANSI_GREEN + "You have confirmed yes!" + Color.ANSI_RESET + "\n"); + } else { + terminal.print(Color.ANSI_YELLOW + "You have not confirmed yes." + Color.ANSI_RESET + "\n"); + } + } + + public Action onCommand(String command) { + if (command.equals("confirm")) { + yes = true; + } + if (command.equals("test")) { + return actions.redirect(Login.class); + } + + return actions.nop(); + } + + public Boolean onSelection(String userInputRaw) { + return false; + } +} diff --git a/src/interfaces/Login.java b/src/interfaces/Login.java new file mode 100644 index 0000000..312e1d1 --- /dev/null +++ b/src/interfaces/Login.java @@ -0,0 +1,114 @@ +package interfaces; + +import quick.Action; +import quick.View; +import quick.Color; + +public class Login extends View { + private String username = ""; + private String password = ""; + private boolean loginSuccess = false; + private int loginTries = 0; + private String editField = null; + private String error = ""; + + @Override + public Boolean init() { + username = ""; + password = ""; + loginSuccess = false; + loginTries = 0; + editField = null; + error = ""; + viewPrompt = "> "; + return true; + } + + @Override + public void draw() { + terminal.print(Color.ANSI_CYAN + "=== Login ===" + Color.ANSI_RESET + "\n"); + + terminal.print("Username: " + (username.isEmpty() ? "" : username) + "\n"); + terminal.print("Password: " + (password.isEmpty() ? "" : "*".repeat(password.length())) + "\n"); + + if (loginSuccess) { + terminal.print(Color.ANSI_GREEN + "Login successful!" + Color.ANSI_RESET + "\n"); + terminal.print("Press any key to continue..." + "\n"); + viewPrompt = "> "; + return; + } + + if (!error.isEmpty()) { + terminal.print(Color.ANSI_RED + error + Color.ANSI_RESET + "\n"); + } + + terminal.print("\nCommands:\n"); + terminal.print(" edit username - enter username\n"); + terminal.print(" edit password - enter password\n"); + terminal.print(" login - attempt login\n"); + terminal.print(" back - go back\n"); + + if (editField != null) { + viewPrompt = "Enter " + editField + ": "; + } else { + viewPrompt = "> "; + } + } + + @Override + public Action onCommand(String command) { + String cmd = command.trim().toLowerCase(); + + if (cmd.isEmpty()) { + error = "Empty input. Type a command."; + return actions.nop(); + } + + if (cmd.equals("back")) { + return actions.redirect(Index.class); + } + + if (cmd.equals("login")) { + if (username.equals("a") && password.equals("a")) { + loginSuccess = true; + error = ""; + } else { + loginTries++; + error = "Login failed (" + loginTries + " attempts)."; + } + return actions.nop(); + } + + if (cmd.startsWith("edit")) { + if (cmd.contains("username")) { + editField = "username"; + error = ""; + } else if (cmd.contains("password")) { + editField = "password"; + error = ""; + } else { + error = "Unknown field to edit. Use: edit username | edit password"; + } + return actions.nop(); + } + + if (editField != null) { + if (editField.equals("username")) { + username = command.trim(); + } else if (editField.equals("password")) { + password = command.trim(); + } + editField = null; + error = ""; + return actions.nop(); + } + + error = "Unknown command: " + command; + return actions.nop(); + } + + @Override + public Boolean onSelection(String userInputRaw) { + return false; + } +}