%s:%d
",
tv->header->target_name[tid],
pos+1
);
fputs("
",ptr->out);
for(y=0;y< ptr->row_count;++y)
{
for(x=0;x< tv->mcol;++x)
{
if(x== 0 || ptr->screen[y][x].attributes != ptr->screen[y][x-1].attributes)
{
int css=0;
fprintf(ptr->out,"1) fprintf(stderr,"css=%d pow2=%d vs %d\n",css,(1 << (css)),ptr->screen[y][x].attributes);
if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0)
{
fprintf(ptr->out," class='tviewc%s%d'",
(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)) )!=0?"u":""),
css);
break;
}
++css;
}
fputs(">",ptr->out);
}
int ch=ptr->screen[y][x].ch;
switch(ch)
{
case '<': fputs("<",ptr->out);break;
case '>': fputs(">",ptr->out);break;
case '&': fputs("&",ptr->out);break;
default: fputc(ch,ptr->out); break;
}
if(x+1 == tv->mcol || ptr->screen[y][x].attributes!=ptr->screen[y][x+1].attributes)
{
fputs("",ptr->out);
}
}
if(y+1 < ptr->row_count) 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);
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);
}
return 0;
}
static int html_loop(tview_t* tv)
{
//tv->my_drawaln(tv, tv->curr_tid, tv->left_pos);
return 0;
}
static int html_underline(tview_t* tv)
{
return (1 << UNDERLINE_FLAG);
}
/*
static void init_pair(html_tview_t *tv,int id_ge_1, const char* pen, const char* paper)
{
}
*/
tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples)
{
char* colstr=getenv("COLUMNS");
html_tview_t *tv = (html_tview_t*)calloc(1, sizeof(html_tview_t));
tview_t* base=(tview_t*)tv;
if(tv==0)
{
fprintf(stderr,"Calloc failed\n");
return 0;
}
tv->row_count=0;
tv->screen=NULL;
tv->out=stdout;
tv->attributes=0;
base_tv_init(base,fn,fn_fa,samples);
/* initialize callbacks */
#define SET_CALLBACK(fun) base->my_##fun=html_##fun;
SET_CALLBACK(destroy);
SET_CALLBACK(mvprintw);
SET_CALLBACK(mvaddch);
SET_CALLBACK(attron);
SET_CALLBACK(attroff);
SET_CALLBACK(clear);
SET_CALLBACK(colorpair);
SET_CALLBACK(drawaln);
SET_CALLBACK(loop);
SET_CALLBACK(underline);
#undef SET_CALLBACK
if(colstr!=0)
{
base->mcol=atoi(colstr);
if(base->mcol<10) base->mcol=80;
}
base->mrow=99999;
/*
init_pair(tv,1, "blue", "white");
init_pair(tv,2, "green", "white");
init_pair(tv,3, "yellow", "white");
init_pair(tv,4, "white", "white");
init_pair(tv,5, "green", "white");
init_pair(tv,6, "cyan", "white");
init_pair(tv,7, "yellow", "white");
init_pair(tv,8, "red", "white");
init_pair(tv,9, "blue", "white");
*/
return base;
}
tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples)
{
tview_t* tv=html_tv_init(fn,fn_fa,samples);
tv->my_drawaln=text_drawaln;
return tv;
}