Re: [code] [textadept] changing text color in message buffer

From: Jay Young <jyng7.att.hotmail.com>
Date: Fri, 11 Mar 2016 16:01:51 +0000

Thank you Mitchell and Robert for your replies. I really appreciate your help and the code examples you've shared.

Jay

________________________________________
From: Mitchell <m.att.foicica.com>
Sent: Friday, March 11, 2016 9:01 AM
To: code.att.foicica.com
Subject: Re: [code] [textadept] changing text color in message buffer

Hi Jay,

On Fri, 11 Mar 2016, Jay Young wrote:

> Hi Mitchell,
>
> Please don't feel obligated to reply to my thoughts below, since I don't
> know what I'm doing and I'm using this code in my init.lua which might
> be a problem (I like my working buffer always active):
>
> textadept.run.RUN_IN_BACKGROUND = true
>
> I was thinking I could loop through the buffers and try to find the
> message buffer in order to work with it. But my lack of knowledge with
> Lua is bringing this to a halt.

Okay, you're right that you'll have to look for the message buffer since
you are running things in the background and the global `buffer` reference
may not point to the message buffer after a call to `ui.print()`.

> I'm not quite sure how to use:
>
> buffer:start_styling(pos, buffer.STYLE_MAX)
> buffer:set_styling(length, style)
>
> The 'pos' and 'length' parameters make sense, but I'm not sure what to
> enter for 'buffer.STYLE_MAX' and 'style'.

`buffer.STYLE_MAX` is a constant. You can leave it as is. `style` is the
style number you'd like to highlight output with. You can use `0` if you'd
like. The default text has a style number of 32 (`buffer.STYLE_DEFAULT`),
so that's the only one you shouldn't use.

> And I'm wondering if I need to use the following somewhere as well, in
> order to add the color to the characters, but not sure what to enter for
> the style and color:
>
> buffer.style_fore[style], color

Whichever style number you pick (e.g. `0`), that is the number you'll use
with `buffer.style_*[]`. `color` is a number in 0xBBGGRR form. (If you're
familiar with CSS, it uses #RRGGBB notation, so you'd be swapping BB and
RR.) For example, `buffer.style_fore[0] = 0xFF0000` sets the foreground
color of style number 0 to blue.

> The code I've been testing looks like so, although it doesn't store the
> message buffer correctly. If you have some quick thoughts, I'd love to
> hear them, but again don't feel obligated and please don't waste too
> much time on this.
>
> events.connect(events.RUN_OUTPUT, function(lexer, output)
> for i, buffer in ipairs(_BUFFERS) do
> if buffer._type == _L['[Message Buffer]'] then
> local buffer = buffer

This most recent line is the problem. You are declaring a local variable
`buffer` in the scope of the `if` conditional. It will not be visible
outside. You should be doing something like this:

     local msg_buf = nil
     for i = 1, #_BUFFERS do
       if _BUFFERS[i]._type == _L['Message Buffer'] then
         msg_buf = _BUFFERS[i]
         break
       end
     end
     if not msg_buf then return end
     -- do something with msg_buf

> break
> end
> end
>
> ui.print(buffer.filename)
> ui.print(buffer.style_at[0])
>
> --buffer:start_styling(0, 0xff)
> --buffer:set_styling(5, 5)
> end, 1)

I hope this helps.

Cheers,
Mitchell

--
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 11 Mar 2016 - 11:01:51 EST

This archive was generated by hypermail 2.2.0 : Sat 12 Mar 2016 - 06:44:47 EST