[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ANSI Terminal Colors Module
- From: Matthew Wild <mwild1@...>
- Date: Tue, 29 Dec 2009 19:40:42 +0000
2009/12/29 Juris Kalnins <juris@mt.lv>:
> On Mon, 28 Dec 2009 22:46:05 +0200, Rob Hoelz <rob@hoelzro.net> wrote:
>>
>> I figured I'd just start simple, but feel free to optimize! =)
>
> Well, since you say so... :)
>
> simple:
> bright = '\27[1m'
> red = '\27[31m'
> ...
> reset = '\27[m'
> ----
> print(red, "text", reset)
>
>
> more simple:
> print "\27[1;31mBAD HAPPEN!\27[m"
>
> Actually, most of the time writing escapes inline is much easier than using
> a library. And since Lua accepts control characters inside quotes, you
> actually can type ^[ character instead of \27 (when writing with e.g. vim or
> emacs) and then using "less -R" you can see your code in full color.
>
It can get tricky remembering what all those codes mean, so I'd rather
have some abstraction. Incidentally I wrote a similar library, which
is here: http://hg.prosody.im/trunk/file/tip/util/termcolours.lua - I
obviously need to do some work on publishing what we've written better
:)
somestyle = termcolours.getstyle("red") -- or ("bright", "red"),
("red", "underline") etc.
print(termcolours.getstring(somestyle, "Hello world"))
Probably some optional metatable magic wouldn't go amiss, but I wanted
the code to be fairly efficient (being part of our logging it gets
called a lot).
Matthew