const (
Reset = "\x1b[0m"
Bright = "\x1b[1m"
Dim = "\x1b[2m"
Underscore = "\x1b[4m"
Blink = "\x1b[5m"
Reverse = "\x1b[7m"
Hidden = "\x1b[8m"
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
BgBlack = "\x1b[40m"
BgRed = "\x1b[41m"
BgGreen = "\x1b[42m"
BgYellow = "\x1b[43m"
BgBlue = "\x1b[44m"
BgMagenta = "\x1b[45m"
BgCyan = "\x1b[46m"
BgWhite = "\x1b[47m"
)
This constants work fine on any unixy terminal. I am not a term
expert, so I am not sure whether a package like this should have
a more elaborate interface. But the constants above are very handy to
me.
You just say:
fmt.Printf(term.FgRed+"blah"+term.Reset)
Thoughts.
--Petar
fmt.Println("\x1b[1;31;40mblah\x1b[0m")
. . . will print 'blah' in bright red on black. Perhaps in addition
to those constants one could have a function that constructs the
colour code based on style, foreground, and background choices.
One area that I spent much more research into was accessing termios -
without- cgo to enable raw input mode. Here's a pastie where I ported
some C code to Go in order to test my implementation.
Of course, it isn't portable to Windows and neither are ANSI terminal
escape codes, though both can be hidden under sufficient code such
that the API is portable. The only problem is that the Win32 console
API must be linked to -- which at the moment means using cgo.
-Daniel
a) heading toward adoption of the widely known terminfo/curses API
(note there are open source non-GPL implementations around for both
(in C) if that helps)
b) have a plan to cover the functionality of terminfo/curses in a Go-
idiomatic way, presumably with automated translation of at least the
still useful parts of the terminfo database entries into something the
Go term package can use.
I grew up too late for it to be fashionable to write my own editor (I
wrote my own mail software instead :-) but I'm sure there are people
on the list who have implemented editors, and perhaps they'd like to
comment on what they'd want from Go to implement a UTF-8 editor,
ideally one that runs in an xterrm (Linux, FreeBSD), and Terminal.app
(OS X).
Windows ... is another ball of wax. Editors there might be best
treated as a separate problem and expected to implement their own GUI,
but I don't know. I vaguely recall that I've used alternate "shells/
consoles" on Windows, but not their names or actually how good they
were, or what editor(s) I used within them.
Giles
On 20 Mar 2010, at 07:10, Giles Lean wrote:
> I have horrible fears that somewhere down this path, we'll end up
> wanting equivalent functionality to terminfo and {n,}curses.
Aye, a full-featured term package will require ncurses, it's the only
thing with some available support for all current X-terminals if
nothing else. Any fresh solution will either appear broken on some
terminals or will require a fresh terminal database to be maintained.
I won't say any more because I personally view it as quite astounding
that new virtual terminals are still being developed. I think I'd
rather develop a custom line protocol than use ncurses!
--
Simplicity does not precede complexity, but follows it.
-- Alan Perlis
-Daniel
I'm pretty sure Ken Thompson (ed) and Rob Pike (sam, acme) know a little something about writing editors...
--
:: atomly ::
www.atomly.com :: ato...@atomly.com
+1.676.575.9782 :: +49.176.65941389
+1.888.8ATOMLY :: +1.347.69ATOM1
> Are people interested in having a...
To unsubscribe from this group, send email to golang-nuts+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
I'm pretty sure Ken Thompson (ed) and Rob Pike (sam, acme) know a little something about writing editors...
I just made a little color formatter thing.fmt.Println(Yellow("Inside yellow is ", Red("red text"), " and ", Blue("blue ", Cyan("(and cyan) "), "text"), ". This is still yellow."))prints: Inside yellow is red text and blue (and cyan) text. This is still yellow.- Jae