Skip to content

Remove ncurses dependency and enable colored output on Windows#111

Open
CarterLi wants to merge 1 commit into
sdnvx:mainfrom
CarterLi:main
Open

Remove ncurses dependency and enable colored output on Windows#111
CarterLi wants to merge 1 commit into
sdnvx:mainfrom
CarterLi:main

Conversation

@CarterLi
Copy link
Copy Markdown
Contributor

@CarterLi CarterLi commented May 6, 2026

Somehow ncurses doesn't work on Windows. I end up with removing it completely (AI assisted)

Copilot AI review requested due to automatic review settings May 6, 2026 11:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the ncurses/curses integration and replaces terminal styling with ANSI escape sequences, including enabling ANSI color support on Windows consoles via ENABLE_VIRTUAL_TERMINAL_PROCESSING. It also cleans up the build configuration and scripts to drop the ENABLE_CURSES feature flag and related dependency discovery/linking.

Changes:

  • Replaced curses-based terminal capability/color handling with ANSI escape sequences in the TTY utility.
  • Updated text formatter helpers to use the TTY helpers instead of terminfo/curses calls.
  • Removed ENABLE_CURSES from CMake configuration, generated config header, and build scripts/config defaults.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
opendmi/src/utils/tty.c Drops curses usage and implements ANSI styling; enables Windows virtual terminal processing.
opendmi/src/format/text/helpers.c Switches text printing color handling from curses calls to TTY helpers; minor I/O cleanups.
opendmi/src/config.h.in Removes ENABLE_CURSES config define.
opendmi/include/opendmi/format/text/helpers.h Adds TTY include and introduces a printf-format attribute on dmi_text_printf.
opendmi/CMakeLists.txt Removes Curses imported target setup and conditional linking.
CMakeLists.txt Removes ENABLE_CURSES option and find_package(Curses) usage.
build.sh Removes --with-curses flag handling and CMake feature propagation.
build.conf.dist Removes ENABLE_CURSES default setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opendmi/include/opendmi/format/text/helpers.h
Comment thread opendmi/src/format/text/helpers.c
Comment thread opendmi/src/format/text/helpers.c
@sdnvx
Copy link
Copy Markdown
Owner

sdnvx commented May 8, 2026

Sorry for the delay in replying, I was moving to another country.

Removing ncurses will break color on *NIX depending on the terminal type - ANSI escape sequences are not universal, which is why ncurses uses the termcap/terminfo database. The correct way to provide cross-platform color support is to use ncurses on *NIX systems, and on Windows use native APIs like SetConsoleTextAttribute().

I really like the idea of ​​having the color work correctly everywhere, but in this version it won't work properly. If you want, I can rework this MR myself to use native Windows APIs. I can probably do this within a week or a week and a half.

@CarterLi
Copy link
Copy Markdown
Contributor Author

CarterLi commented May 8, 2026

Removing ncurses will break color on *NIX depending on the terminal type

Break color of what terminal? I'm the developer of fastfetch; and I tested fastfetch (which uses ANSI escape sequences heavily) in various terminals/consoles, including real TTY (Linux Console, macOS, *BSD, Solaris), all of them have basic text color support. Some have quirks, such as Linux console requires \e[5m to make background to work correctly, but they can be easily work around.

A more common situation is:

  1. A user doesn't have ncurses development package installed
  2. He/her builds opendmi locally
  3. (n)curses support is not built at all
  4. No colors are displayed

on Windows use native APIs like SetConsoleTextAttribute()

No. SetConsoleTextAttribute and all other Console APIs of Windows are deprecated for a long time. The correct way is to use ANSI escape sequences, as what I did in the PR.

@sdnvx
Copy link
Copy Markdown
Owner

sdnvx commented May 11, 2026

Break color of what terminal? I'm the developer of fastfetch; and I tested fastfetch (which uses ANSI escape sequences heavily) in various terminals/consoles, including real TTY (Linux Console, macOS, *BSD, Solaris), all of them have basic text color support. Some have quirks, such as Linux console requires \e[5m to make background to work correctly, but they can be easily work around.

First of all, ncurses detects color abilities of the terminal and will not output any ESC-sequences if the terminal doesn't support them. I don't think it's worth removing ncurses support. It's more likely that you should look for the reason why it doesn't work on Windows, as it should.

A more common situation is:

  1. A user doesn't have ncurses development package installed
  2. He/her builds opendmi locally
  3. (n)curses support is not built at all
  4. No colors are displayed

It's normal that color output is not supported without ncurses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants