<commit_before>class Newt < Formula
  desc "Library for color text mode, widget based user interfaces"
  homepage "https://pagure.io/newt"
  url "https://releases.pagure.org/newt/newt-0.52.21.tar.gz"
  sha256 "265eb46b55d7eaeb887fca7a1d51fe115658882dfe148164b6c49fccac5abb31"
  license "LGPL-2.0-or-later"
  revision 1

  livecheck do
    url "https://releases.pagure.org/newt/"
    regex(/href=.*?newt[._-]v?(\d+(?:\.\d+)+)\.t/i)
  end

  bottle do
    sha256 cellar: :any,                 arm64_monterey: "ba9ab9973ca7804fceda2fbdb82b2ce93486f855f6310d3ef739045a2d6cdede"
    sha256 cellar: :any,                 arm64_big_sur:  "6c795ee83da9eeaa36c30296b15ea5383c7d0d49d6f8128baac3f25ea41a09e6"
    sha256 cellar: :any,                 monterey:       "f798d2745a79ce24fbda942067341e83c6ceba3717eeacf5aa95b861fb64a1e8"
    sha256 cellar: :any,                 big_sur:        "b4b973be7df201c92b09765adb2aa821157d334e271dd0d73d853229eacdd27c"
    sha256 cellar: :any,                 catalina:       "7a3f57dddb0be9c1f628638ce67f794c1cf33472d09bc48af7f9c60db92f18f1"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "b91288367ad2b36bc9054fe9800f04f1c0bca7fd3d4232f86e5504520fa97ccc"
  end

  depends_on "gettext"
  depends_on "popt"
  depends_on "s-lang"

  on_linux do
    depends_on "python@3.10"
  end

  def install
    args = ["--prefix=#{prefix}", "--without-tcl"]

    if OS.mac?
      inreplace "Makefile.in" do |s|
        # name libraries correctly
        # https://bugzilla.redhat.com/show_bug.cgi?id=1192285
        s.gsub! "libnewt.$(SOEXT).$(SONAME)", "libnewt.$(SONAME).dylib"
        s.gsub! "libnewt.$(SOEXT).$(VERSION)", "libnewt.$(VERSION).dylib"

        # don't link to libpython.dylib
        # causes https://github.com/Homebrew/homebrew/issues/30252
        # https://bugzilla.redhat.com/show_bug.cgi?id=1192286
        s.gsub! "`$$pyconfig --ldflags`", '"-undefined dynamic_lookup"'
        s.gsub! "`$$pyconfig --libs`", '""'
      end
    end

    system "./configure", *args
    system "make", "install"
  end

  test do
    ENV["TERM"] = "xterm"
    (testpath/"test.c").write <<~EOS<commit_msg>newt: install Python binding<commit_after>class Newt < Formula
  desc "Library for color text mode, widget based user interfaces"
  homepage "https://pagure.io/newt"
  url "https://releases.pagure.org/newt/newt-0.52.21.tar.gz"
  sha256 "265eb46b55d7eaeb887fca7a1d51fe115658882dfe148164b6c49fccac5abb31"
  license "LGPL-2.0-or-later"
  revision 2

  livecheck do
    url "https://releases.pagure.org/newt/"
    regex(/href=.*?newt[._-]v?(\d+(?:\.\d+)+)\.t/i)
  end

  bottle do
    sha256 cellar: :any,                 arm64_monterey: "ba9ab9973ca7804fceda2fbdb82b2ce93486f855f6310d3ef739045a2d6cdede"
    sha256 cellar: :any,                 arm64_big_sur:  "6c795ee83da9eeaa36c30296b15ea5383c7d0d49d6f8128baac3f25ea41a09e6"
    sha256 cellar: :any,                 monterey:       "f798d2745a79ce24fbda942067341e83c6ceba3717eeacf5aa95b861fb64a1e8"
    sha256 cellar: :any,                 big_sur:        "b4b973be7df201c92b09765adb2aa821157d334e271dd0d73d853229eacdd27c"
    sha256 cellar: :any,                 catalina:       "7a3f57dddb0be9c1f628638ce67f794c1cf33472d09bc48af7f9c60db92f18f1"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "b91288367ad2b36bc9054fe9800f04f1c0bca7fd3d4232f86e5504520fa97ccc"
  end

  depends_on "gettext"
  depends_on "popt"
  depends_on "python@3.10"
  depends_on "s-lang"

  def install
    xy = Language::Python.major_minor_version("python3")
    args = %W[--prefix=#{prefix} --without-tcl --with-python=python#{xy}]

    if OS.mac?
      inreplace "Makefile.in" do |s|
        # name libraries correctly
        # https://bugzilla.redhat.com/show_bug.cgi?id=1192285
        s.gsub! "libnewt.$(SOEXT).$(SONAME)", "libnewt.$(SONAME).dylib"
        s.gsub! "libnewt.$(SOEXT).$(VERSION)", "libnewt.$(VERSION).dylib"

        # don't link to libpython.dylib
        # causes https://github.com/Homebrew/homebrew/issues/30252
        # https://bugzilla.redhat.com/show_bug.cgi?id=1192286
        s.gsub! "`$$pyconfig --ldflags`", '"-undefined dynamic_lookup"'
        s.gsub! "`$$pyconfig --libs`", '""'
      end
    end

    system "./configure", *args
    system "make", "install"
  end

  test do
    ENV["TERM"] = "xterm"
    system Formula["python@3.10"].opt_bin/"python3", "-c", "import snack"

    (testpath/"test.c").write <<~EOS
{'fraction_non_alphanumeric': 0.13153724247226625, 'fraction_numerical': 0.14557391894951324, 'mean_word_length': 3.2156488549618323, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2304873', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1821, 'n_words': 255}