Ncurses on Linux

So I'm trying to use the Ncurses library in swift on linux and it hangs forever when I call the initscr() method. I'm not really sure how to debug this and I'm pretty sure I've set up the C module map stuff correctly.

You can see the Ncurses module I created here.

I wanted to include the macros and constants that swift can't automatically import, so I use @_exported CNCurses and set up all the macros/constants that I could find in the Linux Ncurses headers that didn't automatically get imported into swift. That way I can just import NCurses and use it just like I would in C, but in swift.


EDIT: Adding example snippet that hangs on my Ubuntu 18.04 machine using Swift 5.0.1

import NCurses

initscr() // Hangs here forever
var xSize: CInt = 0
var ySize: CInt = 0
getmaxyx(stdscr, &ySize, &xSize)
print("Width: \(xSize), Height: \(ySize)")

Perhaps you may want to try my ANSI Terminal library. It's not as complete as ncurses, yet. But it does some of screen management functionality without any external libraries. Ignore it if it doesn't fill your need. :blush:

1 Like

I actually looked into using ANSI sequences first but I couldnt find a library that had implemented anything beyond the CSI color sequences. I clearly didnt find your library because youve got everything I needed!

My primary use is not to control the entire terminal, but to just move the cursor around the lowest few lines to do some custom printing and formatting when gathering user input. Ive got a termios library that I can use to get terminal window sizes. The combination of that and your ANSI library should give me what I need. I want to make a tab-completable library for when a user is inputting paths on the cli. I think that ANSI capabilities meet my needs, but I reached for ncurses since ived used it in other languages and knew it would work (and i thought setting up the modulemap to import the C library would be faster than writing my own ANSI sequence library).

I still am curious/concerned that ncurses doesnt seem to work on my machine. Ive seen other posts on here about people making module maps for ncurses that worked for them, but I will use your ANSI library for now :slight_smile:

I'm glad you found my library suits your need. :blush:

AFAIK, ncurses takes control the whole terminal. CMIIW. That's the reason I avoid it. For most common needs, ANSI's features are actually pretty complete. I don't even implement all ANSI features into my library. The problem with ANSI is compatibility with some terminals. But if you keep only using the most common ANSI's features, it should be fine.

I'm interested to see your termios library to get terminal window size. Does it work on Mac and Linux? Could you share that particular function? Thank you.

So I have the Termios stuff swift-ified here. I just forked someone else's unmaintained project and updated it.

The ioctl part to actually get the terminal window size is still a work in progress and isn't public yet, but as soon as it is I'll share it! It should work on both Mac and Linux, but I'm currently doing my dev for it on Linux (Ubuntu 18.04).

Thank you. I'll wait for the function to get terminal window size.

Terms of Service

Privacy Policy

Cookie Policy