Skip to content

Commit

Permalink
render: Fix mirc-colour-codes in multiline messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ec429 committed Jun 14, 2012
1 parent 6e37ec8 commit 4c59e62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
34 changes: 21 additions & 13 deletions bits.c
Expand Up @@ -55,6 +55,8 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
int l2,i2;
char *word;
const char *ptr=msg;
colour cc=lc; // current colour
s_setcolour(cc, out, l, i);
while(*ptr)
{
switch(*ptr)
Expand All @@ -67,17 +69,21 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
else
{
append_char(out, l, i, '\n');
s_setcolour(lc, out, l, i);
for(x=0;x<tabx;x++)
append_char(out, l, i, ' ');
s_setcolour(cc, out, l, i);
}
ptr++;
break;
case '\n':
if(*++ptr)
{
append_char(out, l, i, '\n');
s_setcolour(lc, out, l, i);
for(x=0;x<tabx;x++)
append_char(out, l, i, ' ');
s_setcolour(cc, out, l, i);
}
break;
case '\t':;
Expand All @@ -92,15 +98,18 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
else
{
append_char(out, l, i, '\n');
s_setcolour(lc, out, l, i);
for(x=0;x<tabx;x++)
append_char(out, l, i, ' ');
s_setcolour(cc, out, l, i);
break;
}
}
ptr++;
break;
default:
init_char(&word, &l2, &i2);
colour oc=cc;
int wdlen=0;
while(!strchr(" \t\n", *ptr))
{
Expand All @@ -114,7 +123,7 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
if(mirc_colour_compat==2)
{
colour mcc=c_mirc(fore, back);
s_setcol(mcc.fore, mcc.back, mcc.hi, mcc.ul, &word, &l2, &i2);
s_setcolour(cc=mcc, &word, &l2, &i2);
}
}
else if(sscanf(ptr, "\003%d%zn", &fore, &bytes)==1)
Expand All @@ -123,15 +132,15 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
if(mirc_colour_compat==2)
{
colour mcc=c_mirc(fore, 1);
s_setcol(mcc.fore, mcc.back, mcc.hi, mcc.ul, &word, &l2, &i2);
s_setcolour(cc=mcc, &word, &l2, &i2);
}
}
else
{
ptr++;
if(mirc_colour_compat==2)
{
s_setcol(lc.fore, lc.back, lc.hi, lc.ul, &word, &l2, &i2);
s_setcolour(cc=lc, &word, &l2, &i2);
}
}
}
Expand All @@ -146,21 +155,20 @@ int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour
break;
}
}
if(wdlen+x<width)
{
append_str(out, l, i, word);
free(word);
x+=wdlen;
}
else
if(wdlen+x>=width)
{
append_char(out, l, i, '\n');
s_setcolour(lc, out, l, i);
for(x=0;x<tabx;x++)
append_char(out, l, i, ' ');
append_str(out, l, i, word);
free(word);
x+=wdlen;
if(mirc_colour_compat==2)
s_setcolour(oc, out, l, i);
else
s_setcolour(cc, out, l, i);
}
append_str(out, l, i, word);
free(word);
x+=wdlen;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions buffer.c
Expand Up @@ -379,6 +379,7 @@ int redraw_buffer(void)
bufs[cbuf].scroll=uline;
bufs[cbuf].ascroll=pline;
int row=height-2;
//setcolour(bufs[cbuf].lpc[uline]);
while(row>(tsb?1:0))
{
bool breakit=false;
Expand All @@ -405,7 +406,6 @@ int redraw_buffer(void)
pline+=bufs[cbuf].lpl[uline];
}
if(breakit) break;
setcolour(bufs[cbuf].lpc[uline]);
locate(row, 0);
fputs(bufs[cbuf].lpt[uline][pline], stdout);
if(!full_width_colour) resetcol();
Expand Down Expand Up @@ -537,7 +537,6 @@ int render_line(int buf, int uline)
break;
}
colour c={.fore=7, .back=0, .hi=false, .ul=false};
int x=wordline(stamp, 0, &proc, &l, &i, c);
char *tag=strdup(bufs[buf].ltag[uline]?bufs[buf].ltag[uline]:"");
switch(bufs[buf].lm[uline])
{
Expand Down Expand Up @@ -629,6 +628,7 @@ int render_line(int buf, int uline)
default:
break;
}
int x=wordline(stamp, 0, &proc, &l, &i, c);
x=wordline(tag, indent?x:0, &proc, &l, &i, c);
free(tag);
wordline(bufs[buf].lt[uline], indent?x:0, &proc, &l, &i, c);
Expand Down

0 comments on commit 4c59e62

Please sign in to comment.