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
JLine 3: handle .inputrc
?
#12269
Comments
perhaps we can imitate @xuwei-k's sbt/sbt#5973 |
@SethTisue def inputrcFileUrl(): Option[URL] = {
sys.props
.get("jline.inputrc")
.flatMap { path =>
try Some(new URL(path))
catch {
case _: MalformedURLException =>
Some(new File(path).toURI.toURL)
}
}.orElse {
sys.props.get("user.home").map { home =>
val f = new File(home).toPath.resolve(".inputrc").toFile
(if (f.isFile) f else new File("/etc/inputrc")).toURI.toURL
}
}
}
def getByteArray(url: URL): Array[Byte] = {
Using.resource(Source.fromURL(url).bufferedReader()) {
bufferedReader =>
LazyList.continually(bufferedReader.read).takeWhile(_ != -1).map(_.toByte).toArray
}
}
lazy val inputrcFileContents: Option[Array[Byte]] = inputrcFileUrl().map(in => getByteArray(in))
val jlineTerminal = TerminalBuilder.builder().jna(true).build()
val completer = new Completion(completion)
val parser = new ReplParser(repl)
val history = new DefaultHistory
val builder =
LineReaderBuilder.builder()
.appName("scala")
.completer(completer)
.history(history)
.parser(parser)
.terminal(jlineTerminal)
locally {
import LineReader._, Option._
builder
.option(AUTO_GROUP, false)
.option(LIST_PACKED, true) // TODO
.option(INSERT_TAB, true) // At the beginning of the line, insert tab instead of completing
.variable(HISTORY_FILE, config.historyFile) // Save history to file
.variable(SECONDARY_PROMPT_PATTERN, config.encolor(config.continueText)) // Continue prompt
.variable(WORDCHARS, LineReaderImpl.DEFAULT_WORDCHARS.filterNot("*?.[]~=/&;!#%^(){}<>".toSet))
.option(Option.DISABLE_EVENT_EXPANSION, true) // Otherwise `scala> println(raw"\n".toList)` gives `List(n)` !!
}
val reader = builder.build()
try inputrcFileContents.foreach(f => InputRC.configure(reader, new ByteArrayInputStream(f))) catch {
case NonFatal(_) =>
} //ignore
|
I think manual testing on this one is fine. (And if you have access to a Windows machine to test it on, that would be cool; otherwise, we can ask for a volunteer Windows tester at PR review time.) |
👌 |
jxnu-liguobin
added a commit
to jxnu-liguobin/scala
that referenced
this issue
Feb 22, 2021
jxnu-liguobin
added a commit
to jxnu-liguobin/scala
that referenced
this issue
Mar 19, 2021
jxnu-liguobin
added a commit
to jxnu-liguobin/scala
that referenced
this issue
Mar 19, 2021
jxnu-liguobin
added a commit
to jxnu-liguobin/scala
that referenced
this issue
Mar 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
at scala/scala#8036 (comment) , @retronym wrote:
The text was updated successfully, but these errors were encountered: