-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a simple RegistryImpl that can provide options from LineReader (
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
console/src/main/java/org/jline/console/impl/SimpleSystemRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |