/* 
 * front/cursio.h
 *   Interface of generic curses IO interface
 *   (nope, it is not using curses, pure ANSI ;-)
 *   It's main piece is io_color() - it converts IRC string to terminal-ready
 *   one - so it expands ^C, ^V and ^B control chars to appropriate control
 *   sequences. Further explanation of ^C color control can be found in
 *   cursio.c - i spent one whole day by examining it and asking around whole
 *   IRC for it chaotic meaning (nope, i didn't found a definitive answer).
 *
 * $Id: cursio.h,v 1.1.1.1 2002/01/24 20:19:48 sembera Exp $
 */
/*
 * IIRC - IIRC Is a Real Client (Modular IRC Client)
 * Copyright (C) 2001  Jan Sembera <fis@ji.cz>
 * Copyright (C) 2001  Petr Baudis <pasky@ji.cz>
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IIRC_FRONT_CUSRIO
#define __IIRC_FRONT_CURSIO

#include<stdio.h>

extern int io_init();
extern int io_done();

extern int io_maxx();
extern int io_maxy();

static int io_cls(); /* CLear Screen */
extern int io_cls_(char *);

static int io_cle(); /* CLear to EOLN */
extern int io_cle_(char *);

static int io_move(int y, int x); /* Move cursor */
extern int io_move_(char *, int, int);

static int io_color(int fg, int bg, int bold, int inverse); /* Change attributes */
extern int io_color_(char *, int, int, int, int);

extern int _cprintf(char *, ...); /* Color printf */
extern int _csprintf(char *, char *, ...);

extern int io_ansi_strlen(char *);

/* inline wrappers */


/* to restore defaults, use -1, -1, 0, 0 */
static inline int io_color(int fg, int bg, int bold, int inverse)
{
  char buf[1024];
  
  buf[0] = 0;
  io_color_(buf, fg, bg, bold, inverse);
  fputs(buf, stdout);

  return 0;
}

static inline int io_move(int y, int x)
{
  char buf[16];

  buf[0] = 0;
  io_move_(buf, y, x);
  fputs(buf, stdout);

  return 0;
}

static inline int io_wrapper(int (*call)())
{
  char buf[16];

  buf[0] = 0;
  call(buf);
  fputs(buf, stdout);

  return 0;
}

static inline int io_cls() { return io_wrapper(&io_cls_); }
static inline int io_cle() { return io_wrapper(&io_cle_); }

#endif
