#!/bin/bash
# gxmessage tests and examples

# use xmessage if gxmessage isn't available
XMESSAGE=${XMESSAGE:-$(which gxmessage)} || MESSAGE=xmessage
XMESSAGE=$(basename "$XMESSAGE")

$XMESSAGE A few $XMESSAGE tests
$XMESSAGE -center "The -center option"
$XMESSAGE -center -default okay "The default button has focus"

$XMESSAGE -center -buttons "one:1,two:2,three:3" \
  "Button labels and return values"
echo $?

$XMESSAGE -center -buttons 'Hello\, world:42,This\, as you see\, is a test:43' \
  "Buttons containing escaped characters"
echo $?

$XMESSAGE -center -print -buttons 'one\: 10:10,two\: 20:20,three\: 30:30,hello\, world\: 40:40' \
  "More buttons with escaped characters"

$XMESSAGE -center \
  -buttons "GTK_STOCK_HELP,GTK_STOCK_OK,GTK_STOCK_CANCEL,GTK_STOCK_CLOSE" \
  -default GTK_STOCK_CLOSE "Some GTK stock buttons"
echo $?

$XMESSAGE -center -buttons "" -timeout 5 "The -timeout option..."
echo $?

$XMESSAGE -center -buttons "_Red,_Green,_Blue" -default _Blue \
  "Keyboard accelerators"

$XMESSAGE -center -file "$0" -default okay
$XMESSAGE -help | $XMESSAGE -center -file - -default okay

$XMESSAGE -center -fg white -bg '#10191e' -default okay \
  "The -fg and -bg options"

FONT="monospace bold 12"
[ "$XMESSAGE" = gxmessage ] || FONT="-misc-fixed-*-*-*-*-*-140-*-*-*-*-*-*"
$XMESSAGE -center -geometry 500x100 ${FONT:+-font "$FONT"} \
  "Using -font without upsetting xmessage"

$XMESSAGE - -- dash - test - -- -center - -default okay -

$XMESSAGE -center -display :0 "Testing the -display and -name options" \
          -name George

if [ "$XMESSAGE" != gxmessage ]
then

  # skip gxmessage-specific tests if not using gxmessage
  :

else

  NAME=$($XMESSAGE -center -entry -buttons "" "What's your name?")
  echo "Hello, $NAME!"

  ME=${HOSTNAME:-Bart}
  NAME=$($XMESSAGE -center -entrytext "$ME" -buttons "" \
         "What's my name?");
  [ "$NAME" = "$ME" ] || echo "You mean I'm not $ME?!"

fi

echo "finished"

