Curses Alternative for Windows

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

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/

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

What is needed for curses in Python 3.4 on Windows7?

You can use curses cross-platform (Windows, MacOS, GNU/Linux) if you install manually for Windows or like other package in others.

  1. Install wheel package. If you need more info about wheel click here.

  2. Go to this repository.

  3. Download a package with your python version, in example for python 3.4:

    curses-2.2-cp34-none-win_amd64.whl
  4. Install it (this command if for windows, in GNU/Linux install like other package)

    python -m pip install curses-2.2-cp34-none-win32.whl
  5. Just include in your python script:

    import curses 

You can use curses wrapper for python. Works in Fedora 25 in all terminals, and Windows 10 using git bash, powershell, or cmd.

Update:

  • An alternative to curses in Windows here.
  • Console user interface in Windows here.
  • An interesting tutorial here.

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.

What's a good Java, curses-like, library for terminal applications?

There is Charva, which links to native code but has an api based on Swing.
The screenshots show lots of text windows, so that looks useful.

hscurses or ncurses, which one to use?

I don't see any advantages in writing the UI in C and call functions from C.

You can choose how you are going to do the UI from several libraries available on Hackage:

  • hscurses
  • ncurses
  • nanocurses
  • vty and vty-ui
  • ansi-terminal (on windows)
  • brick — there's even a video tutorial on it.

I don't know which is better, there's a small description but not enough. Nanocurses seems more portable but with less features.

curses-like library for cross-platform console app in python

There is a wcurses. I've never tried it but it may meet your needs. It sounds like it doesn't have full curses compatibility, but may be close enough. Also it might not be using the DOS terminal, but opening a GUI window and drawing monospaced text inside.

Other windows text mode options are:

  • The console module;
  • wconio -- based on Borland's C conio library.

I believe both are windows only.



Related Topics



Leave a reply



Submit