#!/usr/bin/env -S emacs -Q --script
;;; e2ansi-info --- Print face-related info to the terminal -*- emacs-lisp -*-

;; Copyright (C) 2014,2025 Anders Lindgren

;; Author: Anders Lindgren
;; Keywords: faces, languages
;; Created: 2015-01-20
;; URL: https://github.com/Lindydancer/e2ansi

;; 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/>.

;;; Commentary:

;; This is a command line tool using Emacs in batch mode to output
;; various ANSI-related information. This is useful when fine-tuning
;; your terminal.
;;
;; Usage:
;;
;;    e2ansi-info [options] WHAT
;;
;; See the file `e2ansi.el' for more information.

;;; Code:

;; Ensure that the `e2ansi' modules are in the path.
;;
;; `file-truename' enables people to symlink to this file.
(let ((dir (file-name-directory (file-truename load-file-name))))
  (add-to-list 'load-path (concat dir "..")))

(require 'e2ansi-load-init)

;; Ensure that dependencies are found.
(package-initialize)

(require 'e2ansi-list)

(setq e2ansi-batch-help-text "\
Print various ANSI color related information.

Usage:
    e2ansi-info WHAT [options]

Where WHAT is:

    settings  Print face-explorer settings
    ansi16    Print color table of the 16 basic ANSI colors.
    ansi256   Print color tables of the 256 ANSI colors.
    faces     Print a selection of standard faces.
    mbg       Print text with background spanning multiple lines.
")

(if (null command-line-args-left)
    (e2ansi-batch-usage)
  (while command-line-args-left
    (let ((arg (pop command-line-args-left)))
      (cond ((string= arg "settings")
             (princ "Native settings:\n")
             (e2ansi-batch-print-setting)
             (princ "\n")
             (e2ansi-batch-parse-options)
             (princ "Settings after parsing options:\n")
             (e2ansi-batch-print-setting))
            ((string= arg "ansi16")
             (e2ansi-list-print-ansi-colors16))
            ((string= arg "ansi256")
             (e2ansi-list-print-ansi-colors256))
            ((string= arg "faces")
             (e2ansi-batch-parse-options)
             (e2ansi-list-print-ansi-faces))
            ((string= arg "mbg")
             (e2ansi-batch-parse-options)
             (e2ansi-list-print-multiline-text-with-background))
            (t
             (e2ansi-user-error "Unexpected subcommand: %s" arg))))))

;;; e2ansi-info ends here.
