summary refs log tree commit diff stats
path: root/lib/impure/rdstdin.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/impure/rdstdin.nim')
-rwxr-xr-xlib/impure/rdstdin.nim24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/impure/rdstdin.nim b/lib/impure/rdstdin.nim
index bc523187a..5d39186ce 100755
--- a/lib/impure/rdstdin.nim
+++ b/lib/impure/rdstdin.nim
@@ -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
023be948e3ad479069c'>^
222c31db ^

bb62d65e ^


c442a5ad ^
bb62d65e ^


1a62e61d ^
c442a5ad ^
f7ff8585 ^
222c31db ^
836d13db ^

c442a5ad ^
836d13db ^

222c31db ^
bb62d65e ^
c442a5ad ^
836d13db ^
bb62d65e ^
631de5d9 ^
836d13db ^
4a943d4e ^





83c67014 ^
4a943d4e ^



83c67014 ^
4a943d4e ^








0e87e934 ^
4a943d4e ^



83c67014 ^
4a943d4e ^



83c67014 ^
4a943d4e ^








d1df4aca ^


4a943d4e ^





83c67014 ^
4a943d4e ^



83c67014 ^
4a943d4e ^









d1df4aca ^







4a943d4e ^





83c67014 ^
4a943d4e ^



83c67014 ^
4a943d4e ^









d1df4aca ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155