/* term-if.h -- Simple terminal interface for unit tests.  */

/* Copyright (C) 2020, 2021, 2022, 2023, 2024, 2025, 2026 Jose E.
 * Marchesi */

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

#include <config.h>
#include <stdio.h>

static void
pk_term_flush (pk_compiler pkc __attribute__ ((unused)))
{
}

void
pk_puts (pk_compiler pkc __attribute__ ((unused)), const char *str)
{
  printf ("%s", str);
}

__attribute__ ((__format__ (__printf__, 2, 3))) void
pk_printf (pk_compiler pkc __attribute__ ((unused)), const char *format, ...)
{
  va_list ap;

  va_start (ap, format);
  vprintf (format, ap);
  va_end (ap);
}

void
pk_term_indent (pk_compiler pkc __attribute__ ((unused)), unsigned int lvl,
                unsigned int step)
{
  printf ("\n%*s", (step * lvl), "");
}

void
pk_term_class (pk_compiler pkc __attribute__ ((unused)), const char *class)
{
}

int
pk_term_end_class (pk_compiler pkc __attribute__ ((unused)), const char *class)
{
  return 1;
}

void
pk_term_hyperlink (pk_compiler pkc __attribute__ ((unused)), const char *url,
                   const char *id)
{
}

int
pk_term_end_hyperlink (pk_compiler pkc __attribute__ ((unused)))
{
  return 1;
}

struct pk_color
pk_term_get_color (pk_compiler pkc __attribute__ ((unused)))
{
  struct pk_color inv = { -1, -1, -1 };
  return inv;
}

struct pk_color
pk_term_get_bgcolor (pk_compiler pkc __attribute__ ((unused)))
{
  struct pk_color inv = { -1, -1, -1 };
  return inv;
}

void
pk_term_set_color (pk_compiler pkc __attribute__ ((unused)),
                   struct pk_color color)
{
}

void
pk_term_set_bgcolor (pk_compiler pkc __attribute__ ((unused)),
                     struct pk_color color)
{
}

static struct pk_term_if poke_term_if =
  {
    .flush_fn = pk_term_flush,
    .puts_fn = pk_puts,
    .printf_fn = pk_printf,
    .indent_fn = pk_term_indent,
    .class_fn = pk_term_class,
    .end_class_fn = pk_term_end_class,
    .hyperlink_fn = pk_term_hyperlink,
    .end_hyperlink_fn = pk_term_end_hyperlink,
    .get_color_fn = pk_term_get_color,
    .get_bgcolor_fn = pk_term_get_bgcolor,
    .set_color_fn = pk_term_set_color,
    .set_bgcolor_fn = pk_term_set_bgcolor,
  };
