From fd7f59b6ef05acc34eaf41184e7959bd4269783e Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 10 Dec 2024 17:54:49 +0100 Subject: [PATCH] Provide a simple RegistryImpl that can provide options from LineReader (#1128) --- .../impl/SimpleSystemRegistryImpl.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 console/src/main/java/org/jline/console/impl/SimpleSystemRegistryImpl.java diff --git a/console/src/main/java/org/jline/console/impl/SimpleSystemRegistryImpl.java b/console/src/main/java/org/jline/console/impl/SimpleSystemRegistryImpl.java new file mode 100644 index 000000000..d9c2a69eb --- /dev/null +++ b/console/src/main/java/org/jline/console/impl/SimpleSystemRegistryImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024, the original author(s). + * + * This software is distributable under the BSD license. See the terms of the + * BSD license in the documentation provided with this software. + * + * https://opensource.org/licenses/BSD-3-Clause + */ +package org.jline.console.impl; + +import java.nio.file.Path; +import java.util.function.Supplier; + +import org.jline.builtins.ConfigurationPath; +import org.jline.reader.LineReader; +import org.jline.reader.Parser; +import org.jline.terminal.Terminal; + +/** + * Simple SystemRegistry which stores variables in the LineReader. + */ +public class SimpleSystemRegistryImpl extends SystemRegistryImpl { + private LineReader lineReader; + + public SimpleSystemRegistryImpl( + Parser parser, Terminal terminal, Supplier workDir, ConfigurationPath configPath) { + super(parser, terminal, workDir, configPath); + } + + public void setLineReader(LineReader lineReader) { + this.lineReader = lineReader; + } + + @SuppressWarnings("unchecked") + @Override + public T consoleOption(String name, T defVal) { + return (T) lineReader.getVariables().getOrDefault(name, defVal); + } + + @Override + public void setConsoleOption(String name, Object value) { + lineReader.setVariable(name, value); + } +}