octotui icon indicating copy to clipboard operation
octotui copied to clipboard

[FEATURE] Adjustable modules

Open Zaedus opened this issue 3 years ago • 4 comments

Its a little annoying, but is it possible for the little modules/boxes to adjust to the terminal width instead of being cut off. Also, it would be really cool to be able to modify which modules/boxes show.

Zaedus avatar May 12 '21 19:05 Zaedus

Looking at termui's docs quickly, looks like it doesn't support relative sizing, only absolute, unlike tview, which is surprising. But I assume it shouldn't be too difficult to calculate manually by using x/term to calculate the terminal's size :slightly_smiling_face:

spenserblack avatar May 12 '21 19:05 spenserblack

it does

x, y := ui.TerminalDimensions()
l.SetRect(0, 4, x, y)

irevenko avatar May 12 '21 19:05 irevenko

That's what I get for only searching "Size" :sweat_smile: Looks like octotui assumes the screen is at least 220 wide from what I'm looking at, so something like

x, _ := ui.TerminalDimensions()
ratio := 220 / x
if ratio < 1 {
    ratio = 1
}
myWidget.SetRect(xCoord / ratio, yCoord, width / ratio, height)

should roughly accomplish sizing based on terminal width. If, for example, the terminal is 110 wide, then ratio is 2, and width of myWidget is half the full size.

This is just a lazy example, and you'll probably want to use floating points instead to get more precise sizing (e.g. if x == 200, there wouldn't be any resizing in this example).

spenserblack avatar May 12 '21 20:05 spenserblack

Ignore my previous comment, it's probably better to use termui's Grid than to manually resize everything based on terminal size. See #9.

looks like it doesn't support relative sizing ... unlike tview,

I was wrong about this, too! :sweat_smile:

spenserblack avatar May 13 '21 13:05 spenserblack