pflenker / hecto-tutorial

Build your own text editor in Rust

Home Page:https://www.flenker.blog/hecto/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Background color and macOS Terminal

jplwill opened this issue · comments

I'm at the point in the tutorial where the status and message lines are first added:

https://github.com/pflenker/hecto-tutorial/tree/draw-status-bar

The code is supposed to draw a status bar by outputting spaces with the desired background color. Instead, the status bar just looks like the terminal's normal background color; and on the first keypress, all of the text is displayed in a darker color. I've determined that if I comment out the call to Terminal::set_bg_color(STATUS_BG_COLOR); in draw_status_bar, it doesn't do this.

const STATUS_BG_COLOR: color::Rgb = color::Rgb(239, 239, 239);
    pub fn set_bg_color(color: color::Rgb) {
        print!("{}", color::Bg(color));
    }

I'm running on macOS using the built-in Terminal app; which says it handles ANSI colors, and which termion has been driving just fine.

Hi there, thanks for opening the issue!
Can you please verify that this issue persists after performing the following steps:

  • clone this repo, e.g. with git clone git@github.com:pflenker/hecto-tutorial.git
  • checkout the tag with git checkout draw-status-bar
  • running it with cargo run?

Thanks!

Yes, it still happens. FWIW, Cargo.lock says I have termion 1.5.3. (BTW, excellent tutorial; quite impressed.)

The problem appears to be related to the color: color::Rgb(239, 239, 239). If I use the standard colors, e.g., color::Red, color::Green, it works. I suspect the macOS terminal only supports the 16 standard ANSI colors. (The preferences dialog lets you pick the precise colors you want for each, so that kind of makes sense: you ask for color::Red and you get the precisely color from the matching slot, given the theme.

I'm going to use termion::style::Invert/termion::style::Reset instead of setting the background color.

Thanks, I'll update the tutorial text a bit to make it clearer there, too!