Skip to content

Commit 114e9c1

Browse files
committed
terminal: Allow a minimum console size to be set with '-c' [#90]
1 parent ee7d61f commit 114e9c1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/terminal.q

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Terminal (Console) Management
2-
// Copyright (c) 2020 Sport Trades Ltd
2+
// Copyright (c) 2020 Sport Trades Ltd, 2020 - 2022 Jaskirat Rajasansir
33

44
// Documentation: https://github.com/BuaBook/kdb-common/wiki/terminal.q
55

@@ -10,12 +10,30 @@
1010
/ adjust it if they are not in sync
1111
.terminal.cfg.trackSizeChange:1b;
1212

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+
1317
/ The default '.z.pi' handler to parse standard input. This seems to give an equivalent of the default handler when
1418
/ '.z.pi' is not set.
1519
.terminal.cfg.defaultZPi:{ 1 .Q.s value x; };
1620

1721

22+
.terminal.cmdLineConsoleSize:0N 0Ni;
23+
24+
1825
.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+
1937
if[.terminal.cfg.trackSizeChange & .terminal.isInteractive[];
2038
.log.if.info "Enabling terminal size change tracking on interactive terminal";
2139
.terminal.i.enableSizeTracking[];
@@ -24,15 +42,23 @@
2442

2543

2644
/ Gets the current terminal size and changes the kdb console size if it has changed
45+
/ @see .terminal.cmdLineConsoleSize
2746
/ @see .os.getTerminalSize
2847
/ @see system "c"
2948
.terminal.setToCurrentSize:{
3049
termSize:.os.getTerminalSize[];
50+
termSizeInt:"I"$" " vs termSize;
3151

3252
oldTermSize:system "c";
3353

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+
3460
/ If the console size is the same, just return
35-
if[oldTermSize ~ "I"$" " vs termSize;
61+
if[oldTermSize ~ termSizeInt;
3662
:(::);
3763
];
3864

0 commit comments

Comments
 (0)