hopkinsr / terminal-color

A Racket library to output colored text to the terminal on any platform, including Windows
18 stars 2 forks source link

Issues in combination with charterm #1

Closed akkartik closed 9 years ago

akkartik commented 9 years ago

Obviously not a bug per se. More a plea for help from someone who understands terminal internals.

I'm on Ubuntu 14.04 (gnome-terminal; TERM=xterm). I'm trying to use http://www.neilvandyke.org/racket-charterm to move the cursor around, etc. and terminal-color to print in color after moving around. It seems to work just enough to keep me interested. For example (after requireing charterm and terminal-color):

(open-charterm)
(charterm-clear-screen)
(charterm-cursor 5 5)
(displayln-color "Hello" #:fg 'green)  ; works
(close-charterm)

This works great. The screen shows "Hello" at 5,5 on the screen. However, replacing the displayln-color with display-color causes the text to appear at row 5, col 1. Using charterm-newline or charterm-clear-line sometimes gives me the sense that display doesn't immediately update the screen. Do you have any idea what might be going on? Is combining these two libraries just a bad idea because of incompatible internals or something? Thanks.

hopkinsr commented 9 years ago

Thanks for your example, however, it displays Hello at 5,5 for me.

The only example I can get for Hello to show at 5,1 is

#lang racket
(require (planet neil/charterm:3:1))
(require terminal-color)

(open-charterm)
(charterm-clear-screen)
(charterm-cursor 5 5)
(display-color "Hello" #:fg 'green) ; shows at 5,1
(charterm-newline)
(close-charterm)

which was fixed by using

#lang racket
(require (planet neil/charterm:3:1))
(require terminal-color)

(open-charterm)
(charterm-clear-screen)
(charterm-cursor 5 5)
(display-color "Hello" #:fg 'green) ; shows at 5,5
(flush-output) ; note this call
(charterm-newline)
(close-charterm)

Can you see if this works for you?

Regarding mixing the 2 libraries I believe for full support (positioning + color) it's only possible to do this on unix-like systems with a terminal that supports ANSI escape codes.

akkartik commented 9 years ago

Many thanks for the tips!

akkartik commented 9 years ago

Yes, (flush-output) does the trick. Thanks again.