Skip to content

Commit

Permalink
Provide a simple RegistryImpl that can provide options from LineReader (
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Dec 10, 2024
1 parent 3ad5b9e commit fd7f59b
Showing 1 changed file with 44 additions and 0 deletions.
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);
}
}

0 comments on commit fd7f59b

Please sign in to comment.