mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-28 12:56:21 +00:00
Time output
This commit is contained in:
6
Makefile
6
Makefile
@@ -2,18 +2,20 @@ 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 windows.o title_bar.o input_bar.o input_win.o jabber.o app.o profanity.o
|
OBJS = log.o windows.o title_bar.o input_bar.o input_win.o jabber.o app.o \
|
||||||
|
profanity.o util.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
|
windows.o: windows.h util.h
|
||||||
title_bar.o: windows.h
|
title_bar.o: windows.h
|
||||||
input_bar.o: windows.h
|
input_bar.o: windows.h
|
||||||
input_win.o: windows.h
|
input_win.o: windows.h
|
||||||
jabber.o: jabber.h log.h windows.h
|
jabber.o: jabber.h log.h windows.h
|
||||||
app.o: log.h windows.h jabber.h
|
app.o: log.h windows.h jabber.h
|
||||||
|
util.o: util.h
|
||||||
profanity.o: log.h windows.h app.h
|
profanity.o: log.h windows.h app.h
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#include <ncurses.h>
|
|
||||||
#include "windows.h"
|
|
||||||
|
|
||||||
static WINDOW *cons_win;
|
|
||||||
|
|
||||||
void create_console_window(void)
|
|
||||||
{
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
cons_win = newwin(rows-3, cols, 1, 0);
|
|
||||||
scrollok(cons_win, TRUE);
|
|
||||||
|
|
||||||
waddstr(cons_win, "Welcome to Profanity.\n");
|
|
||||||
touchwin(cons_win);
|
|
||||||
wrefresh(cons_win);
|
|
||||||
}
|
|
||||||
|
|
||||||
13
util.c
Normal file
13
util.c
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
void get_time(char *thetime)
|
||||||
|
{
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm *timeinfo;
|
||||||
|
|
||||||
|
time(&rawtime);
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
|
strftime(thetime, 80, "%H:%M", timeinfo);
|
||||||
|
}
|
||||||
|
|
||||||
6
util.h
Normal file
6
util.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef UTIL_H
|
||||||
|
#define UTIL_H
|
||||||
|
|
||||||
|
void get_time(char *thetime);
|
||||||
|
|
||||||
|
#endif
|
||||||
36
windows.c
36
windows.c
@@ -1,6 +1,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static struct prof_win wins[10];
|
static struct prof_win wins[10];
|
||||||
static int curr_win = 0;
|
static int curr_win = 0;
|
||||||
@@ -71,8 +72,15 @@ void get_recipient(char *recipient)
|
|||||||
|
|
||||||
void show_incomming_msg(char *from, char *message)
|
void show_incomming_msg(char *from, char *message)
|
||||||
{
|
{
|
||||||
|
char from_cpy[100];
|
||||||
|
strcpy(from_cpy, from);
|
||||||
|
|
||||||
char line[100];
|
char line[100];
|
||||||
sprintf(line, "%s: %s\n", from, message);
|
char *short_from = strtok(from_cpy, "@");
|
||||||
|
char tstmp[80];
|
||||||
|
get_time(tstmp);
|
||||||
|
|
||||||
|
sprintf(line, " [%s] %s: %s\n", tstmp, short_from, message);
|
||||||
|
|
||||||
// find the chat window for sender
|
// find the chat window for sender
|
||||||
int i;
|
int i;
|
||||||
@@ -120,7 +128,9 @@ void show_incomming_msg(char *from, char *message)
|
|||||||
void show_outgoing_msg(char *from, char* message)
|
void show_outgoing_msg(char *from, char* message)
|
||||||
{
|
{
|
||||||
char line[100];
|
char line[100];
|
||||||
sprintf(line, "%s: %s\n", from, message);
|
char tstmp[80];
|
||||||
|
get_time(tstmp);
|
||||||
|
sprintf(line, " [%s] %s: %s\n", tstmp, from, message);
|
||||||
|
|
||||||
wprintw(wins[curr_win].win, line);
|
wprintw(wins[curr_win].win, line);
|
||||||
touchwin(wins[curr_win].win);
|
touchwin(wins[curr_win].win);
|
||||||
@@ -129,10 +139,14 @@ void show_outgoing_msg(char *from, char* message)
|
|||||||
|
|
||||||
void cons_help(void)
|
void cons_help(void)
|
||||||
{
|
{
|
||||||
waddstr(wins[9].win, "Help\n");
|
char tstmp[80];
|
||||||
waddstr(wins[0].win, "----\n");
|
get_time(tstmp);
|
||||||
waddstr(wins[0].win, "/quit - Quits Profanity.\n");
|
|
||||||
waddstr(wins[0].win, "/connect <username@host> - Login to jabber.\n");
|
wprintw(wins[0].win, " [%s] Help\n", tstmp);
|
||||||
|
wprintw(wins[0].win, " [%s] ----\n", tstmp);
|
||||||
|
wprintw(wins[0].win, " [%s] /help - This help.\n", tstmp);
|
||||||
|
wprintw(wins[0].win, " [%s] /connect <username@host> - Login to jabber.\n", tstmp);
|
||||||
|
wprintw(wins[0].win, " [%s] /quit - Quits Profanity.\n", tstmp);
|
||||||
|
|
||||||
// if its the current window, draw it
|
// if its the current window, draw it
|
||||||
if (curr_win == 0) {
|
if (curr_win == 0) {
|
||||||
@@ -143,7 +157,10 @@ void cons_help(void)
|
|||||||
|
|
||||||
void cons_bad_command(char *cmd)
|
void cons_bad_command(char *cmd)
|
||||||
{
|
{
|
||||||
wprintw(wins[0].win, "Unknown command: %s\n", cmd);
|
char tstmp[80];
|
||||||
|
get_time(tstmp);
|
||||||
|
|
||||||
|
wprintw(wins[0].win, " [%s] Unknown command: %s\n", tstmp, cmd);
|
||||||
|
|
||||||
// if its the current window, draw it
|
// if its the current window, draw it
|
||||||
if (curr_win == 0) {
|
if (curr_win == 0) {
|
||||||
@@ -163,7 +180,10 @@ static void create_windows(void)
|
|||||||
cons.win = newwin(rows-3, cols, 1, 0);
|
cons.win = newwin(rows-3, cols, 1, 0);
|
||||||
scrollok(cons.win, TRUE);
|
scrollok(cons.win, TRUE);
|
||||||
|
|
||||||
waddstr(cons.win, "Welcome to Profanity.\n");
|
char tstmp[80];
|
||||||
|
get_time(tstmp);
|
||||||
|
|
||||||
|
wprintw(cons.win, " [%s] Welcome to Profanity.\n", tstmp);
|
||||||
touchwin(cons.win);
|
touchwin(cons.win);
|
||||||
wrefresh(cons.win);
|
wrefresh(cons.win);
|
||||||
wins[0] = cons;
|
wins[0] = cons;
|
||||||
|
|||||||
Reference in New Issue
Block a user