Skip to content

Commit

Permalink
Fix CLI, but for real this time
Browse files Browse the repository at this point in the history
I think
Closes #12
  • Loading branch information
skycatminepokie committed Dec 21, 2024
1 parent 0adbc32 commit cddca70
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
67 changes: 34 additions & 33 deletions src/main/java/com/skycatdev/binarysearchtool/CliUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

Expand Down Expand Up @@ -94,38 +95,6 @@ public void onBisectFinished() {
showBisectMenu();
}

private void showBisectMenu() {
asyncDisplayOption("", "Is the problem fixed?", MessageType.NONE, new Option[]{
new Option("Yes", this::success),
new Option("No", this::failure),
new Option("List", () -> {
showLists();
showBisectMenu();
})
});
}

private void showLists() {
if (getSearchHandler() == null) {
asyncDisplayOption("", "SearchHandler was null when trying to display lists. Please report this.", MessageType.ERROR, new Option[]{new Option("OK", null)});
return;
}
System.out.println("Might be the problem:");
for (Mod mod : getSearchHandler().getCandidateMods()){
System.out.println(mod.name());
}
System.out.println();
System.out.println("Not the problem:");
for (Mod mod: getSearchHandler().getWorkingMods()) {
System.out.println(mod.name());
}
System.out.println();
System.out.println("Mods we're testing now:");
for (Mod mod : getSearchHandler().getTestingMods()) {
System.out.println(mod.name());
}
}

@Override
public void onFinished(ArrayList<Mod> problematicMods) {
assert searchHandler != null : "searchHandler should be the one calling, why is it null?";
Expand Down Expand Up @@ -170,6 +139,38 @@ public void sendNextStepInstructions() {
sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). Then respond to the prompt.");
}

private void showBisectMenu() {
asyncDisplayOption("", "Is the problem fixed?", MessageType.NONE, new Option[]{
new Option("Yes", this::success),
new Option("No", this::failure),
new Option("List", () -> {
showLists();
showBisectMenu();
})
});
}

private void showLists() {
if (getSearchHandler() == null) {
asyncDisplayOption("", "SearchHandler was null when trying to display lists. Please report this.", MessageType.ERROR, new Option[]{new Option("OK", null)});
return;
}
System.out.println("Might be the problem:");
for (Mod mod : getSearchHandler().getCandidateMods()) {
System.out.println(mod.name());
}
System.out.println();
System.out.println("Not the problem:");
for (Mod mod : getSearchHandler().getWorkingMods()) {
System.out.println(mod.name());
}
System.out.println();
System.out.println("Mods we're testing now:");
for (Mod mod : getSearchHandler().getTestingMods()) {
System.out.println(mod.name());
}
}

@Override
public void start() {
System.out.println("Starting, please wait...");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ public void bisect(boolean lastSuccessful) {
// Ready for next step
if (candidateMods.size() == 1) {
iterations++;
enableAll(mods);
finished = true;
ui.updateLists(candidateMods, workingMods);
ui.updateProgress(iterations, maxIterations);
ui.onFinished(candidateMods);
enableAll(mods);
return;
} else {
if (candidateMods.isEmpty()) {
Expand Down Expand Up @@ -259,11 +259,11 @@ private void disableAll(ArrayList<Mod> mods) {

private void disableMod(Mod mod) {
assert modsPath != null;
if (!mod.tryDisable(modsPath)) {
while (!mod.tryDisable(modsPath)) {
try {
ui.asyncDisplayOption("Disable failed", "Couldn't disable \"%s\". Make sure Minecraft is closed.".formatted(mod.name()), MessageType.WARNING, new Option[]{
new Option("Abort", this::onFatalError),
new Option("Try again", () -> disableMod(mod))
new Option("Try again", null)
}).get();
} catch (ExecutionException | InterruptedException e) {
ui.asyncDisplayOption("Uh-oh", "Failed to disable gracefully", MessageType.ERROR, new Option[]{new Option("OK, cya", this::onFatalError)});
Expand Down Expand Up @@ -329,11 +329,11 @@ private void enableAll(ArrayList<Mod> mods) {

private void enableMod(Mod mod) {
assert modsPath != null;
if (!mod.tryEnable(modsPath)) {
while (!mod.tryEnable(modsPath)) {
try {
ui.asyncDisplayOption("Enable failed", "Couldn't enable \"%s\". Make sure Minecraft is closed.".formatted(mod.name()), MessageType.WARNING, new Option[]{
new Option("Abort", this::onFatalError),
new Option("Try again", () -> enableMod(mod))
new Option("Try again", null)
}).get();
} catch (ExecutionException | InterruptedException e) {
ui.asyncDisplayOption("Uh-oh", "Failed to enable gracefully", MessageType.ERROR, new Option[]{new Option("OK, cya", this::onFatalError)});
Expand Down

0 comments on commit cddca70

Please sign in to comment.