0

The linux dialog command is a great tool for creating dialog boxes in terminal windows (e.g. in a bash script).

However, there is a drawback of dialog which is that the window is always positioned in the center of the screen.

In particular I would like to use the tail box function, e.g.

dialog --tailboxbg MYFILE 20 20

... which displays a tail of a file inside a text dialog (just like the built-in tail command).

However, I would like to place the resulting window at different positions on the screen. e.g. just in the top half or the lower half. dialog does not provide such functionality.

Is there any way to move the windows provided by dialog or can someone recommend an alternative tool which is capable of this?

2 Answers2

3

It is possible to position the dialog wherever you like using dialog's --begin switch (http://linux.die.net/man/1/dialog). However, to create dynamically sized dialogs, that work no matter what size your terminal window is, you will need to access the terminal window dimensions using tput. Then you can do the following in your bash script:

x=$(tput cols)
y=$(tput lines)
bx=10 # some offset
by=10 # how far down the window should be displayed
padbottom=2
# centered on width                                                     
dwidth=$(($x - $((bx * 2))))
# leave some padding at the bottom
dheight=$(($y - $((by + $padbottom))))
dialog --begin $by $bx --tailbox MY_FILE $dheight $dwidth

Result: horizontally centered dialog box on the lower half of your terminal window.

Warning: you may wish to add some extra checks in case the window size is very small.

0

There is only so much you can do with bash.

However for TUI progarms you can do pretty much everything you need with ncurses. https://www.gnu.org/software/ncurses/ncurses.html

There are wrappers over the C functions provided by curses; if you’re already familiar with curses programming in C.

Andy
  • 344