SQLite Forum

Shell function to return screen width
Login

Shell function to return screen width

(1) By anonymous on 2021-03-04 15:44:28 [link] [source]

When running queries/views in different PCs with different console width, it'd be nice to have a way of knowing what the terminal width is so that the query/view output is adjusted to not wrap in multiple lines. For example:

SELECT a,b from t;

may wrap around if the combined length of a and b is too long for the current screen width.

SELECT substr(a,1,20/100*width()) a,substr(b,1,78/100*width()) b from t;

would automatically truncate the output as 20/78% (I'm leaving 2% for inter-column overhead) for the above example.

For this to work, a function width() [name?] is required at the shell level, not the SQLite3 core.

(2) By Stephan Beal (stephan) on 2021-03-04 15:58:20 in reply to 1 [source]

... it'd be nice to have a way of knowing what the terminal width is so that the query/view output is adjusted to not wrap in multiple lines.

For anyone interested in working on such a thing, Fossil has an implementation:

https://fossil-scm.org/home/finfo?name=src/terminal.c