|
1 | 1 | // Terminal (Console) Management |
2 | | -// Copyright (c) 2020 Sport Trades Ltd |
| 2 | +// Copyright (c) 2020 Sport Trades Ltd, 2020 - 2022 Jaskirat Rajasansir |
3 | 3 |
|
4 | 4 | // Documentation: https://github.com/BuaBook/kdb-common/wiki/terminal.q |
5 | 5 |
|
|
10 | 10 | / adjust it if they are not in sync |
11 | 11 | .terminal.cfg.trackSizeChange:1b; |
12 | 12 |
|
| 13 | +/ If enabled, and '.terminal.cfg.trackSizeChange' is enabled, any console size specified via '-c' on the command line will |
| 14 | +/ be used as the smallest the terminal window will be resized to |
| 15 | +.terminal.cfg.setMinWithCommandLineArg:1b; |
| 16 | + |
13 | 17 | / The default '.z.pi' handler to parse standard input. This seems to give an equivalent of the default handler when |
14 | 18 | / '.z.pi' is not set. |
15 | 19 | .terminal.cfg.defaultZPi:{ 1 .Q.s value x; }; |
16 | 20 |
|
17 | 21 |
|
| 22 | +.terminal.cmdLineConsoleSize:0N 0Ni; |
| 23 | + |
| 24 | + |
18 | 25 | .terminal.init:{ |
| 26 | + if[.terminal.cfg.setMinWithCommandLineArg; |
| 27 | + .require.lib`cargs; |
| 28 | + |
| 29 | + args:.cargs.getWithInternal[]; |
| 30 | + |
| 31 | + if[`c in key args; |
| 32 | + .terminal.cmdLineConsoleSize:"I"$" " vs args`c; |
| 33 | + .log.info ("Minimum console size specified via '-c' command line argument [ Minimum Size: {} ]"; .terminal.cmdLineConsoleSize); |
| 34 | + ]; |
| 35 | + ]; |
| 36 | + |
19 | 37 | if[.terminal.cfg.trackSizeChange & .terminal.isInteractive[]; |
20 | 38 | .log.if.info "Enabling terminal size change tracking on interactive terminal"; |
21 | 39 | .terminal.i.enableSizeTracking[]; |
|
24 | 42 |
|
25 | 43 |
|
26 | 44 | / Gets the current terminal size and changes the kdb console size if it has changed |
| 45 | +/ @see .terminal.cmdLineConsoleSize |
27 | 46 | / @see .os.getTerminalSize |
28 | 47 | / @see system "c" |
29 | 48 | .terminal.setToCurrentSize:{ |
30 | 49 | termSize:.os.getTerminalSize[]; |
| 50 | + termSizeInt:"I"$" " vs termSize; |
31 | 51 |
|
32 | 52 | oldTermSize:system "c"; |
33 | 53 |
|
| 54 | + / If either the columns or lines is smaller than the console size specified via command line, don't change |
| 55 | + if[any termSizeInt < .terminal.cmdLineConsoleSize; |
| 56 | + termSize:" " sv string .terminal.cmdLineConsoleSize; |
| 57 | + termSizeInt:.terminal.cmdLineConsoleSize; |
| 58 | + ]; |
| 59 | + |
34 | 60 | / If the console size is the same, just return |
35 | | - if[oldTermSize ~ "I"$" " vs termSize; |
| 61 | + if[oldTermSize ~ termSizeInt; |
36 | 62 | :(::); |
37 | 63 | ]; |
38 | 64 |
|
|
0 commit comments