mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-08-01 05:26:21 +00:00
Split out window functions
This commit is contained in:
3
Makefile
3
Makefile
@@ -2,12 +2,13 @@ CC = gcc
|
|||||||
WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
|
WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
|
||||||
LIBS = -lxml2 -lssl -lresolv -lncurses -lstrophe
|
LIBS = -lxml2 -lssl -lresolv -lncurses -lstrophe
|
||||||
CFLAGS = -O3 $(WARNS) $(LIBS)
|
CFLAGS = -O3 $(WARNS) $(LIBS)
|
||||||
OBJS = log.o profanity.o
|
OBJS = log.o windows.o profanity.o
|
||||||
|
|
||||||
profanity: $(OBJS)
|
profanity: $(OBJS)
|
||||||
$(CC) -o profanity $(OBJS) $(LIBS)
|
$(CC) -o profanity $(OBJS) $(LIBS)
|
||||||
|
|
||||||
log.o: log.h
|
log.o: log.h
|
||||||
|
windows.o: windows.h
|
||||||
profanity.o: log.h
|
profanity.o: log.h
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|||||||
1
log.h
1
log.h
@@ -1,7 +1,6 @@
|
|||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
// log
|
|
||||||
FILE *logp;
|
FILE *logp;
|
||||||
|
|
||||||
xmpp_log_t *xmpp_get_file_logger();
|
xmpp_log_t *xmpp_get_file_logger();
|
||||||
|
|||||||
59
profanity.c
59
profanity.c
@@ -6,6 +6,7 @@
|
|||||||
#include <strophe/strophe.h>
|
#include <strophe/strophe.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "windows.h"
|
||||||
|
|
||||||
// refernce to log
|
// refernce to log
|
||||||
extern FILE *logp;
|
extern FILE *logp;
|
||||||
@@ -13,11 +14,11 @@ extern FILE *logp;
|
|||||||
// area for log message in profanity
|
// area for log message in profanity
|
||||||
static const char *prof = "prof";
|
static const char *prof = "prof";
|
||||||
|
|
||||||
// static windows
|
// window references
|
||||||
static WINDOW *title_bar;
|
extern WINDOW *title_bar;
|
||||||
static WINDOW *cmd_bar;
|
extern WINDOW *cmd_bar;
|
||||||
static WINDOW *cmd_win;
|
extern WINDOW *cmd_win;
|
||||||
static WINDOW *main_win;
|
extern WINDOW *main_win;
|
||||||
|
|
||||||
// message handlers
|
// message handlers
|
||||||
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
@@ -30,18 +31,8 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
|||||||
|
|
||||||
// curses functions
|
// curses functions
|
||||||
void init(void);
|
void init(void);
|
||||||
void create_title_bar(void);
|
|
||||||
void create_command_bar(void);
|
|
||||||
void create_command_window(void);
|
|
||||||
void create_main_window(void);
|
|
||||||
|
|
||||||
void event_loop(xmpp_ctx_t *ctx, xmpp_conn_t *conn);
|
void event_loop(xmpp_ctx_t *ctx, xmpp_conn_t *conn);
|
||||||
|
|
||||||
struct receiver {
|
|
||||||
xmpp_ctx_t *ctx;
|
|
||||||
xmpp_conn_t *conn;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
char cmd[50];
|
char cmd[50];
|
||||||
@@ -269,41 +260,3 @@ void init(void)
|
|||||||
attron(A_BOLD);
|
attron(A_BOLD);
|
||||||
attron(COLOR_PAIR(1));
|
attron(COLOR_PAIR(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_title_bar(void)
|
|
||||||
{
|
|
||||||
char *title = "Profanity";
|
|
||||||
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
title_bar = newwin(1, cols, 0, 0);
|
|
||||||
wbkgd(title_bar, COLOR_PAIR(3));
|
|
||||||
mvwprintw(title_bar, 0, 0, title);
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_command_bar(void)
|
|
||||||
{
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
cmd_bar = newwin(1, cols, rows-2, 0);
|
|
||||||
wbkgd(cmd_bar, COLOR_PAIR(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_command_window(void)
|
|
||||||
{
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
cmd_win = newwin(1, cols, rows-1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_main_window(void)
|
|
||||||
{
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
main_win = newwin(rows-3, cols, 1, 0);
|
|
||||||
scrollok(main_win, TRUE);
|
|
||||||
}
|
|
||||||
|
|||||||
47
windows.c
Normal file
47
windows.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
#include "windows.h"
|
||||||
|
|
||||||
|
// window references
|
||||||
|
extern WINDOW *title_bar;
|
||||||
|
extern WINDOW *cmd_bar;
|
||||||
|
extern WINDOW *cmd_win;
|
||||||
|
extern WINDOW *main_win;
|
||||||
|
|
||||||
|
void create_title_bar(void)
|
||||||
|
{
|
||||||
|
char *title = "Profanity";
|
||||||
|
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
|
title_bar = newwin(1, cols, 0, 0);
|
||||||
|
wbkgd(title_bar, COLOR_PAIR(3));
|
||||||
|
mvwprintw(title_bar, 0, 0, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_command_bar(void)
|
||||||
|
{
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
|
cmd_bar = newwin(1, cols, rows-2, 0);
|
||||||
|
wbkgd(cmd_bar, COLOR_PAIR(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_command_window(void)
|
||||||
|
{
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
|
cmd_win = newwin(1, cols, rows-1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_main_window(void)
|
||||||
|
{
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
|
main_win = newwin(rows-3, cols, 1, 0);
|
||||||
|
scrollok(main_win, TRUE);
|
||||||
|
}
|
||||||
16
windows.h
Normal file
16
windows.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WINDOWS_H
|
||||||
|
#define WINDOWS_h
|
||||||
|
|
||||||
|
// windows
|
||||||
|
WINDOW *title_bar;
|
||||||
|
WINDOW *cmd_bar;
|
||||||
|
WINDOW *cmd_win;
|
||||||
|
WINDOW *main_win;
|
||||||
|
|
||||||
|
// window creation
|
||||||
|
void create_title_bar(void);
|
||||||
|
void create_command_bar(void);
|
||||||
|
void create_command_window(void);
|
||||||
|
void create_main_window(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user