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

Provide a simple RegistryImpl that can provide options from LineReader #1128

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Path> workDir, ConfigurationPath configPath) {
super(parser, terminal, workDir, configPath);
}

public void setLineReader(LineReader lineReader) {
this.lineReader = lineReader;
}

@SuppressWarnings("unchecked")
@Override
public <T> 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);
}
}
Loading