fix nim secret dots interfering with prompt (#16491)
* fix nim secret dots * cleanups
This commit is contained in:
parent
fbc8a40c7a
commit
f9a15dbae9
3 changed files with 9 additions and 4 deletions
|
|
@ -20,6 +20,7 @@ when hasRstdin: import rdstdin
|
||||||
|
|
||||||
type
|
type
|
||||||
TLLRepl* = proc (s: PLLStream, buf: pointer, bufLen: int): int
|
TLLRepl* = proc (s: PLLStream, buf: pointer, bufLen: int): int
|
||||||
|
OnPrompt* = proc() {.closure.}
|
||||||
TLLStreamKind* = enum # enum of different stream implementations
|
TLLStreamKind* = enum # enum of different stream implementations
|
||||||
llsNone, # null stream: reading and writing has no effect
|
llsNone, # null stream: reading and writing has no effect
|
||||||
llsString, # stream encapsulates a string
|
llsString, # stream encapsulates a string
|
||||||
|
|
@ -32,6 +33,7 @@ type
|
||||||
rd*, wr*: int # for string streams
|
rd*, wr*: int # for string streams
|
||||||
lineOffset*: int # for fake stdin line numbers
|
lineOffset*: int # for fake stdin line numbers
|
||||||
repl*: TLLRepl # gives stdin control to clients
|
repl*: TLLRepl # gives stdin control to clients
|
||||||
|
onPrompt*: OnPrompt
|
||||||
|
|
||||||
PLLStream* = ref TLLStream
|
PLLStream* = ref TLLStream
|
||||||
|
|
||||||
|
|
@ -55,12 +57,13 @@ proc llStreamOpen*(): PLLStream =
|
||||||
result.kind = llsNone
|
result.kind = llsNone
|
||||||
|
|
||||||
proc llReadFromStdin(s: PLLStream, buf: pointer, bufLen: int): int
|
proc llReadFromStdin(s: PLLStream, buf: pointer, bufLen: int): int
|
||||||
proc llStreamOpenStdIn*(r: TLLRepl = llReadFromStdin): PLLStream =
|
proc llStreamOpenStdIn*(r: TLLRepl = llReadFromStdin, onPrompt: OnPrompt = nil): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsStdIn
|
result.kind = llsStdIn
|
||||||
result.s = ""
|
result.s = ""
|
||||||
result.lineOffset = -1
|
result.lineOffset = -1
|
||||||
result.repl = r
|
result.repl = r
|
||||||
|
result.onPrompt = onPrompt
|
||||||
|
|
||||||
proc llStreamClose*(s: PLLStream) =
|
proc llStreamClose*(s: PLLStream) =
|
||||||
case s.kind
|
case s.kind
|
||||||
|
|
@ -133,6 +136,7 @@ proc llStreamRead*(s: PLLStream, buf: pointer, bufLen: int): int =
|
||||||
of llsFile:
|
of llsFile:
|
||||||
result = readBuffer(s.f, buf, bufLen)
|
result = readBuffer(s.f, buf, bufLen)
|
||||||
of llsStdIn:
|
of llsStdIn:
|
||||||
|
if s.onPrompt!=nil: s.onPrompt()
|
||||||
result = s.repl(s, buf, bufLen)
|
result = s.repl(s, buf, bufLen)
|
||||||
|
|
||||||
proc llStreamReadLine*(s: PLLStream, line: var string): bool =
|
proc llStreamReadLine*(s: PLLStream, line: var string): bool =
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,8 @@ proc commandInteractive(graph: ModuleGraph) =
|
||||||
var m = graph.makeStdinModule()
|
var m = graph.makeStdinModule()
|
||||||
incl(m.flags, sfMainModule)
|
incl(m.flags, sfMainModule)
|
||||||
var idgen = IdGenerator(module: m.itemId.module, item: m.itemId.item)
|
var idgen = IdGenerator(module: m.itemId.module, item: m.itemId.item)
|
||||||
processModule(graph, m, idgen, llStreamOpenStdIn())
|
let s = llStreamOpenStdIn(onPrompt = proc() = flushDot(graph.config, stderr))
|
||||||
|
processModule(graph, m, idgen, s)
|
||||||
|
|
||||||
proc commandScan(cache: IdentCache, config: ConfigRef) =
|
proc commandScan(cache: IdentCache, config: ConfigRef) =
|
||||||
var f = addFileExt(AbsoluteFile mainCommandArg(config), NimExt)
|
var f = addFileExt(AbsoluteFile mainCommandArg(config), NimExt)
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ template instLoc(): InstantiationInfo = instantiationInfo(-2, fullPaths = true)
|
||||||
template toStdOrrKind(stdOrr): untyped =
|
template toStdOrrKind(stdOrr): untyped =
|
||||||
if stdOrr == stdout: stdOrrStdout else: stdOrrStderr
|
if stdOrr == stdout: stdOrrStdout else: stdOrrStderr
|
||||||
|
|
||||||
template flushDot(conf, stdOrr) =
|
template flushDot*(conf, stdOrr) =
|
||||||
## safe to call multiple times
|
## safe to call multiple times
|
||||||
let stdOrrKind = stdOrr.toStdOrrKind()
|
let stdOrrKind = toStdOrrKind(stdOrr)
|
||||||
if stdOrrKind in conf.lastMsgWasDot:
|
if stdOrrKind in conf.lastMsgWasDot:
|
||||||
conf.lastMsgWasDot.excl stdOrrKind
|
conf.lastMsgWasDot.excl stdOrrKind
|
||||||
write(stdOrr, "\n")
|
write(stdOrr, "\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue