From 8d788be43d5941f24a29b355415dac6fba72f864 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Wed, 6 Apr 2011 09:53:29 +0430 Subject: [PATCH] show info with i key --- cnoor.c | 6 ++++-- txtwin.c | 25 +++++++++++++++++++------ txtwin.h | 7 +------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cnoor.c b/cnoor.c index 36c9a41..22171d6 100644 --- a/cnoor.c +++ b/cnoor.c @@ -23,7 +23,7 @@ static void ins_sura(struct txtwin *tw, struct quran *quran, int i; for (i = 0; i < ayas; i++) { int juz = juz_start(sura, i + 1); - enum sajda sajda = sajda_kind(sura, i + 1); + int sajda = sajda_kind(sura, i + 1); if (juz) { sprintf(buf, "%d\n", juz); txtwin_append(tw, buf, "juz"); @@ -55,10 +55,12 @@ static void set_tags(struct txtwin *tw) int show(int sura) { + char name[128]; struct txtwin *tw; struct quran *quran; struct quran *trans = NULL; - tw = txtwin_alloc(); + sprintf(name, "%d(%s)", sura, sura_name(sura)); + tw = txtwin_alloc(name); quran = quran_alloc(QURAN_PATH); if (TRANS_PATH) trans = quran_alloc(TRANS_PATH); diff --git a/txtwin.c b/txtwin.c index 101c855..4e58c0c 100644 --- a/txtwin.c +++ b/txtwin.c @@ -33,9 +33,11 @@ static struct { }; static int ntags = 1; +static char name[128]; static PangoContext *context; static int width = 1; static int height = 1; +static int head; static PangoFontMap *fontmap; static FT_Bitmap *bitmap; static char text[MAXTEXT]; @@ -146,10 +148,17 @@ static int getcount(int def) return result; } +static void printinfo(void) +{ + printf("\x1b[H"); + printf("CNOOR \t\t\t %d%% \t\t\t %s \x1b[K", + head * 100 / height, name); + fflush(stdout); +} + void txtwin_loop(struct txtwin *tw) { int step = fb_rows() / PAGESTEPS; - int head = 0; int c; struct termios oldtermios, termios; tcgetattr(STDIN_FILENO, &termios); @@ -201,6 +210,9 @@ void txtwin_loop(struct txtwin *tw) if (count) head = height * getcount(0) / 100; break; + case 'i': + printinfo(); + continue; default: /* no need to redraw */ continue; @@ -213,27 +225,28 @@ void txtwin_loop(struct txtwin *tw) void txtwin_gtk_init(int argc, char **argv) { char *clear = "\x1b[2J\x1b[H"; - char *msg = "\t\t\t\t***FBPAN***\n"; char *hide = "\x1b[?25l"; g_type_init(); - g_set_prgname("fbpan"); + g_set_prgname("cpan"); setlocale(LC_ALL, ""); write(STDIN_FILENO, clear, strlen(clear)); - write(STDIN_FILENO, msg, strlen(msg)); write(STDIN_FILENO, hide, strlen(hide)); fb_init(); } -struct txtwin *txtwin_alloc() { +struct txtwin *txtwin_alloc(char *sura) +{ fontmap = pango_ft2_font_map_new(); pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fontmap), DPI, DPI); context = pango_font_map_create_context(PANGO_FONT_MAP(fontmap)); + strcpy(name, sura); + printinfo(); return NULL; } void txtwin_free(struct txtwin *tw) { - char *show = "\x1b[?25h"; + char *show = "\x1b[?25h\n"; fb_free(); destroy_bitmap(bitmap); g_object_unref(context); diff --git a/txtwin.h b/txtwin.h index dab717a..f20e077 100644 --- a/txtwin.h +++ b/txtwin.h @@ -1,13 +1,8 @@ -#ifndef _TXTWIN_H -#define _TXTWIN_H - struct txtwin; -struct txtwin *txtwin_alloc(); +struct txtwin *txtwin_alloc(char *name); void txtwin_gtk_init(int argc, char **argv); void txtwin_free(struct txtwin *tw); void txtwin_loop(struct txtwin *tw); void txtwin_append(struct txtwin *tw, char *s, char *tag); void txtwin_tag(struct txtwin *tw, char *name, char *fg, char *bg, char *font); - -#endif -- 2.11.4.GIT