#!/bin/bash
# Programmer: Kevin Day
# License: FLLL
# See: www.kevux.org

main(){
  local c_reset="\\033[0m"
  local c_title="\\033[1;33m"
  local c_error="\\033[1;31m"
  local c_warning="\\033[0;33m"
  local c_highlight="\\033[1;32m"
  local c_notice="\\033[0;01m"
  local c_important="\\033[0;32m"
  local do_color="normal"

  local the_input="$@"
  local version="1.0.1"
  local return_status=

  process_parameters
  
  if [[ $return_status != "" ]] ; then
    return $return_status
  fi

  execute_program
}

process_parameters(){
  local grab_next=

  for i in $the_input ; do
   if [[ $i == "-n" || $i == "--no_color" ]] ; then
     do_color="none"
     break
   elif [[ $i == "-l" || $i == "--light" ]] ; then
     do_color="light"
     break
   fi
  done
  
  if [[ $do_color == "light" || $(echo $the_input | grep "[[:space:]]*--light\>") != "" ]] ; then
    the_input=$(echo $the_input | sed -e 's|[[:space:]]*-l\>||g' | sed -e 's|[[:space:]]*--light\>||g')
    c_error="\\033[1;31m"
    c_warning="\\033[0;31m"
    c_title="\\033[1;34m"
    c_highlight="\\033[1;34m"
    c_notice="\\033[0;01m"
    c_important="\\033[0;34m"
  elif [[ $do_color == "none" || $(echo $the_input | grep "[[:space:]]*--no_color\>") != "" ]] ; then
    the_input=$(echo $the_input | sed -e 's|[[:space:]]*-n\>||g' | sed -e 's|[[:space:]]*--no_color\>||g')
    c_reset=
    c_title=
    c_error=
    c_warning=
    c_highlight=
    c_notice=
    c_important=
  fi

  if [[ $(echo $the_input | grep "[[:space:]]*-h\>") != "" || $(echo $the_input | grep "[[:space:]]*--help\>") != "" ]] ; then
    echo
    echo -e "${c_title}Turtle Kevux Webbrowser Starter$c_reset"
    echo -e " ${c_notice}Version $version$c_reset"
    echo
    echo -e "${c_highlight}webbrowser$c_reset $c_notice[${c_reset}commands$c_notice]$c_reset $c_notice<${c_reset}client_commands$c_notice>$c_reset"
    echo -e " ${c_important}client_commands${c_reset} These are the commands to pass to the webbrowser, such as a website url"
    echo
    echo -e "${c_highlight}Options:$c_reset"
    echo -e " -${c_important}h${c_reset}, --${c_important}help${c_reset}      Print this help screen"
    echo -e " -${c_important}v${c_reset}, --${c_important}version${c_reset}   Print only the version number"
    echo -e " -${c_important}l${c_reset}, --${c_important}light${c_reset}     Use colormodes that show up better on light background"
    echo -e " -${c_important}n${c_reset}, --${c_important}no_color${c_reset}  Do not use color"
    echo
    return_status=0
    return $return_status
  else
    for i in $the_input ; do
      if [[ $grab_next == "" ]] ; then
        if [[ $i == "-v" || $i == "--version" ]] ; then
          return_status=0
          echo $version
          return $return_status
        fi
      fi
    done
  fi
}

execute_program(){
  midori $the_input
}

main ${@}
