feat: save console history to a file so we can restore it on the next boot

This commit is contained in:
ChomeNS
2025-07-28 18:20:42 +07:00
parent 3da96f9347
commit 908bbc07be
2 changed files with 10 additions and 3 deletions

View File

@@ -1 +1 @@
3517
3519

View File

@@ -17,10 +17,13 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.jetbrains.annotations.NotNull;
import org.jline.reader.*;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
public class ConsolePlugin implements Completer {
private static final Path HISTORY_PATH = Path.of(".console_history");
private static final ConsoleFormatRenderer RENDERER = new ConsoleFormatRenderer();
private final List<Bot> allBots;
@@ -40,10 +43,10 @@ public class ConsolePlugin implements Completer {
this.reader = LineReaderBuilder
.builder()
.completer(this)
.variable(LineReader.HISTORY_FILE, HISTORY_PATH)
.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true)
.build();
reader.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true);
final Thread thread = new Thread(
() -> {
while (true) {
@@ -55,6 +58,10 @@ public class ConsolePlugin implements Completer {
}
handleLine(line);
try {
reader.getHistory().save();
} catch (final IOException ignored) { }
}
},
"Console Thread"