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?

chriskelly
  • 576
  • 6
  • 11
maihabunash
  • 443
  • 1
  • 11
  • 25

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.

chriskelly
  • 576
  • 6
  • 11
  • but how can I work with dialog command and with vmctrl ? ( +1) – maihabunash Sep 19 '14 at 12:36
  • First you open your dialog. Then get a handle on the dialog window. Then use wmctrl to control the position of the window. I will update the answer with an example when I am at home and I have linux in front of me. – chriskelly Sep 19 '14 at 12:54
  • thx , I not want to give up with dialog and if wmctrl can move the dialog window it will solve my problem – maihabunash Sep 19 '14 at 13:34
  • I have looked only to discover that *dialog* is a text based window maker. I haver personally never used this tool (although I use wmctrl a lot) and from your question I had the impression that it was and X based GUI tool. I have edited your question above and will update my answer tomorrow. – chriskelly Sep 19 '14 at 23:45
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
  • 1
  • 8