aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapter/protocol/ftp.nim4
-rw-r--r--src/io/dynstream.nim6
-rw-r--r--src/local/pager.nim4
-rw-r--r--src/local/term.nim28
-rw-r--r--src/server/buffer.nim2
5 files changed, 27 insertions, 17 deletions
diff --git a/adapter/protocol/ftp.nim b/adapter/protocol/ftp.nim
index ba2a34d2..66987267 100644
--- a/adapter/protocol/ftp.nim
+++ b/adapter/protocol/ftp.nim
@@ -18,7 +18,7 @@ proc sendCommand(os, ps: PosixStream; cmd, param: string; outs: var string):
outs = ""
try:
ps.recvDataLoop(buf)
- while (let c = ps.sreadChar(); c != '\n'):
+ while (let c = ps.readChar(); c != '\n'):
outs &= c
let status = parseInt32(buf.toOpenArray(0, 2)).get(-1)
if buf[3] == ' ':
@@ -26,7 +26,7 @@ proc sendCommand(os, ps: PosixStream; cmd, param: string; outs: var string):
buf[3] = ' '
while true: # multiline
var lbuf = ""
- while (let c = ps.sreadChar(); c != '\n'):
+ while (let c = ps.readChar(); c != '\n'):
lbuf &= c
outs &= lbuf
if lbuf.startsWith(buf):
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim
index 55a73061..959c212a 100644
--- a/src/io/dynstream.nim
+++ b/src/io/dynstream.nim
@@ -60,10 +60,6 @@ proc write*(s: DynStream; buffer: openArray[char]) {.inline.} =
proc write*(s: DynStream; c: char) {.inline.} =
s.sendDataLoop(unsafeAddr c, 1)
-proc sreadChar*(s: DynStream): char =
- let n = s.recvData(addr result, 1)
- assert n == 1
-
proc recvDataLoop*(s: DynStream; buffer: pointer; len: int) =
var n = 0
while n < len:
@@ -134,7 +130,7 @@ method recvData*(s: PosixStream; buffer: pointer; len: int): int =
s.setEnd()
return n
-proc sreadChar*(s: PosixStream): char =
+proc readChar*(s: PosixStream): char =
let n = read(s.fd, addr result, 1)
assert n == 1
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 04f5fbe1..aee3c157 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -444,9 +444,9 @@ proc interruptHandler(rt: JSRuntime; opaque: pointer): cint {.cdecl.} =
var buf = [char(0)]
let n = pager.term.istream.recvData(buf)
if n == 1 and buf[0] == char(3): #C-c
- pager.term.ibuf = ""
+ pager.term.resetInputBuffer()
return 1
- pager.term.ibuf &= buf[0]
+ pager.term.bufferInputChar(buf[0])
except ErrorAgain:
discard
return 0
diff --git a/src/local/term.nim b/src/local/term.nim
index 77bd4ead..00c60e2b 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -136,7 +136,9 @@ type
origTermios: Termios
defaultBackground: RGBColor
defaultForeground: RGBColor
- ibuf*: string # buffer for chars when we can't process them
+ ibuf: array[256, char] # buffer for chars when we can't process them
+ ibufLen: int # len of ibuf
+ ibufn: int # position in ibuf
sixelRegisterNum*: int
sixelMaxWidth*: int
sixelMaxHeight: int
@@ -254,11 +256,23 @@ proc write(term: Terminal; s: cstring) =
term.outfile.write(s)
proc readChar*(term: Terminal): char =
- if term.ibuf.len == 0:
- result = term.istream.sreadChar()
- else:
- result = term.ibuf[0]
- term.ibuf.delete(0..0)
+ if term.ibufn == term.ibufLen:
+ term.ibufn = 0
+ term.ibufLen = term.istream.recvData(term.ibuf)
+ result = term.ibuf[term.ibufn]
+ inc term.ibufn
+
+proc bufferInputChar*(term: Terminal; c: char) =
+ if term.ibufn == term.ibuf.len:
+ return # can't help it, sorry :P
+ term.ibuf[term.ibufn] = c
+ inc term.ibufn
+ if term.ibufn >= term.ibufLen:
+ term.ibufLen = term.ibufn
+
+proc resetInputBuffer*(term: Terminal) =
+ term.ibufn = 0
+ term.ibufLen = 0
proc flush*(term: Terminal) =
term.outfile.flushFile()
@@ -292,7 +306,7 @@ proc anyKey*(term: Terminal; msg = "[Hit any key]") =
if term.isatty():
term.write(term.clearEnd() & msg)
term.flush()
- discard term.istream.sreadChar()
+ discard term.istream.readChar()
proc resetFormat(term: Terminal): string =
when TermcapFound:
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index c80f1b07..9258b293 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -1025,7 +1025,7 @@ proc clone*(buffer: Buffer; newurl: URL): int {.proxy.} =
discard close(pipefd[1]) # close write
# We must wait for child to tee its ongoing streams.
let ps = newPosixStream(pipefd[0])
- let c = ps.sreadChar()
+ let c = ps.readChar()
assert c == char(0)
ps.sclose()
buffer.loader.resume(ids)