X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=blobdiff_plain;f=bam_tview_html.c;h=8ab3e8a3e04ff8de9ebead34d7b0f5a2ca90a18a;hp=1c75005b9f58a883b43e7b86d2d485d12385f61b;hb=307c147168f7154e3755712797078c513e0b242a;hpb=5193fbf4944f67fd2d2bb0be5a54b5bbd27c5e6b 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); } /*