Added optional proc parameter to llStreamOpenStdIn (#10769)
This commit is contained in:
parent
7072e3ddca
commit
bf1f4b914b
1 changed files with 6 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ when not defined(windows) and (defined(useGnuReadline) or defined(useLinenoise))
|
||||||
import rdstdin
|
import rdstdin
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TLLRepl* = proc (s: PLLStream, buf: pointer, bufLen: int): int
|
||||||
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
|
||||||
|
|
@ -28,6 +29,7 @@ type
|
||||||
s*: string
|
s*: string
|
||||||
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
|
||||||
|
|
||||||
PLLStream* = ref TLLStream
|
PLLStream* = ref TLLStream
|
||||||
|
|
||||||
|
|
@ -50,11 +52,13 @@ proc llStreamOpen*(): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsNone
|
result.kind = llsNone
|
||||||
|
|
||||||
proc llStreamOpenStdIn*(): PLLStream =
|
proc llReadFromStdin(s: PLLStream, buf: pointer, bufLen: int): int
|
||||||
|
proc llStreamOpenStdIn*(r: TLLRepl = llReadFromStdin): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsStdIn
|
result.kind = llsStdIn
|
||||||
result.s = ""
|
result.s = ""
|
||||||
result.lineOffset = -1
|
result.lineOffset = -1
|
||||||
|
result.repl = r
|
||||||
|
|
||||||
proc llStreamClose*(s: PLLStream) =
|
proc llStreamClose*(s: PLLStream) =
|
||||||
case s.kind
|
case s.kind
|
||||||
|
|
@ -127,7 +131,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:
|
||||||
result = llReadFromStdin(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 =
|
||||||
setLen(line, 0)
|
setLen(line, 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue