view ui.h @ 642:c8e5949a8961

Use th-libs functions.
author Matti Hamalainen <>
date Wed, 07 Jan 2015 16:56:54 +0200
parents 5b059a85cab8
children fc19ab0334b1
line wrap: on
line source

 * NNChat - Custom chat client for chatrooms
 * Written by Matti 'ccr' Hämäläinen
 * (C) Copyright 2008-2013 Tecnic Software productions (TNSP)
#ifndef LIBNNUI_H
#define LIBNNUI_H

#ifdef __WIN32
#define SET_DELAY          (0)
// Undefine because both windows.h and curses.h #define it
#define SET_DELAY          (5)

#include <ncurses.h>
#include <curses.h>
#include <time.h>
#include "th_types.h"
#include "th_string.h"
#include "th_network.h"

#define SET_MAX_WINDOWS    (32)        // Max chat buffer windows
#define SET_BACKBUF_LEN    (512)       // Backbuffer size (in lines)

typedef struct
    int *buf;
    size_t len, bufsize;
} nn_line_t;

typedef struct
    qringbuf_t *data;   // "Backbuffer" data for this window
    int pos;            // Current position in the window, 0 = real time
    BOOL dirty;

    int num;
    char *id;           // Chatter ID, NULL = main window

    nn_line_t *line;

    // Logging
    char *logFilename;
    FILE *logFile;
    time_t logPrevMsgTime;
} nn_window_t;

typedef struct
    time_t prevKeepAlive;
    BOOL insertMode, isError, update, mask, done;
    th_conn_t *conn;
    void (*debugMsg)(const char *fmt, ...);
} nn_editstate_t;

extern nn_window_t *currWin;
extern BOOL appCursesInit, appQuitFlag;
extern int scrHeight, scrWidth;

BOOL           nnwin_init(int delay);
void           nnwin_shutdown();
void           nnwin_reset(void);

void           nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *optUserName, int optUserColor);

nn_window_t *  nnwin_main_window();
nn_window_t *  nnwin_get(const int index);
nn_window_t *  nnwin_find(const char *id);
void           nnwin_set_current(nn_window_t *);

BOOL           nnwin_open(const char *name, BOOL curwin);
void           nnwin_close(nn_window_t *win);

int            nnwin_print(nn_window_t *win, const char *fmt);

void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState,
    BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *));

char *         nnwin_prompt_requester(BOOL allowEmpty, nn_editstate_t *,
    BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *),
    void (*update)(nn_editbuf_t *, nn_editstate_t *));

BOOL nn_log_open(nn_window_t *win);
void nn_log_close(nn_window_t *win);