#!/usr/bin/env bash
# -------------------------------------------
#       @script: ia32-64.sh
#         @link: https://bolha.dev/nrzcode/ia32-64
#  @description: Intel® 64 and IA-32 Instruction Set Reference using FZF interface.
#      @license: GNU/GPL v3.0
#      @version: 0.0.1
#       @author: NRZ Code <nrzcode@protonmail.com>
#      @created: 08/07/2025 01:24
#
# @requirements: ---
#         @bugs: ---
#        @notes: ---
#     @revision: ---
# -------------------------------------------
# Copyright (C) 2025   NRZ Code <nrzcode@protonmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------
# USAGE
#   ia32-64.sh [OPTIONS]
# -------------------------------------------
version='0.0.1'
usage='Usage: ia32-64.sh [OPTIONS]

DESCRIPTION
   Intel® 64 and IA-32 Instruction Set Reference using FZF interface

OPTIONS
  General options
    -h, --help        Print this help usage and exit
    -v, --version     Display version information and exit
'
copy='Copyright (C) 2025 NRZ Code <nrzcode@protonmail.com>.
License: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
'

# functions ---------------------------------
check_dependencies() {
    local code=0
    for dep; do
        if ! type -p $dep &>/dev/null; then
            echo "ERROR: ${BASH_SOURCE##*/}: $dep dependency is missing."
            code=1
        fi
    done
    return $code
}

main() {
    fzf_opt=(
        --info inline-right
        --pointer '█'
        --color hl+:red:bold,hl:red:bold
        --color label:gray
        --no-scrollbar
        --border
        --border-label $'┤ \e[1;34mINSTRUÇÕES INTEL 32 E 64 BITS\e[0m ├'
        -e -i
        --reverse
        --prompt ': '
        --tiebreak begin
        --tabstop 24
        -d '|'
        --with-nth $'{1} \t- {2}'
        --preview 'w3m -cols $(tput cols) -o display_border=1 {3}.html'
        --preview-window bottom,70%,border-top
        --bind 'enter:become(w3m -o display_border=1 {3}.html),esc:become(true)'
    )
    fzf "${fzf_opt[@]}" < ../inst.list
}

# main --------------------------------------
check_dependencies fzf w3m || exit 1
workdir=$(dirname $BASH_SOURCE)
cd $workdir/x86
[[ $BASH_SOURCE == $0 ]] && main "$@"
