BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Nuthatch · Keep terminal help visible after a resize

Wrap a message and preserve a valid scroll position after resizing a terminal.

Keep terminal help visible after a resize

After a terminal becomes wider, the old scroll offset can leave an otherwise valid help screen blank. Four words each occupy their own line. A scroll request past the end selects the last two visible lines.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-nuthatch.git
cd blyx-nuthatch
blyxc native-run project.blyx -- "4,4,4,4" 6 99 2

API and return values

Returns [wrapped line count, first visible line, exclusive end, last line width]. The host supplies display-cell widths for its font. Invalid input returns an empty vector.

ArgumentAccepted input
widthsVector of: nonnegative exact integer
columnspositive exact integer
startnonnegative exact integer
heightpositive exact integer

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
4
2
4
4
Open in the full playground →

Practice

Change widths = [2, 2], columns = 5.0, start = 0.0, height = 3.0. Predict the result, then run the program.

Hint

Returns [wrapped line count, first visible line, exclusive end, last line width]. The host supplies display-cell widths for its font.

Worked solution

The result vector is [1, 0, 1, 5]. Compare its fields with the return layout in the API section.

Find

    let widths = [4, 4, 4, 4];

Replace with

    let widths = [2, 2];

Find

    let columns = 6.0;

Replace with

    let columns = 5.0;

Find

    let start = 99.0;

Replace with

    let start = 0.0;

Find

    let height = 2.0;

Replace with

    let height = 3.0;

Output after the change

1
0
1
5