Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent Command Buffer #2047

Merged
merged 15 commits into from Nov 9, 2023
2 changes: 2 additions & 0 deletions src/data/defaults.txt
Expand Up @@ -26,6 +26,8 @@ global combatHotkey6
global combatHotkey7
global combatHotkey8
global combatHotkey9
global commandBufferGCLI
global commandBufferTabbedChat
global commandLineNamespace
global compactChessboard false
global copyAsHTML false
Expand Down
Expand Up @@ -24,7 +24,7 @@
public CommandDisplayFrame() {
super("Graphical CLI");

this.setCenterComponent(new CommandDisplayPanel());
this.setCenterComponent(new CommandDisplayPanel("commandBufferGCLI"));

Check warning on line 27 in src/net/sourceforge/kolmafia/swingui/CommandDisplayFrame.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/CommandDisplayFrame.java#L27

Added line #L27 was not covered by tests
}

@Override
Expand All @@ -42,12 +42,12 @@
return true;
}

public static final boolean hasQueuedCommands() {
public static boolean hasQueuedCommands() {
return !CommandDisplayFrame.commandQueue.isEmpty() || handler.command != null;
}

public static final void executeCommand(final String command) {
if (command.length() == 0) {
public static void executeCommand(final String command) {
if (command.isEmpty()) {
return;
}

Expand Down
Expand Up @@ -17,7 +17,7 @@
this.setTitle("Loathing Chat");

if (Preferences.getBoolean("addChatCommandLine")) {
this.tabs.addTab("[gcli]", new CommandDisplayPanel());
this.tabs.addTab("[gcli]", new CommandDisplayPanel("commandBufferTabbedChat"));

Check warning on line 20 in src/net/sourceforge/kolmafia/swingui/TabbedChatFrame.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/TabbedChatFrame.java#L20

Added line #L20 was not covered by tests
}

this.tabs.addChangeListener(new TabFocusingListener());
Expand Down
@@ -1,9 +1,13 @@
package net.sourceforge.kolmafia.swingui.panel;

import static net.sourceforge.kolmafia.preferences.Preferences.getString;
import static net.sourceforge.kolmafia.preferences.Preferences.setString;

import java.awt.BorderLayout;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.util.Collections;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand All @@ -24,9 +28,14 @@
private final AutoHighlightTextField entryField;
private final JButton entryButton;

private final String preference;
private final String DELIMITER = "#";

Check warning on line 32 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L32

Added line #L32 was not covered by tests
jaadams5 marked this conversation as resolved.
Show resolved Hide resolved

private int commandIndex = 0;

public CommandDisplayPanel() {
public CommandDisplayPanel(String preference) {
this.preference = preference;
loadHistoryFromPreference();

Check warning on line 38 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L36-L38

Added lines #L36 - L38 were not covered by tests
RequestPane outputDisplay = new RequestPane();
outputDisplay.addHyperlinkListener(new HyperlinkAdapter());

Expand Down Expand Up @@ -56,6 +65,20 @@
this.addFocusListener(this);
}

private void loadHistoryFromPreference() {
String pref = getString(preference);
String[] commands = pref.split(DELIMITER);

Check warning on line 70 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L69-L70

Added lines #L69 - L70 were not covered by tests
if (!commands[0].trim().isEmpty()) {
Collections.addAll(commandHistory, commands);
this.commandIndex = commandHistory.size();

Check warning on line 73 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L72-L73

Added lines #L72 - L73 were not covered by tests
}
}

Check warning on line 75 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L75

Added line #L75 was not covered by tests

private void updatePreference() {
String newPref = String.join(DELIMITER, commandHistory);
setString(preference, newPref);
}

Check warning on line 80 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L78-L80

Added lines #L78 - L80 were not covered by tests

@Override
public void focusGained(FocusEvent e) {
this.entryField.requestFocus();
Expand Down Expand Up @@ -139,6 +162,7 @@
&& (CommandDisplayPanel.this.commandHistory.isEmpty()
|| !CommandDisplayPanel.this.commandHistory.getLast().equals(command))) {
CommandDisplayPanel.this.commandHistory.add(command);
updatePreference();

Check warning on line 165 in src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java

View check run for this annotation

Codecov / codecov/patch

src/net/sourceforge/kolmafia/swingui/panel/CommandDisplayPanel.java#L165

Added line #L165 was not covered by tests
}

CommandDisplayPanel.this.commandIndex = CommandDisplayPanel.this.commandHistory.size();
Expand Down