diff --git a/Makefile b/Makefile index 176c8bb4..98a029d5 100644 --- a/Makefile +++ b/Makefile @@ -2,18 +2,20 @@ CC = gcc WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable LIBS = -lxml2 -lssl -lresolv -lncurses -lstrophe 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) $(CC) -o profanity $(OBJS) $(LIBS) log.o: log.h -windows.o: windows.h +windows.o: windows.h util.h title_bar.o: windows.h input_bar.o: windows.h input_win.o: windows.h jabber.o: jabber.h log.h windows.h app.o: log.h windows.h jabber.h +util.o: util.h profanity.o: log.h windows.h app.h .PHONY: clean diff --git a/console_win.c b/console_win.c deleted file mode 100644 index b303d0e3..00000000 --- a/console_win.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#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); -} - diff --git a/util.c b/util.c new file mode 100644 index 00000000..08737ee9 --- /dev/null +++ b/util.c @@ -0,0 +1,13 @@ +#include + +void get_time(char *thetime) +{ + time_t rawtime; + struct tm *timeinfo; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + strftime(thetime, 80, "%H:%M", timeinfo); +} + diff --git a/util.h b/util.h new file mode 100644 index 00000000..d37d981b --- /dev/null +++ b/util.h @@ -0,0 +1,6 @@ +#ifndef UTIL_H +#define UTIL_H + +void get_time(char *thetime); + +#endif diff --git a/windows.c b/windows.c index 629d98bf..7f9c54bf 100644 --- a/windows.c +++ b/windows.c @@ -1,6 +1,7 @@ #include #include #include "windows.h" +#include "util.h" static struct prof_win wins[10]; static int curr_win = 0; @@ -71,8 +72,15 @@ void get_recipient(char *recipient) void show_incomming_msg(char *from, char *message) { + char from_cpy[100]; + strcpy(from_cpy, from); + 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 int i; @@ -120,7 +128,9 @@ void show_incomming_msg(char *from, char *message) void show_outgoing_msg(char *from, char* message) { 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); touchwin(wins[curr_win].win); @@ -129,10 +139,14 @@ void show_outgoing_msg(char *from, char* message) void cons_help(void) { - waddstr(wins[9].win, "Help\n"); - waddstr(wins[0].win, "----\n"); - waddstr(wins[0].win, "/quit - Quits Profanity.\n"); - waddstr(wins[0].win, "/connect - Login to jabber.\n"); + char tstmp[80]; + get_time(tstmp); + + 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 - Login to jabber.\n", tstmp); + wprintw(wins[0].win, " [%s] /quit - Quits Profanity.\n", tstmp); // if its the current window, draw it if (curr_win == 0) { @@ -143,7 +157,10 @@ void cons_help(void) 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 (curr_win == 0) { @@ -162,8 +179,11 @@ static void create_windows(void) strcpy(cons.from, "_cons"); cons.win = newwin(rows-3, cols, 1, 0); scrollok(cons.win, TRUE); + + char tstmp[80]; + get_time(tstmp); - waddstr(cons.win, "Welcome to Profanity.\n"); + wprintw(cons.win, " [%s] Welcome to Profanity.\n", tstmp); touchwin(cons.win); wrefresh(cons.win); wins[0] = cons;