compiler uses new 'readLine'
This commit is contained in:
parent
7832af187a
commit
a489161b16
8 changed files with 86 additions and 73 deletions
|
|
@ -14,15 +14,25 @@
|
|||
## wanted functionality.
|
||||
|
||||
when defined(Windows):
|
||||
proc ReadLineFromStdin*(prompt: string): TaintedString =
|
||||
proc ReadLineFromStdin*(prompt: string): TaintedString {.deprecated.} =
|
||||
## Reads a line from stdin.
|
||||
stdout.write(prompt)
|
||||
result = readLine(stdin)
|
||||
|
||||
proc ReadLineFromStdin*(prompt: string, line: var TaintedString): bool =
|
||||
## Reads a `line` from stdin. `line` must not be
|
||||
## ``nil``! May throw an IO exception.
|
||||
## A line of text may be delimited by ``CR``, ``LF`` or
|
||||
## ``CRLF``. The newline character(s) are not part of the returned string.
|
||||
## Returns ``false`` if the end of the file has been reached, ``true``
|
||||
## otherwise. If ``false`` is returned `line` contains no new data.
|
||||
stdout.write(prompt)
|
||||
result = readLine(stdin, line)
|
||||
|
||||
else:
|
||||
import readline, history
|
||||
|
||||
proc ReadLineFromStdin*(prompt: string): TaintedString =
|
||||
proc ReadLineFromStdin*(prompt: string): TaintedString {.deprecated.} =
|
||||
var buffer = readline.readLine(prompt)
|
||||
if isNil(buffer): quit(0)
|
||||
result = TaintedString($buffer)
|
||||
|
|
@ -30,6 +40,16 @@ else:
|
|||
add_history(buffer)
|
||||
readline.free(buffer)
|
||||
|
||||
proc ReadLineFromStdin*(prompt: string, line: var TaintedString): bool =
|
||||
var buffer = readline.readLine(prompt)
|
||||
if isNil(buffer): quit(0)
|
||||
line = TaintedString($buffer)
|
||||
if line.string.len > 0:
|
||||
add_history(buffer)
|
||||
readline.free(buffer)
|
||||
# XXX how to determine CTRL+D?
|
||||
result = true
|
||||
|
||||
# initialization:
|
||||
# disable auto-complete:
|
||||
proc doNothing(a, b: cint): cint {.cdecl, procvar.} = nil
|
||||
|
|
|
|||
|
|
@ -150,19 +150,6 @@ proc readStr*(s: PStream, length: int): TaintedString =
|
|||
var L = readData(s, addr(string(result)[0]), length)
|
||||
if L != length: setLen(result.string, L)
|
||||
|
||||
proc readLine*(s: PStream): TaintedString {.deprecated.} =
|
||||
## Reads a line from a stream `s`. Note: This is not very efficient. Raises
|
||||
## `EIO` if an error occured.
|
||||
## **Deprecated since version 0.8.14**: Because Posix supports it poorly.
|
||||
result = TaintedString""
|
||||
while not atEnd(s):
|
||||
var c = readChar(s)
|
||||
if c == '\c':
|
||||
c = readChar(s)
|
||||
break
|
||||
elif c == '\L' or c == '\0': break
|
||||
result.string.add(c)
|
||||
|
||||
proc readLine*(s: PStream, line: var TaintedString): bool =
|
||||
## reads a line of text from the stream `s` into `line`. `line` must not be
|
||||
## ``nil``! May throw an IO exception.
|
||||
|
|
@ -183,6 +170,19 @@ proc readLine*(s: PStream, line: var TaintedString): bool =
|
|||
line.string.add(c)
|
||||
result = true
|
||||
|
||||
proc readLine*(s: PStream): TaintedString {.deprecated.} =
|
||||
## Reads a line from a stream `s`. Note: This is not very efficient. Raises
|
||||
## `EIO` if an error occured.
|
||||
## **Deprecated since version 0.8.14**: Because Posix supports it poorly.
|
||||
result = TaintedString""
|
||||
while true:
|
||||
var c = readChar(s)
|
||||
if c == '\c':
|
||||
c = readChar(s)
|
||||
break
|
||||
elif c == '\L' or c == '\0': break
|
||||
result.string.add(c)
|
||||
|
||||
type
|
||||
PStringStream* = ref TStringStream ## a stream that encapsulates a string
|
||||
TStringStream* = object of TStream
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue