annotate PsiCLASS-1.0.2/samtools-0.1.19/bam_tview_html.c @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #include <unistd.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #include "bam_tview.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #define UNDERLINE_FLAG 10
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 typedef struct HtmlTview {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 tview_t view;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 int row_count;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 tixel_t** screen;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 FILE* out;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 int attributes;/* color... */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 } html_tview_t;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 #define FROM_TV(ptr) ((html_tview_t*)ptr)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 static void html_destroy(tview_t* base)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 html_tview_t* tv=(html_tview_t*)base;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 if(tv->screen!=NULL)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 for(i=0;i< tv->row_count;++i) free(tv->screen[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 free(tv->screen);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 base_tv_destroy(base);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 free(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 void (*my_)(struct AbstractTview*,int,int,int);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 void (*my_attron)(struct AbstractTview*,int);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 void (*my_attroff)(struct AbstractTview*,int);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 void (*my_clear)(struct AbstractTview*);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 int (*my_colorpair)(struct AbstractTview*,int);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 static void html_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 int i,nchars=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 unsigned int size=tv->mcol+2;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 char* str=malloc(size);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 if(str==0) exit(EXIT_FAILURE);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 va_list argptr;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 va_start(argptr, fmt);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 nchars=vsnprintf(str,size, fmt, argptr);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 va_end(argptr);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 for(i=0;i< nchars;++i)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 tv->my_mvaddch(tv,y,x+i,str[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 free(str);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 static void html_mvaddch(struct AbstractTview* tv,int y,int x,int ch)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 tixel_t* row=NULL;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 if( x >= tv->mcol ) return; //out of screen
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 while(ptr->row_count<=y)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 int x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 row=(tixel_t*)calloc(tv->mcol,sizeof(tixel_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 if(row==0) exit(EXIT_FAILURE);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 for(x=0;x<tv->mcol;++x) {row[x].ch=' ';row[x].attributes=0;}
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 ptr->screen=(tixel_t**)realloc(ptr->screen,sizeof(tixel_t*)*(ptr->row_count+1));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 ptr->screen[ptr->row_count++]=row;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 row=ptr->screen[y];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 row[x].ch=ch;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 row[x].attributes=ptr->attributes;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 static void html_attron(struct AbstractTview* tv,int flag)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78 ptr->attributes |= flag;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 static void html_attroff(struct AbstractTview* tv,int flag)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
84 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
85 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
86 ptr->attributes &= ~(flag);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
87 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
88
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
89 static void html_clear(struct AbstractTview* tv)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
90 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
91 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
92 if(ptr->screen!=NULL)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
93 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
94 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
95 for(i=0;i< ptr->row_count;++i) free(ptr->screen[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
96 free(ptr->screen);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
97 ptr->screen=NULL;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
98 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
99 ptr->row_count=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
100 ptr->attributes=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
101 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
102
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
103 static int html_colorpair(struct AbstractTview* tv,int flag)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
104 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
105 return (1 << (flag));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
106 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
107
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
108 static int html_drawaln(struct AbstractTview* tv, int tid, int pos)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
109 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
110 int y,x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
111 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
112 html_clear(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
113 base_draw_aln(tv, tid, pos);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
114 fputs("<html><head>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
115 fprintf(ptr->out,"<title>%s:%d</title>",
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
116 tv->header->target_name[tid],
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
117 pos+1
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
118 );
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
119 //style
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
120
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
121 fputs("<style type='text/css'>\n",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
122 fputs(".tviewbody { margin:5px; background-color:white;text-align:center;}\n",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
123 fputs(".tviewtitle {text-align:center;}\n",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
124 fputs(".tviewpre { margin:5px; background-color:white;}\n",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
125 #define CSS(id,col) fprintf(ptr->out,".tviewc%d {color:%s;}\n.tviewcu%d {color:%s;text-decoration:underline;}\n",id,col,id,col);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
126 CSS(0, "black");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
127 CSS(1, "blue");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
128 CSS(2, "green");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
129 CSS(3, "yellow");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
130 CSS(4, "black");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
131 CSS(5, "green");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
132 CSS(6, "cyan");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
133 CSS(7, "yellow");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
134 CSS(8, "red");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
135 CSS(9, "blue");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
136 #undef CSS
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
137 fputs("</style>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
138
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
139 fputs("</head><body>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
140
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
141 fprintf(ptr->out,"<div class='tviewbody'><div class='tviewtitle'>%s:%d</div>",
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
142 tv->header->target_name[tid],
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
143 pos+1
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
144 );
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
145
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
146 fputs("<pre class='tviewpre'>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
147 for(y=0;y< ptr->row_count;++y)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
148 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
149
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
150 for(x=0;x< tv->mcol;++x)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
151 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
152
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
153
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
154 if(x== 0 || ptr->screen[y][x].attributes != ptr->screen[y][x-1].attributes)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
155 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
156 int css=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
157 fprintf(ptr->out,"<span");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
158 while(css<32)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
159 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
160 //if(y>1) fprintf(stderr,"css=%d pow2=%d vs %d\n",css,(1 << (css)),ptr->screen[y][x].attributes);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
161 if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
162 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
163
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
164 fprintf(ptr->out," class='tviewc%s%d'",
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
165 (( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)) )!=0?"u":""),
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
166 css);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
167 break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
168 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
169 ++css;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
170 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
171
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
172
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
173 fputs(">",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
174 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
175
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
176 int ch=ptr->screen[y][x].ch;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
177 switch(ch)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
178 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
179 case '<': fputs("&lt;",ptr->out);break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
180 case '>': fputs("&gt;",ptr->out);break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
181 case '&': fputs("&amp;",ptr->out);break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
182 default: fputc(ch,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
183 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
184
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
185
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
186 if(x+1 == tv->mcol || ptr->screen[y][x].attributes!=ptr->screen[y][x+1].attributes)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
187 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
188 fputs("</span>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
189 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
190 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
191 if(y+1 < ptr->row_count) fputs("<br/>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
192 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
193 fputs("</pre></div></body></html>",ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
194 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
195 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
196
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
197
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
198 #define ANSI_COLOR_RED "\x1b[31m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
199 #define ANSI_COLOR_GREEN "\x1b[32m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
200 #define ANSI_COLOR_YELLOW "\x1b[33m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
201 #define ANSI_COLOR_BLUE "\x1b[34m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
202 #define ANSI_COLOR_MAGENTA "\x1b[35m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
203 #define ANSI_COLOR_CYAN "\x1b[36m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
204 #define ANSI_COLOR_BLACK "\x1b[0m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
205 #define ANSI_COLOR_RESET ANSI_COLOR_BLACK
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
206
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
207 #define ANSI_UNDERLINE_SET "\033[4m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
208 #define ANSI_UNDERLINE_UNSET "\033[0m"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
209
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
210 static int text_drawaln(struct AbstractTview* tv, int tid, int pos)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
211 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
212 int y,x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
213 html_tview_t* ptr=FROM_TV(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
214 html_clear(tv);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
215 base_draw_aln(tv, tid, pos);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
216 int is_term= isatty(fileno(ptr->out));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
217
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
218 for(y=0;y< ptr->row_count;++y)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
219 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
220 for(x=0;x< tv->mcol;++x)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
221 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
222 if(is_term)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
223 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
224 int css=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
225 while(css<32)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
226 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
227 if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
228 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
229 break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
230 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
231 ++css;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
232 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
233 switch(css)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
234 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
235 //CSS(0, "black");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
236 case 1: fputs(ANSI_COLOR_BLUE,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
237 case 2: fputs(ANSI_COLOR_GREEN,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
238 case 3: fputs(ANSI_COLOR_YELLOW,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
239 //CSS(4, "black");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
240 case 5: fputs(ANSI_COLOR_GREEN,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
241 case 6: fputs(ANSI_COLOR_CYAN,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
242 case 7: fputs(ANSI_COLOR_YELLOW,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
243 case 8: fputs(ANSI_COLOR_RED,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
244 case 9: fputs(ANSI_COLOR_BLUE,ptr->out); break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
245 default:break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
246 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
247 if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
248 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
249 fputs(ANSI_UNDERLINE_SET,ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
250 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
251
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
252 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
253
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
254
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
255 int ch=ptr->screen[y][x].ch;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
256
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
257 fputc(ch,ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
258 if(is_term)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
259 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
260 fputs(ANSI_COLOR_RESET,ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
261 if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
262 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
263 fputs(ANSI_UNDERLINE_UNSET,ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
264 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
265 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
266 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
267 fputc('\n',ptr->out);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
268 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
269 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
270 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
271
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
272
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
273 static int html_loop(tview_t* tv)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
274 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
275 //tv->my_drawaln(tv, tv->curr_tid, tv->left_pos);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
276 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
277 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
278
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
279 static int html_underline(tview_t* tv)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
280 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
281 return (1 << UNDERLINE_FLAG);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
282 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
283
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
284 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
285 static void init_pair(html_tview_t *tv,int id_ge_1, const char* pen, const char* paper)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
286 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
287
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
288 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
289 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
290
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
291 tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
292 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
293 char* colstr=getenv("COLUMNS");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
294 html_tview_t *tv = (html_tview_t*)calloc(1, sizeof(html_tview_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
295 tview_t* base=(tview_t*)tv;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
296 if(tv==0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
297 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
298 fprintf(stderr,"Calloc failed\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
299 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
300 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
301 tv->row_count=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
302 tv->screen=NULL;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
303 tv->out=stdout;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
304 tv->attributes=0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
305 base_tv_init(base,fn,fn_fa,samples);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
306 /* initialize callbacks */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
307 #define SET_CALLBACK(fun) base->my_##fun=html_##fun;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
308 SET_CALLBACK(destroy);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
309 SET_CALLBACK(mvprintw);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
310 SET_CALLBACK(mvaddch);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
311 SET_CALLBACK(attron);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
312 SET_CALLBACK(attroff);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
313 SET_CALLBACK(clear);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
314 SET_CALLBACK(colorpair);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
315 SET_CALLBACK(drawaln);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
316 SET_CALLBACK(loop);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
317 SET_CALLBACK(underline);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
318 #undef SET_CALLBACK
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
319
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
320
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
321 if(colstr!=0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
322 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
323 base->mcol=atoi(colstr);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
324 if(base->mcol<10) base->mcol=80;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
325 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
326 base->mrow=99999;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
327
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
328 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
329 init_pair(tv,1, "blue", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
330 init_pair(tv,2, "green", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
331 init_pair(tv,3, "yellow", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
332 init_pair(tv,4, "white", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
333 init_pair(tv,5, "green", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
334 init_pair(tv,6, "cyan", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
335 init_pair(tv,7, "yellow", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
336 init_pair(tv,8, "red", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
337 init_pair(tv,9, "blue", "white");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
338 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
339 return base;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
340 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
341
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
342
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
343 tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
344 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
345 tview_t* tv=html_tv_init(fn,fn_fa,samples);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
346 tv->my_drawaln=text_drawaln;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
347 return tv;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
348 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
349