Color your terminal's output

Jens Mueller jens.k.mueller at
Sun Oct 9 03:26:40 PDT 2011

Johannes Pfau wrote:
> Jens Mueller wrote:
> >Johannes Pfau wrote:
> >> You could use ANSI codes on posix to avoid a dependency on curses:
> >>
> >> But I think using curses is ok. ncurses is MIT licensed and can be
> >> used as a dynamic library, so I don't think there are license
> >> problems.
> >> 
> >> However, I'd recommend to load ncurses dynamically with dlopen/dlsym
> >> and fallback to simple text output if the ncurses library cannot be
> >> loaded.
> >
> >Using the ANSI codes is fine with me. I assumed they aren't that
> >portable but it seems fine.
> I'd still use curses though, as it abstracts some things away. Finding
> terminal capabilities and similar stuff.
> >> >Any help is very appreciated.
> >> >
> >> >Though this module is functionality-wise inferior to something like
> >> >ncurses it conveniently allows coloring output for most use cases.
> >> 
> >> as you already use these functions:
> >>
> >> it'd be nice to have wget-like progressbars and 'updateable' text
> >> labels. Shouldn't be as fancy as full ncurses, for most use cases
> >> it's good enough to modify the current line. +Points if it properly
> >> handles terminal width and resizing.
> >
> >I believe progress bars are easy to add. Boost's progress_bar should be
> >fairly easy to port. It'll be nice if you could provide a pull request
> >for this. Is this feasible for you?
> Sure, I'll have a look at it soon. You're talking about this
> progress_display class, right?

Yes. Maybe it's too simple compared to wget's.

> >Regarding update able text labels I'm not sure how they are typically
> >used. So I would also prefer some pull request from somebody with a
> >common use case.
> Well, think of wget's output:
>  0% [                                       ] 1.154.567    123K/s  ETA 57m 6s
>  |                        |                       |          |         |
> updateable label     progressbar               u-label     u-label   u-label

That looks very useful. Is this difficult to add?
Can't one just delete the entire line and replace it with an
appropriately updated one? Is this too naive?
This would be easy to implement on Windows as well, I suppose.


More information about the Digitalmars-d mailing list