From 1bdc0794c25967da86e798ebcfd51c2a5891ebc8 Mon Sep 17 00:00:00 2001 From: lindenb Date: Fri, 25 Jan 2013 09:08:19 +0100 Subject: [PATCH] works with curses --- bam_tview.h | 2 +- bam_tview_curses.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bam_tview.h b/bam_tview.h index 2f395ff..c9952c9 100644 --- a/bam_tview.h +++ b/bam_tview.h @@ -29,7 +29,7 @@ typedef struct AbstractTview { char *ref; khash_t(kh_rg) *rg_hash; /* callbacks */ - void (*destroy)(struct AbstractTview* ); + void (*my_destroy)(struct AbstractTview* ); void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); void (*my_mvaddch)(struct AbstractTview*,int,int,int); void (*my_attron)(struct AbstractTview*,int); diff --git a/bam_tview_curses.c b/bam_tview_curses.c index 0c18ac7..7ccf64b 100644 --- a/bam_tview_curses.c +++ b/bam_tview_curses.c @@ -1,9 +1,9 @@ #include "bam_tview_curses.h" +#define FROM_TV(ptr) ((curses_tview_t*)ptr) - -static void curses_tv_destroy(tview_t* base) +static void curses_destroy(tview_t* base) { curses_tview_t* tv=(curses_tview_t*)base; @@ -27,22 +27,37 @@ static void curses_tv_destroy(tview_t* base) static void curses_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...) { + unsigned int size=tv->mcol+2; + char* str=malloc(size); + va_list argptr; + va_start(argptr, fmt); + vsnprintf(str,size, fmt, argptr); + va_end(argptr); + mvprintw(y,x,str); + free(str); } + static void curses_mvaddch(struct AbstractTview* tv,int y,int x,int ch) - { - } + { + mvaddch(y,x,ch); + } + static void curses_attron(struct AbstractTview* tv,int flag) { + attron(flag); } static void curses_attroff(struct AbstractTview* tv,int flag) { + attroff(flag); } static void curses_clear(struct AbstractTview* tv) { + clear(); } static int curses_colorpair(struct AbstractTview* tv,int flag) { + return COLOR_PAIR(flag); } @@ -268,7 +283,7 @@ int bam_tview_main(int argc, char *argv[]) } tv_draw_aln(tv, tv->curr_tid, tv->left_pos); tv_loop(CTV); - tv->destroy(tv); - free(tv); + tv->my_destroy(tv); + return 0; } -- 2.39.2