Actualizado el martes, 28 febrero, 2017
Continuamos con los artículos «Crear menús y diálogos con scripts bash». Así que hoy creamos nuestro primer «box«, para ello usaremos el comando dialog.
Instalando.
Debian, Ubuntu y derivados:
apt-get install dialog
Centos, Red hat y derivados:
yum install dialog
OpenSuse:
zypper install dialog
Sintaxis.
La sintaxis de dialog es muy simple, observa:
dialog --common-options --boxType "Text" Height Width --box-specific-option
Explicación…
- –common-options: Se establecen los cuadros de diálogo, color de fondo, título, etc…
- Todos los cuadros de diálogo deben al menos tres parámetros:
- «Text»: Título o contenido del box.
- «Height»: Altura del cuadro de diálogo.
- «Width»: Ancho del cuadro de diálogo.
Mi primer Box con dialog.
Crearemos nuestro primer box con las siguientes características.
- Un box con texto se mostrara en la pantalla con un botón OK.
- Puedes mostrar cualquier mensaje.
- Al pulsar ENTER o ticar en Ok saldrás del script shell y volverás a la consola.
Ejemplo:
dialog --title "Hola" --msgbox 'Hola Sololinux!' 6 20
- 6 : Establece la altura del box.
- 20 : Establece el ancho del box.
El resultado:
Box con titulo y opciones.
En este caso ya colocaremos un titulo en la parte superior de la pantalla, algo que nos recordara al articulo anterior.
Usaremos «–backtitle» para insertar el titulo y «–begin» para posicionarlo, en este caso en la parte superior izquierda de la pantalla.
dialog --begin 10 30 --backtitle "System Information" \ --title "About" \ --msgbox 'Pese a que muchos les fastidie, el conocimiento debe ser libre y gratuito.' 10 30
- –begin 10 30: 10 posición horizontal y 30 posición vertical.
El resultado:
Opciones del box.
Estas son las opciones más comunes en dialog:
--calendar <text> <height> <width> <day> <month> <year> --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>... --dselect <directory> <height> <width> --editbox <file> <height> <width> --fselect <filepath> <height> <width> --gauge <text> <height> <width> [<percent>] --infobox <text> <height> <width> --inputbox <text> <height> <width> [<init>] --inputmenu <text> <height> <width> <menu height> <tag1> <item1>... --menu <text> <height> <width> <menu height> <tag1> <item1>... --msgbox <text> <height> <width> --passwordbox <text> <height> <width> [<init>] --pause <text> <height> <width> <seconds> --progressbox <height> <width> --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>... --tailbox <file> <height> <width> --tailboxbg <file> <height> <width> --textbox <file> <height> <width> --timebox <text> <height> <width> <hour> <minute> <second> --yesno <text> <height> <width>
Continuaremos en próximo articulo. ——–>>