mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add time to status bar
This commit is contained in:
parent
fcdddf11c0
commit
105c9c2943
@ -102,7 +102,7 @@ ui_init(void)
|
|||||||
ui_load_colours();
|
ui_load_colours();
|
||||||
refresh();
|
refresh();
|
||||||
create_title_bar();
|
create_title_bar();
|
||||||
create_status_bar();
|
status_bar_init();
|
||||||
status_bar_active(1);
|
status_bar_active(1);
|
||||||
create_input_window();
|
create_input_window();
|
||||||
wins_init();
|
wins_init();
|
||||||
@ -183,6 +183,7 @@ ui_close(void)
|
|||||||
notifier_uninit();
|
notifier_uninit();
|
||||||
wins_destroy();
|
wins_destroy();
|
||||||
inp_close();
|
inp_close();
|
||||||
|
status_bar_close();
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,14 +51,13 @@
|
|||||||
#include "ui/inputwin.h"
|
#include "ui/inputwin.h"
|
||||||
#include "ui/screen.h"
|
#include "ui/screen.h"
|
||||||
|
|
||||||
#define TIME_CHECK 60000000
|
|
||||||
|
|
||||||
typedef struct _status_bar_t {
|
typedef struct _status_bar_t {
|
||||||
char *time;
|
gchar *time;
|
||||||
char *message;
|
char *message;
|
||||||
GList *tabs;
|
GList *tabs;
|
||||||
} StatusBar;
|
} StatusBar;
|
||||||
|
|
||||||
|
static GTimeZone *tz;
|
||||||
static StatusBar *statusbar;
|
static StatusBar *statusbar;
|
||||||
static WINDOW *statusbar_win;
|
static WINDOW *statusbar_win;
|
||||||
//static char *message = NULL;
|
//static char *message = NULL;
|
||||||
@ -80,13 +79,18 @@ static WINDOW *statusbar_win;
|
|||||||
static void _status_bar_draw(void);
|
static void _status_bar_draw(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
create_status_bar(void)
|
status_bar_init(void)
|
||||||
{
|
{
|
||||||
|
tz = g_time_zone_new_local();
|
||||||
|
|
||||||
statusbar = malloc(sizeof(StatusBar));
|
statusbar = malloc(sizeof(StatusBar));
|
||||||
|
statusbar->time = NULL;
|
||||||
|
|
||||||
int row = screen_statusbar_row();
|
int row = screen_statusbar_row();
|
||||||
int cols = getmaxx(stdscr);
|
int cols = getmaxx(stdscr);
|
||||||
statusbar_win = newwin(1, cols, row, 0);
|
statusbar_win = newwin(1, cols, row, 0);
|
||||||
wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
|
wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
|
||||||
|
|
||||||
_status_bar_draw();
|
_status_bar_draw();
|
||||||
|
|
||||||
// int i;
|
// int i;
|
||||||
@ -122,6 +126,19 @@ create_status_bar(void)
|
|||||||
// _status_bar_draw();
|
// _status_bar_draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
status_bar_close(void)
|
||||||
|
{
|
||||||
|
if (tz) {
|
||||||
|
g_time_zone_unref(tz);
|
||||||
|
}
|
||||||
|
if (statusbar) {
|
||||||
|
if (statusbar->time) {
|
||||||
|
g_free(statusbar->time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
status_bar_update_virtual(void)
|
status_bar_update_virtual(void)
|
||||||
{
|
{
|
||||||
@ -475,6 +492,34 @@ status_bar_clear_message(void)
|
|||||||
static void
|
static void
|
||||||
_status_bar_draw(void)
|
_status_bar_draw(void)
|
||||||
{
|
{
|
||||||
|
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
||||||
|
if (g_strcmp0(time_pref, "off") != 0) {
|
||||||
|
if (statusbar->time) {
|
||||||
|
g_free(statusbar->time);
|
||||||
|
statusbar->time = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GDateTime *datetime = g_date_time_new_now(tz);
|
||||||
|
statusbar->time = g_date_time_format(datetime, time_pref);
|
||||||
|
assert(statusbar->time != NULL);
|
||||||
|
g_date_time_unref(datetime);
|
||||||
|
|
||||||
|
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
|
||||||
|
int time_attrs = theme_attrs(THEME_STATUS_TIME);
|
||||||
|
|
||||||
|
size_t len = strlen(statusbar->time);
|
||||||
|
wattron(statusbar_win, bracket_attrs);
|
||||||
|
mvwaddch(statusbar_win, 0, 1, '[');
|
||||||
|
wattroff(statusbar_win, bracket_attrs);
|
||||||
|
wattron(statusbar_win, time_attrs);
|
||||||
|
mvwprintw(statusbar_win, 0, 2, statusbar->time);
|
||||||
|
wattroff(statusbar_win, time_attrs);
|
||||||
|
wattron(statusbar_win, bracket_attrs);
|
||||||
|
mvwaddch(statusbar_win, 0, 2 + len, ']');
|
||||||
|
wattroff(statusbar_win, bracket_attrs);
|
||||||
|
}
|
||||||
|
prefs_free_string(time_pref);
|
||||||
|
|
||||||
wnoutrefresh(statusbar_win);
|
wnoutrefresh(statusbar_win);
|
||||||
inp_put_back();
|
inp_put_back();
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
#ifndef UI_STATUSBAR_H
|
#ifndef UI_STATUSBAR_H
|
||||||
#define UI_STATUSBAR_H
|
#define UI_STATUSBAR_H
|
||||||
|
|
||||||
void create_status_bar(void);
|
void status_bar_init(void);
|
||||||
|
void status_bar_close(void);
|
||||||
void status_bar_update_virtual(void);
|
void status_bar_update_virtual(void);
|
||||||
void status_bar_resize(void);
|
void status_bar_resize(void);
|
||||||
void status_bar_clear(void);
|
void status_bar_clear(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user