read()

Expression usage:

read()


In an expression, read() reads a line of input from the keyboard until the newline key is pressed or "/dokey newline" is executed. During read(), all existing keybindings continue to work normally.

Any text already in the input buffer is not cleared when read() starts. Text entered after read() starts is appended to the existing text, and when the read() ends, its result is the entire input buffer. Lines entered during a read() are not saved in the input history (but you can use "/recordline -i" to save them explicitly).

read() (and the macro that called it) can be interrupted with a SIGINT, normally generated by typing CTRL-C.

As an example, here's a simplified version of /cat:

  /def mycat = \
      /let line=%; \
      /let all=%; \
      /while ((line:=read()) !~ ".") \
          /test all:=strcat(all, line)%; \
      /done%; \
      /eval %{all}
Executing "/mycat" will repeatedly read lines from the keyboard, and assign them to %line. If the line matches ".", the loop ends. Each %line is appended onto %all. After the loop ends, the contents of %all are evaluated.

Caveat: during a read(), if a macro calls /dokey newline, the newline will not be executed immediately, but will be held until the rest of the commands in the macro are processed. For example, consider the keybinding "/def -b'^[^M' = /dokey newline%; /send go". Normally, typing ^[^M would execute the current input buffer, then send "go" to the server. But during a read(), typing ^[^M would send "go" first, and then do the newline that completes the read().

See: interface, /input, expressions, functions


Back to index
Back to tf home page
Copyright © 1995, 1996, 1997 Ken Keys