3 typedef struct HtmlTview {
8 int attributes;/* color... */
11 #define FROM_TV(ptr) ((html_tview_t*)ptr)
13 static void html_destroy(tview_t* base)
16 html_tview_t* tv=(html_tview_t*)base;
19 for(i=0;i< tv->row_count;++i) free(tv->screen[i]);
22 base_tv_destroy(base);
27 void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...);
28 void (*my_)(struct AbstractTview*,int,int,int);
29 void (*my_attron)(struct AbstractTview*,int);
30 void (*my_attroff)(struct AbstractTview*,int);
31 void (*my_clear)(struct AbstractTview*);
32 int (*my_colorpair)(struct AbstractTview*,int);
35 static void html_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...)
38 unsigned int size=tv->mcol+2;
39 char* str=malloc(size);
40 if(str==0) exit(EXIT_FAILURE);
42 va_start(argptr, fmt);
43 nchars=vsnprintf(str,size, fmt, argptr);
46 for(i=0;i< nchars;++i)
48 tv->my_mvaddch(tv,y,x+i,str[i]);
53 static void html_mvaddch(struct AbstractTview* tv,int y,int x,int ch)
56 html_tview_t* ptr=FROM_TV(tv);
57 if( x >= tv->mcol ) return; //out of screen
58 while(ptr->row_count<=y)
61 row=(tixel_t*)calloc(tv->mcol,sizeof(tixel_t));
62 if(row==0) exit(EXIT_FAILURE);
63 for(x=0;x<tv->mcol;++x) {row[x].ch=' ';row[x].attributes=0;}
64 ptr->screen=(tixel_t**)realloc(ptr->screen,sizeof(tixel_t*)*(ptr->row_count+1));
65 ptr->screen[ptr->row_count++]=row;
69 row[x].attributes=ptr->attributes;
72 static void html_attron(struct AbstractTview* tv,int flag)
74 html_tview_t* ptr=FROM_TV(tv);
75 ptr->attributes |= 1 << flag;
78 static void html_attroff(struct AbstractTview* tv,int flag)
80 html_tview_t* ptr=FROM_TV(tv);
81 ptr->attributes &= ~(1 << flag);
84 static void html_clear(struct AbstractTview* tv)
86 html_tview_t* ptr=FROM_TV(tv);
90 for(i=0;i< ptr->row_count;++i) free(ptr->screen[i]);
98 static int html_colorpair(struct AbstractTview* tv,int flag)
103 static int html_drawaln(struct AbstractTview* tv, int tid, int pos)
106 html_tview_t* ptr=FROM_TV(tv);
108 base_draw_aln(tv, tid, pos);
109 fputs("<html><head>",ptr->out);
112 fputs("<style type='text/css'>",ptr->out);
113 #define CSS(id,col) fprintf(ptr->out,".tviewc%d {color:%s;}\n.tviewcu%d {color:%s;text-decoration:underline;}\n",id,col,id,col);
125 fputs("</style>",ptr->out);
127 fputs("</head><body>",ptr->out);
128 fputs("<pre class='tview'>\n",ptr->out);
129 for(y=0;y< ptr->row_count;++y)
132 for(x=0;x< tv->mcol;++x)
136 if(x== 0 || ptr->screen[y][x].attributes!=ptr->screen[y][x-1].attributes)
139 fputs("<span class='",ptr->out);
142 if((ptr->screen[y][x].attributes & (1 << css))!=0)
149 fprintf(ptr->out,"tviewc%d",css);
150 fputs("'>",ptr->out);
153 int ch=ptr->screen[y][x].ch;
156 case '<': fputs("<",ptr->out);break;
157 case '>': fputs(">",ptr->out);break;
158 case '&': fputs("&",ptr->out);break;
159 default: fputc(ch,ptr->out); break;
163 if(x+1 == tv->mcol || ptr->screen[y][x].attributes!=ptr->screen[y][x+1].attributes)
165 fputs("</span>",ptr->out);
168 if(y+1 < ptr->row_count) fputs("<br/>",ptr->out);
170 fputs("</pre></body></html>",ptr->out);
174 static int text_drawaln(struct AbstractTview* tv, int tid, int pos)
177 html_tview_t* ptr=FROM_TV(tv);
179 base_draw_aln(tv, tid, pos);
180 for(y=0;y< ptr->row_count;++y)
182 for(x=0;x< tv->mcol;++x)
184 int ch=ptr->screen[y][x].ch;
188 fputc('\n',ptr->out);
194 static int html_loop(tview_t* tv)
196 //tv->my_drawaln(tv, tv->curr_tid, tv->left_pos);
200 static int html_underline(tview_t* tv)
206 static void init_pair(html_tview_t *tv,int id_ge_1, const char* pen, const char* paper)
212 tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples)
214 char* colstr=getenv("COLUMNS");
215 html_tview_t *tv = (html_tview_t*)calloc(1, sizeof(html_tview_t));
216 tview_t* base=(tview_t*)tv;
219 fprintf(stderr,"Calloc failed\n");
226 base_tv_init(base,fn,fn_fa,samples);
227 /* initialize callbacks */
228 #define SET_CALLBACK(fun) base->my_##fun=html_##fun;
229 SET_CALLBACK(destroy);
230 SET_CALLBACK(mvprintw);
231 SET_CALLBACK(mvaddch);
232 SET_CALLBACK(attron);
233 SET_CALLBACK(attroff);
235 SET_CALLBACK(colorpair);
236 SET_CALLBACK(drawaln);
238 SET_CALLBACK(underline);
244 base->mcol=atoi(colstr);
245 if(base->mcol<10) base->mcol=80;
250 init_pair(tv,1, "blue", "white");
251 init_pair(tv,2, "green", "white");
252 init_pair(tv,3, "yellow", "white");
253 init_pair(tv,4, "white", "white");
254 init_pair(tv,5, "green", "white");
255 init_pair(tv,6, "cyan", "white");
256 init_pair(tv,7, "yellow", "white");
257 init_pair(tv,8, "red", "white");
258 init_pair(tv,9, "blue", "white");
264 tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples)
266 tview_t* tv=html_tv_init(fn,fn_fa,samples);
267 tv->my_drawaln=text_drawaln;