Coder Social home page Coder Social logo

raku-ncurses's Introduction

NCurses

Actions Status

NCurses provides a Raku native interface to the ncurses library for terminal-independent screen I/O.

Example

use NCurses;

# Initialize curses window
my $win = initscr() or die "Failed to initialize ncurses\n";
start_color;

# Initialize colors
init_pair(1, COLOR_WHITE, COLOR_RED);
init_pair(2, COLOR_WHITE, COLOR_BLUE);

# Print Hello World
color_set(1, 0);
mvaddstr( 10, 10, " Hello world " );
color_set(2, 0);
mvaddstr( LINES() - 2, 2, "Press any key to exit..." );

# Refresh (this is needed)
nc_refresh;

# Wait for a keypress
getch;

# Cleanup
LEAVE {
    delwin($win) if $win;
    endwin;
}

For more examples, please see the examples folder.

Installation

  • On Debian-based linux distributions, please use the following command:
$ sudo apt-get install libncurses6
  • On Mac OS X, please use the following command:
$ brew update
$ brew install ncurses
  • Using zef (a module management tool bundled with Rakudo Star):
$ zef install NCurses

Environment variables

The following environment variables can be used to specify the location of the different ncurses libraries:

  • RAKU_NCURSES_LIB
  • RAKU_NCURSES_PANEL_LIB
  • RAKU_NCURSES_MENU_LIB
  • RAKU_NCURSES_FORM_LIB

Troubleshooting

  • To fix a broken or messed up terminal after a crash, please type reset to reset your terminal into its original state.

Testing

  • To run tests:
$ prove -ve "raku -Ilib"
  • To run all tests including author tests (Please make sure Test::Meta is installed):
$ zef install Test::META
$ AUTHOR_TESTING=1 prove -e "raku -Ilib"

Author

Ahmad M. Zawawi, azawawi on #raku, https://github.com/azawawi/

License

MIT License

raku-ncurses's People

Contributors

azawawi avatar jonathanstowe avatar krunen avatar samcv avatar softmoth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

raku-ncurses's Issues

NCURSES_MOUSE_VERSION

Hello, would it be possible to add something that returns the NCURSES_MOUSE_VERSION?

Crazy CPU utilization && Memory leak ......

COLS() - Not only uses a tremendous amount of cpu to return the number of columns,
each iteration of the call consumes more and more memory until all memory is consumed and it crashes.
I suspect LINES() does the same, but I haven't tested it.

root@FreeBSD11:~ # uname -sr
FreeBSD 11.2-RELEASE

OR

root@host:~ % uname -sr
Linux 4.13.0-46-generic

root@FreeBSD11:~ # perl6 --version
This is Rakudo Star version 2018.06 built on MoarVM version 2018.06
implementing Perl 6.c.

I suspect this is a problem with moarvm, but figured I'd start here.

+++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/env perl6

use NCurses;

sub MAIN()
{
my $win = initscr() or die("Failed to initialize ncurses\n");
loop {
say COLS();
sleep(1);
}
delwin($win) if $win;
endwin;
}

example not working on Arch Linux

Hey,

I installed this NCurses via panda and used the Rakudo Star 2015.02 version for that. When executing
perl6 hello-world.pl
Nothing happens. There is no error message and after a short screen flickering, a new prompt appears. I checked with a c++ test program if ncurses works in my terminal (xterm) successfully.

It seems, that getch does not work properly. When I remove the last line (endwin) I can see the Text 'Hello World !!!' before the prompt.

I'm using ncurses 5.9-7.

Doesn't work on systems with ncurses 6

I'm using arch linux, which uses version 6 of ncurses, and thus has no /usr/lib/libncursesw.so.5. Running anything using this library then results in:

Cannot locate native library 'libncursesw.so.5': libncursesw.so.5: cannot open shared object file: No such file or directory

Symlinking /usr/lib/libncursesw.so.6.0 to /usr/lib/libncursesw.so.5 hackishly "solves" the issue, but isn't exactly a great solution.

COLS() and LINES() shouldn't be cached

Programs running a la windows(not the os)/terminals that resize generally deliver a SIGWINCH upon that resize occuring.

COLS() and LINES() should always contain the current window dimensions. Currently they only return the dimensions that they were initially invoked with.

Example:


sub x()
{
  say COLS();
}

initscr();
signal(SIGWINCH).tap: { x() }

loop {
  sleep(1);
}

Cannot use NCurses from another module.

ncurses-test.zip

When I try to use NCurses in another module between my pl6 file and NCurses, I get this error upon running the script:

$ ./ncurses-test.pl6 
===SORRY!===
Cannot invoke this object (REPR: Null; VMNull)

I've attached a small zip file containing two perl6 files that exhibit this behavior.

Arch Linux 
rakudo 2017.03 (AUR),
rakudo 2017.4.2 (rakudobrew)

Problem with wborder signature

As is, the signature for wborder is (NCurses::WINDOW, int32, int32, int32, int32, int32, int32, int32, int32 --> int32). In order to accept characters shouldn't that be (NCurses::WINDOW, int, int, int, int, int, int, int, int --> int) such that wborder( $window, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord ); would work?

wrefresh(stdscr) causes segfault

It's my understanding that wrefresh(stdscr) should work exactly the same as nc_refresh(), but I seem to be getting a segfault.

The failing code:

use NCurses;
initscr; endwin; # To make sure stdscr is set
wrefresh(stdscr);
endwin;

On the other hand, the following works:

use NCurses;
use NativeCall;
initscr; endwin; # Again, make sure stdscr is set.
my \intptr_t = (nativesizeof(Pointer) == 8) int64 ?? int32;
wrefresh(Pointer.new(cglobal(library,'stdscr',intptr_t));
endwin;

I'm not entirely convinced this is an NCurses problem (I've opened a bug on rakudo/rakudo), but I was advised on the Perl6 IRC to bring it up here and at this point I'm just referring the issue to anyone who might know what's going on.

garbled Chinese character

When I pass some Chinese to mvaddstr function, for example: 你好, the output is OK, but when I pass some other Chinese/Japanese to mvaddstr, such as 彩虹, 哈哈 , ウルヰ, the out put is not ok.

use v6;
use NCurses;

# Initialize curses window
my $win = initscr() or die "Failed to initialize ncurses\n";
start_color;

# Initialize colors
init_pair(1, COLOR_WHITE, COLOR_RED);
init_pair(2, COLOR_WHITE, COLOR_BLUE);

# Print Hello World
color_set(1, 0);
mvaddstr( 10, 10, "你好");    # ok
mvaddstr( 15, 10, "彩虹");    # not ok, becomes: 彩?~Y?
mvaddstr( 15, 10, "哈哈");    # not ok, becomes: ?~S~H?~S~H
color_set(2, 0);
mvaddstr( LINES() - 2, 2, "Press any key to exit..." );

# Refresh (this is needed)
nc_refresh;

# Wait for a keypress
getch;

# Cleanup
LEAVE {
    delwin($win) if $win;
    endwin;
}

Location of ncursesw.so.5 is hardcoded.

Currently, the module hardcodes the DLL location. Perhaps it can accept an environment variable indicating the path to the library.

This would allow compatibility with Windows if I'm not mistaken.

NCurses::Lift

This is used in the examples, is in the lib/ dir, but isn't installed.

on archlinux, libncurses.so is present, but can not install

Hello,
From archlinux (zsh shell with features), command:
find /usr -name "libncurses.so*"
show that i have libncurses installed
but zef is not happy because an other request is to also have a bigger libncurses (error from zef)

then i do:
la /usr/lib/libncurses*
and see that libncurses.so is not a symbolic link, but the real lib is libncursesw.so.6.0
content of libncurses.so is:
INPUT(-lncursesw)

so actually, this module can not be installed on archlinux without break my archlinux organisation (and my packager will not be happy with that...).

NCurses do things the way it can not be used by all OS Linux.

export PERL6_NCURSES_LIB=/usr/lib/libncursesw.so.6.0
then add this line in /etc/profile
and also in ~/.zshrc
do the job and resolve the problem (but this thread post should not be close).

Fails to install under FreeBSD

zef install NCurses

===> Searching for: NCurses
===> Searching for missing dependencies: LibraryCheck
===> Testing: LibraryCheck:ver<0.0.6>:authgithub:jonathanstowe
===> Testing [OK] for LibraryCheck:ver<0.0.6>:authgithub:jonathanstowe
===> Testing: NCurses:ver<0.6.3>:authgithub:azawawi
===> Testing [FAIL]: NCurses:ver<0.6.3>:authgithub:azawawi
Aborting due to test failure: NCurses:ver<0.6.3>:authgithub:azawawi (use --force-test to override)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.