Skip to content

Commit

Permalink
CLI list
Browse files Browse the repository at this point in the history
  • Loading branch information
skycatminepokie committed Dec 20, 2024
1 parent d5703a4 commit 0adbc32
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 29 deletions.
88 changes: 59 additions & 29 deletions src/main/java/com/skycatdev/binarysearchtool/CliUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
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;

public class CliUi implements SearchUi {
protected final DialogHandler dialogHandler = new DialogHandler();
protected final Scanner scanner = new Scanner(System.in);
/**
* The SearchHandler this is linked to. Is null if none is linked.
*/
protected @Nullable SearchHandler searchHandler = null;
protected final Scanner scanner = new Scanner(System.in);

public CliUi() {
}
Expand Down Expand Up @@ -67,6 +66,10 @@ private void blockingDisplayOption(String text, Option[] options) {
}
}

private void displayStartMenu() {
asyncDisplayOption("", "Ready to start?", MessageType.NONE, new Option[]{new Option("start", this::start), new Option("advanced", this::openAdvancedOptions)});
}

@Override
public void failure() {
System.out.println("Working...");
Expand All @@ -86,8 +89,55 @@ public void initialize(SearchHandler searchHandler) {
displayStartMenu();
}

private void displayStartMenu() {
asyncDisplayOption("", "Ready to start?", MessageType.NONE, new Option[]{new Option("start", this::start), new Option("advanced", this::openAdvancedOptions)});
@Override
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?";
if (problematicMods.size() == 1) {
System.out.printf("Finished! The problematic mod was: %s (%s)%n", problematicMods.get(0).name(), problematicMods.get(0).filename());
} else {
System.out.println("Finished! The following mods rely on each other, and one is the problem:");
for (Mod problematicMod : problematicMods) {
System.out.printf("%s (%s)", problematicMod.name(), problematicMod.filename());
}
}
System.exit(0);
}

private void openAdvancedOptions() {
Expand All @@ -111,32 +161,13 @@ private void openAdvancedOptions() {
}

@Override
public void sendNextStepInstructions() {
sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). Then respond to the prompt.");
}

@Override
public void onBisectFinished() {
asyncDisplayOption("", "Is the problem fixed?", MessageType.NONE, new Option[]{new Option("Yes", this::success), new Option("No", this::failure)});
}

@Override
public void onFinished(ArrayList<Mod> problematicMods) {
assert searchHandler != null : "searchHandler should be the one calling, why is it null?";
if (problematicMods.size() == 1) {
System.out.printf("Finished! The problematic mod was: %s (%s)%n", problematicMods.get(0).name(), problematicMods.get(0).filename());
} else {
System.out.println("Finished! The following mods rely on each other, and one is the problem:");
for (Mod problematicMod : problematicMods) {
System.out.printf("%s (%s)", problematicMod.name(), problematicMod.filename());
}
}
System.exit(0);
public void sendInstructions(String instructions) {
System.out.println(instructions);
}

@Override
public void sendInstructions(String instructions) {
System.out.println(instructions);
public void sendNextStepInstructions() {
sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). Then respond to the prompt.");
}

@Override
Expand All @@ -157,7 +188,6 @@ public void success() {

@Override
public void updateLists(ArrayList<Mod> candidateMods, ArrayList<Mod> workingMods) {
// TODO: Add a way to query the search handler, that's what the cli will be doing
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ public void onFatalError() {
System.exit(1);
}

public ArrayList<Mod> getWorkingMods() {
return workingMods;
}

public ArrayList<Mod> getTestingMods() {
return testingMods;
}

public ArrayList<Mod> getCandidateMods() {
return candidateMods;
}

private @Nullable Mod parseMod(JarFile jarFile) throws IOException {
Main.log("Parsing mod");
JarEntry fmj = jarFile.getJarEntry("fabric.mod.json");
Expand Down

0 comments on commit 0adbc32

Please sign in to comment.