jeaye/ncurses-rs

has_colors return false, while c program return true

Closed this issue · 4 comments

I'm experiencing inconsistency and need help troubleshoot (whether this crate or my terminal).
When running ncurses color test program in c, has_colors() return 1.
While using this crate, ncurses::ll::has_colors() return 0 and ncurses::has_colors() return false.

This is... weird. Here's my C program:

#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#define PROGNAME "curses_init"

int main(void)
{
    /* Verify terminal capabilities */
    if (!isatty(1) || initscr() == NULL) {
        fprintf(stderr, "%s: This program must be run from a terminal!\n",
                PROGNAME);
        return EXIT_FAILURE;
    }
    printf("%d", has_colors());
    attron(COLOR_PAIR(5) | A_BOLD );
    endwin();

    return EXIT_SUCCESS;
}

Another information,

  1. tput colors return 8
  2. echo $XTERM return nothing

Did you call ncurses::initscr() in your rust program?

Ah yes I've, and additionally done the following,

fn gui_start() {
    use ncurses::*;

    /* Setup ncurses. */
    initscr(); // <------ Here
    raw();

    /* Allow for extended keyboard (like F1). */
    keypad(stdscr(), true);
    noecho();
    timeout(10);

    /* Invisible cursor. */
    curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);

    refresh();
}

Try using ltrace to see shared lib calls:

cargo build
ltrace target/debug/YOUR_APP 2> err
rg has_colors err # or just post the entire file

EDIT: As a note, in your rustodoro app, you seem to call has_colors before gui_start:
https://github.com/Abdillah/rustodoro/blob/master/src/bin/main.rs#L350

Wow, what a deep dive. Sure, that may be the root of the problem then.
I have changed the order and currently works fine. Thanks!
I will close this issue for now.
@AlexArgoAi sorry for the late reply; haven't lookup this issue for that while.