Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/commandjoo/java-native-ncurses

NCurses Implementation written in Java, with a Wrapper for making GUIs
https://github.com/commandjoo/java-native-ncurses

cli curses curses-library curses-ui java jni jni-java jni-wrapper linux-app native ncurses ncurses-library ncurses-tui terminal-app terminal-based tui wrapper

Last synced: 28 days ago
JSON representation

NCurses Implementation written in Java, with a Wrapper for making GUIs

Awesome Lists containing this project

README

        

Welcome to Java-Native-NCurses 👋



Version


c java

> Java NativeCurses is an NCurses wrapper written in Java, it provides direct access to many NCurses methods, and also provides an API for directly creating GUIs using Windows Buttons and Text fields

***
## Quickstart
Download
[The latest version](https://github.com/CommandJoo/Java-Native-NCurses/releases/latest)
and add it as a Library to your Project

Alternatively
Clone the Repository
```shell
git clone https://github.com/CommandJoo/Java-Native-NCurses
```

***
## Usage

### Running the Application
Building the library:
- compiling and linking the library
```sh
cd ./src/native
make compile
make lib
```
- Generating the header and then compiling and linking the library
```sh
cd ./src/native
make
```

Running the Jar
```sh
java -jar "build/libs/JavaCurses.jar"
#or
./run
```

### Creating a GUI in Java NativeCurses
```java
...
public static void main(String[] args) {
int fps = 30;//too high fps will cause flickering
int width = 40;//minimum width in characters
int width = 10;//minimum height in lines
WindowManager windowManager = new WindowManager(fps, width, height);
Window window = windowManager.addWindow(0, new MyWindow());//add a window to the screen and make it be the actively rendered one

windowManager.render();//starts the drawing
windowManager.handleKey();//starts listening for inputs
}
```
```java
public class MyWindow {
public MyWindow() {
super(null,
Curses.width() / 2 - 30, //x position
Curses.height() / 2 - 6, //y position
60, //width in characters
12, //height in lines
ColorBuilder //create a new color pair
.create()
.defineForeground(new Color(70, 200, 150)) //Java Colors and Hex are supported
.defineBackground(1) //default black -> NativeCurses.BLACK
.build(), //get the color pair id
"MyWindow"); //title
}

public void init() {
//initialize your components like Textfields
}

public void draw() {
//Draw things like Text which aren't a component
}

public boolean handleKey(char ch) {
boolean buttons = this.handleButtonKeys(ch);
if(buttons) return true;//returns true if a key has been handled

return this.handleKeysForSub(someComponent, ch);//returns if a key has been handled by a component

}
}
```
A working example of a simple login and chat interface can be found in [ExampleProject](src/main/java/de/johannes/example/Example.java)

A Simple Snake-Game can also be found here: [Snake](src/main/java/de/johannes/snake/SnakeWindow.java)
***
## Author

**Johannes Hans** ([@CommandJoo](https://github.com/CommandJoo))

## Show your support

Give a ⭐️ if this project helped you!