Compare commits
2 Commits
5116918ff2
...
8e21117986
Author | SHA1 | Date |
---|---|---|
Sekulum Forka | 8e21117986 | |
Sekulum Forka | 87982fdcbc |
15
src/fsh.nim
15
src/fsh.nim
|
@ -35,6 +35,7 @@ type
|
|||
variable: string
|
||||
ShellCommandError = object of ShellError
|
||||
command: string
|
||||
InterruptCtrlC = object of CatchableError
|
||||
|
||||
# procs for making procedures
|
||||
proc newShellException(msg: string, line=0, col=0, whileExec=""): ref ShellError =
|
||||
|
@ -64,6 +65,10 @@ proc newShellCommandException(msg: string, command: string, line=0, col=0, while
|
|||
proc eval(cmd: string): string
|
||||
proc substitute(strm: Stream, delim = ";\p"): string
|
||||
|
||||
# ctrlc is the ctrl-c handler
|
||||
proc ctrlc() {.noconv.} =
|
||||
raise newException(InterruptCtrlC, "")
|
||||
|
||||
# skipSpaces reads the stream until a non-space character is found
|
||||
proc skipSpaces(strm: Stream): int =
|
||||
while not strm.atEnd():
|
||||
|
@ -321,6 +326,14 @@ proc eval(cmd: string): string =
|
|||
strm.close
|
||||
|
||||
when isMainModule:
|
||||
# ctrlc handler
|
||||
setControlCHook(ctrlc)
|
||||
let stdinstrm = stdin.newFileStream
|
||||
while not stdinstrm.atEnd():
|
||||
stdinstrm.readCommand.execute.echo
|
||||
try:
|
||||
discard stdinstrm.readCommand.execute
|
||||
except ShellError, ShellCommandError, ShellVariableError:
|
||||
let e = getCurrentException()
|
||||
stderr.write(e.msg, "\n")
|
||||
except InterruptCtrlC:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue