Skip to content

terminal.q

Jaskirat Rajasansir edited this page Jan 10, 2021 · 3 revisions

Terminal (Console) Management

This library can track changes to the current terminal window that kdb+ is running in and adjust the kdb console size (system "c") to match it.

The adjustment can be done manually (via .terminal.setToCurrentSize) or automatically via the .z.pi event hander.

Automatic Update of Console Size

Automatic update of the kdb+ console size to the current terminal window is configured by .terminal.cfg.trackSizeChange.

If enabled, and the current terminal is interactive, the .z.pi event handler function will be set.

Any existing .z.pi function will be kept and wrapped by .terminal.i.trackHandler. If no existing .z.pi function exists, a default .terminal.cfg.defaultZPi function will be used instead.

.terminal.setToCurrentSize

This function changes the kdb+ console size to match the current terminal window size.

Example

/ With TRACE logging enabled
q)\c
25 80i
q).terminal.setToCurrentSize[]
2020.05.16 20:00:24.128 DEBUG pid-1218 jas 0 Running system command: "stty size"
2020.05.16 20:00:24.140 TRACE pid-1218 jas 0 Console size change [ Old: 25 80i ] [ New: 84 157 ]
q)\c
84 157i

.terminal.isInteractive

This function returns true if the current kdb process is running interactively, false otherwise.

Example

/ Interactive session with "rlwrap $QHOME/l64/q src/require.q"

q).require.init[]; .require.lib`terminal
...

q).terminal.isInteractive[]
Running system command: "stty size"
Running system command: "tty --quiet; echo $?"
Current kdb process terminal state [ Interactive: yes ]
1b
# Non-interactive session

> echo '.require.init[]; .require.lib`terminal; -1 .Q.s .terminal.isInteractive[];' | $QHOME/l64/q src/require.q
...
Running system command: "tty --quiet; echo $?"
Current kdb process terminal state [ Interactive: no ]
0b
Clone this wiki locally