From 307c147168f7154e3755712797078c513e0b242a Mon Sep 17 00:00:00 2001 From: lindenb Date: Fri, 25 Jan 2013 15:12:12 +0100 Subject: [PATCH] works --- bam_tview.c | 5 +++ bam_tview_html.c | 112 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 101 insertions(+), 16 deletions(-) diff --git a/bam_tview.c b/bam_tview.c index 81afdfd..6184213 100644 --- a/bam_tview.c +++ b/bam_tview.c @@ -302,6 +302,7 @@ static void error(const char *format, ...) enum dipsay_mode {display_ncurses,display_html,display_text}; extern tview_t* curses_tv_init(const char *fn, const char *fn_fa, const char *samples); extern tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples); +extern tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples); int bam_tview_main(int argc, char *argv[]) { int view_mode=display_ncurses; @@ -336,6 +337,10 @@ int bam_tview_main(int argc, char *argv[]) break; } case display_text: + { + tv = text_tv_init(argv[optind], (optind+1>=argc)? 0 : argv[optind+1], samples); + break; + } case display_html: { tv = html_tv_init(argv[optind], (optind+1>=argc)? 0 : argv[optind+1], samples); diff --git a/bam_tview_html.c b/bam_tview_html.c index 1c75005..8ab3e8a 100644 --- a/bam_tview_html.c +++ b/bam_tview_html.c @@ -1,5 +1,8 @@ +#include #include "bam_tview.h" +#define UNDERLINE_FLAG 10 + typedef struct HtmlTview { tview_t view; int row_count; @@ -72,13 +75,15 @@ static void html_mvaddch(struct AbstractTview* tv,int y,int x,int ch) static void html_attron(struct AbstractTview* tv,int flag) { html_tview_t* ptr=FROM_TV(tv); - ptr->attributes |= 1 << flag; + ptr->attributes |= flag; + + } static void html_attroff(struct AbstractTview* tv,int flag) { html_tview_t* ptr=FROM_TV(tv); - ptr->attributes &= ~(1 << flag); + ptr->attributes &= ~(flag); } static void html_clear(struct AbstractTview* tv) @@ -97,7 +102,7 @@ static void html_clear(struct AbstractTview* tv) static int html_colorpair(struct AbstractTview* tv,int flag) { - return flag; + return (1 << (flag)); } static int html_drawaln(struct AbstractTview* tv, int tid, int pos) @@ -107,9 +112,16 @@ static int html_drawaln(struct AbstractTview* tv, int tid, int pos) html_clear(tv); base_draw_aln(tv, tid, pos); fputs("",ptr->out); - + fprintf(ptr->out,"%s:%d", + tv->header->target_name[tid], + pos+1 + ); //style - fputs("",ptr->out); fputs("",ptr->out); - fputs("
\n",ptr->out);
+    
+      fprintf(ptr->out,"
%s:%d
", + tv->header->target_name[tid], + pos+1 + ); + + fputs("
",ptr->out);
     for(y=0;y< ptr->row_count;++y)
     	{
     	
@@ -133,21 +151,27 @@ static int html_drawaln(struct AbstractTview* tv, int tid, int pos)
 	    	{
 	    	
 		
-		if(x== 0 || ptr->screen[y][x].attributes!=ptr->screen[y][x-1].attributes)
+		if(x== 0 || ptr->screen[y][x].attributes != ptr->screen[y][x-1].attributes)
 	    		{
 	    		int css=0;
-	    		fputs("screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)) )!=0?"u":""),
+	    					css);
+	    				fputs("'",ptr->out);
 	    				break;
 	    				}
 	    			++css;
 	    			}
-	    		if(css>=10) css=0;
-	    		fprintf(ptr->out,"tviewc%d",css);
-	    		fputs("'>",ptr->out);
+
+
+	    		fputs(">",ptr->out);
 	    		}
 		
 		int ch=ptr->screen[y][x].ch;
@@ -167,23 +191,79 @@ static int html_drawaln(struct AbstractTview* tv, int tid, int pos)
 	    	}
     	if(y+1 < ptr->row_count) fputs("
",ptr->out); } - fputs("
",ptr->out); + fputs("
",ptr->out); return 0; } + +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_YELLOW "\x1b[33m" +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_MAGENTA "\x1b[35m" +#define ANSI_COLOR_CYAN "\x1b[36m" +#define ANSI_COLOR_BLACK "\x1b[0m" +#define ANSI_COLOR_RESET ANSI_COLOR_BLACK + +#define ANSI_UNDERLINE_SET "\033[4m" +#define ANSI_UNDERLINE_UNSET "\033[0m" + static int text_drawaln(struct AbstractTview* tv, int tid, int pos) { int y,x; html_tview_t* ptr=FROM_TV(tv); html_clear(tv); - base_draw_aln(tv, tid, pos); + base_draw_aln(tv, tid, pos); + int is_term= isatty(fileno(ptr->out)); + for(y=0;y< ptr->row_count;++y) { for(x=0;x< tv->mcol;++x) { + if(is_term) + { + int css=0; + while(css<32) + { + if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0) + { + break; + } + ++css; + } + switch(css) + { + //CSS(0, "black"); + case 1: fputs(ANSI_COLOR_BLUE,ptr->out); break; + case 2: fputs(ANSI_COLOR_GREEN,ptr->out); break; + case 3: fputs(ANSI_COLOR_YELLOW,ptr->out); break; + //CSS(4, "black"); + case 5: fputs(ANSI_COLOR_GREEN,ptr->out); break; + case 6: fputs(ANSI_COLOR_CYAN,ptr->out); break; + case 7: fputs(ANSI_COLOR_YELLOW,ptr->out); break; + case 8: fputs(ANSI_COLOR_RED,ptr->out); break; + case 9: fputs(ANSI_COLOR_BLUE,ptr->out); break; + default:break; + } + if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) + { + fputs(ANSI_UNDERLINE_SET,ptr->out); + } + + } + + int ch=ptr->screen[y][x].ch; fputc(ch,ptr->out); + if(is_term) + { + fputs(ANSI_COLOR_RESET,ptr->out); + if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) + { + fputs(ANSI_UNDERLINE_UNSET,ptr->out); + } + } } fputc('\n',ptr->out); } @@ -199,7 +279,7 @@ static int html_loop(tview_t* tv) static int html_underline(tview_t* tv) { - return 11; + return (1 << UNDERLINE_FLAG); } /* -- 2.39.2