Is Ncurses Available For Windows

Is ncurses available for windows?

There's an ongoing effort for a PDCurses port:

http://www.mail-archive.com/pdcurses-l@lightlink.com/msg00129.html

http://www.projectpluto.com/win32a.htm

How To add Ncurses to my Project in Visual Studio 2017?

NCurses is UNIX library, i.e. available for POSIX UNIX-es like Linux, FreeBSD, MacOS X etc. There is PDCurses which support Windows, and you can replace ncurses with PDCurses in your program and use it with POSIX and another systems like DOS, Windows etc.

Please follow the PDCurses build manual. And check demos code

NCurses-Like System for Windows

There is very similar library PDCurses. It uses the same calls as ncurses, but works on Win32. The only thing you'd need to port a program would be to recompile.

http://pdcurses.sourceforge.net/

How to Compile Ncurses Program for Native Windows Use

I figured out a solution. I'll post it here in case anyone else has this same issue. Thanks to Thomas Dickey for your help!

  1. Install the mingw-w64 toolchain and any other packages you need to compile your project (this is mostly where I messed up)
  2. Make sure to include the /mingw64/include/ncurses directory when compiling, or else gcc won't be able to find curses.h
  3. Include /mingw64/bin as a static directory or copy over the necessary dlls to the same folder as the directory

I ended up with this to compile:

gcc -I/mingw64/include/ncurses -o PROGRAMNAME main.c -lncurses -L/mingw64/bin -static

How to download , add NCurses to Code::Blocks 16.01 IDE for Windows 10

ncurses is a text-based graphics library for C that is
supported on unix-like OSes, not on Windows. So you can use
it if you're writing C on a unix-like OS (such as Linux). Your choice of IDE doesn't matter.

On Windows, you could use it under a unix-like environment such as Cygwin
or MSYS2, but you would hardly want to
go to that length merely for the sake of writing ncurses programs.

There is a very similar library, PDCurses
that is supported on Windows, and also a Project Pluto fork of PDCurses
The first of those provides a binary distibution,
but it dates from 2008. In both cases, there are links to GitHub repositories hosting
the latest source code, from which you may build the library yourself, following the instructions you will find in the project's README.md file.

Enabling curses in both Linux and Windows

I needed to build a cross-platform project that uses ncurses on Linux and MacOS but uses pdcurses on Windows. Some variant of curses is usually installed on popular distributions of Linux. ncurses is also available on MacOS as well. The same isn't quite true for Windows. My solution was to download the pdcurses sources and write a cmake script for building it on Windows. if (WIN32 or MSVC) build pdcurses else() find ncurses. You might also want to create a proxy header that #includes pdcurses or ncurses depending on the platform.

After cloning the GitHub repo, I copied the headers in ., the C files in ./pdcurses, the sources in ./wincon into a new directory in my project. Then I wrote a CMakeLists.txt file to compile all of these files into a library. It looked something like this:

cmake_minimum_required(VERSION 3.2)

add_library(PDcurses
# all of the sources
addch.c
addchstr.c
addstr.c
attr.c
beep.c
# ...
)
target_include_directories(PDcurses
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

My main CMakeLists.txt file compiled the pdcurses sources if the target is windows.

if(WIN32 OR MSVC)
add_subdirectory(pdcurses)
target_link_libraries(MyTarget
PRIVATE
PDcurses
)
else()
# find ncurses and use that
endif()

PDCurses seems to be a (more or less) drop-in replacement for ncurses in most situations. I was able to compile the example programs that came with PDcurses on my Mac using curses without any troubles.

Curses alternative for windows

Then you're out of luck i'm afraid.
There's no real cross-platform version or port of curses/ncurses, there is a "dialogue" port which works, but it's limited in capabilities.

Your best bet is to run CygWin or MinGW32, both are, in "loose terms", a Linux system+terminal emulator which has much of the binaries you need. They can run native Linux/Unix binaries inside the terminal and access your "host" system files at any time, so it's like patching Windows with a kick-ass terminal with all your goodies from the Linux world.
You'll still need some basic knowledge of Linux and how the commands etc work, but you'll figure it out.

Screenshot of MinGW and CygWin

Here's a Pyglet GUI example:

import pyglet
from pyglet.gl import *

class main (pyglet.window.Window):
def __init__ (self):
super(main, self).__init__(800, 600, fullscreen = False)
self.button_texture = pyglet.image.load('button.png')
self.button = pyglet.sprite.Sprite(self.button_texture)

## --- If you'd like to play sounds:
#self.sound = pyglet.media.load('music.mp3')
#self.sound.play()

self.alive = 1

def on_draw(self):
self.render()

def on_close(self):
self.alive = 0

def on_mouse_press(self, x, y, button, modifiers):
if x > self.button.x and x < (self.button.x + self.button_texture.width):
if y > self.button.y and y < (self.button.y + self.button_texture.height):
self.alive = 0

def on_key_press(self, symbol, modifiers):
if symbol == 65307: # [ESC]
self.alive = 0

def render(self):
self.clear()
self.button.draw()
self.flip()

def run(self):
while self.alive == 1:
self.render()

# -----------> This is key <----------
# This is what replaces pyglet.app.run()
# but is required for the GUI to not freeze
#
event = self.dispatch_events()


x = main()
x.run()

Here's the output of that code:

Sample Image

Use ncursesw6 on mingw

That looks as if you downloaded one of the sample cross-compiled builds from the ncurses homepage. Those are configured assuming a typical MinGW configuration, with the DLLs in /bin, the headers under /include and the link-libraries in /lib.

It is possible to use that from another location, but you would have to modify the ncursesw6-config script to reflect the new location. Also, the DLLs have to be in some directory on your $PATH. If they are not, that may not interfere with linking, but will prevent the resulting programs from running.

In the script, there is a section like this:

prefix=""
exec_prefix="${prefix}"

bindir="${exec_prefix}/bin"
includedir="${prefix}/include"
libdir="${exec_prefix}/lib"
datarootdir="${prefix}/share"
datadir="${datarootdir}"
mandir="${datarootdir}/man"

Based on the illustration of your directory tree, you would want to change that first line to

prefix=/home/LNV/ncurses6_mingw64

and add

/home/LNV/ncurses6_mingw64/bin

to your PATH environment variable.

By the way, MinGW has a package for ncurses, which you might consider using...

screenshot of MinGW installer



Related Topics



Leave a reply



Submit