Giter Club home page Giter Club logo

ncurses-st-menu's Introduction

ncurses-st-menu

modern and simple ncurses/PDCurses based library for CUA look menu

I didn't find any library for Unix terminal applications for creating pull down and menu bar menus. My short target is library for menu with midnight commander look. The origin ncurses menu are not designed for CUA applications, and cannot be used for these types of applications. This is library - small library. It does only pulldown menus and menubars, nothing else. It is not complex framework with thousand functions.

Features

  • CUA look pulldown and menu bar support

  • Support inner accelerator x and outer accelerator x

  • Menubar are accessable via Alt x accelerators

  • Nested pulldown menu are suppported

  • Possible to set style (14 attributes, 12 styles are prepared)

  • Possible to set shadow around pulldown menu

  • Mouse is supported

  • Possible serialize and load state of menu objects

  • Menu is scrollable when has more items than can be displayed

  • The usage pattern is close to original ncurses menu library. A menudata are created by functions st_menu_new or st_menu_new_menubar. A function st_menu_post displays menu, and function st_menu_unpost hides menu. Any event can be processed in menu library by function st_menu_driver and menu can be removed by function st_menu_free.

  • Compatible with PDCurses (offers Windows support--among others)

Screenshots

Building Libraries/Demos

Use the following to build for ncurses. (PDCurses specific build information is detailed later in this document)

./autogen.sh
./configure
make

NOTE: To generate a debug build append --enable-debug to the configure statement.

Creates demoapp and demoapp_sl. demoapp_sl uses shared library - and it can be executed by LD_LIBRARY_PATH=. /.demoapp_sl. Note: when you doesn't modify LD_LIBRARY_PATH, you should to run make install for correct behave of demoapp_sl (demo with shared library).

Command|Set style submenu is active - you can change styles interactivly.

When there are no ncursesw library, then modify Makefile and replace ncursesw by necurses, and remove -DNCURSES_WIDECHAR=1.

Clean Build

To remove all built objects/executable/etc run:

make clean

To remove the files created by the autotools as well as objects/executable/etc:

make cleanall

Usage

#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
#include <locale.h>
#include "st_curses.h"
#include "st_panel.h"
#include <string.h>
#include <unicase.h>

#include "st_menu.h"

/*
 * Read event. When event is mouse event, read mouse data
 */
static inline int
get_event(MEVENT *mevent, bool *alt)
{
	bool	first_event = true;
	int		c;

	*alt = false;

repeat:

	c = getch();

	/*
	 * Read mouse event when it is possible. Do it now, before st_menu_driver call,
	 * as protection to unwanted multiple call of getmouse function. For one mouse
	 * event, it returns data only once time.
	 */
	if (c == KEY_MOUSE)
	{
		int ok = getmouse(mevent);

		if (ok != OK)
			goto repeat;
	}

	if (c == ST_MENU_ESCAPE)
	{
		if (first_event)
		{
			first_event = false;
			goto repeat;
		}
	}

	*alt = !first_event;

	return c;
}

/*
 * Application demo
 */
int
main()
{
	PANEL *mainpanel;
	ST_MENU_CONFIG  config;
	ST_MENU_ITEM		   *active_item;
	struct ST_MENU *menu;
	bool	activated;
	int		c;
	MEVENT	mevent;
	bool	alt;
	bool	force8bit;

	ST_MENU_ITEM _file[] = {
		{"E~x~it", 34, "Alt-x"},
		{NULL, -1, NULL}
	};

	ST_MENU_ITEM menubar[] = {
		{"~F~ile", 61, NULL, 0, _file},
		{NULL, -1, NULL}
	};

	setlocale(LC_ALL, "");

    #ifdef HAVE_LANGINFO_CODESET
	/* Don't use UTF when terminal doesn't use UTF */
	config.encoding = nl_langinfo(CODESET);
	#else
	config.encoding = "";
	#endif

#ifdef LIBUNISTRING

	config.language = uc_locale_language();

#else

	config.language = NULL;

#endif
    
	force8bit = strcmp(config.encoding, "UTF-8") != 0;

	initscr();
	start_color();
	clear();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

#ifdef NCURSES_EXT_FUNCS

	set_escdelay(25);

#endif

	refresh();

	init_pair(1, COLOR_WHITE, COLOR_BLUE);

	/* load style, possible alternatives: ST_MENU_STYLE_MC, ST_MENU_STYLE_DOS */
	st_menu_load_style(&config, ST_MENU_STYLE_VISION, 2, force8bit, false);

	mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED, NULL);
	mouseinterval(0);

	/* prepare main window */
	wbkgd(stdscr, COLOR_PAIR(1));
	wclear(stdscr);
	wrefresh(stdscr);

	/*
	 * main window should be panelized. Only panels can be
	 * overlapped without unwanted effects.
	 */
	mainpanel = new_panel(stdscr);
	st_menu_set_desktop_panel(mainpanel);

	/* prepare state variable for menubar */
	menu = st_menu_new_menubar(&config, menubar);

	/* post meubar (display it) */
	st_menu_post(menu);

	c = get_event(&mevent, &alt);

	refresh();

	while (1)
	{
		bool	processed = false;

		processed = st_menu_driver(menu, c, alt, &mevent);

		doupdate();

		active_item = st_menu_selected_item(&activated);
		if (processed && activated)
		{
			/* here is processing of menucode related to Exit menu item */
			if (active_item->code == 34)
				break;
		}

		if (!processed && alt && c == 'x')
			break;

		/* get new event */
		c = get_event(&mevent, &alt);
	}

	endwin();

	st_menu_unpost(menu, true);
	st_menu_free(menu);

	return 0;
}

Dependency

  • optional libunistring - LGPL Unicode library

  • define NCURSES_WIDECHAR when wide char ncurses support is available.

PDCurses

Building PDCurses

This is a simple overview on building PDcurses from source. For the latest info refer to the README files for each build directory/type.

X11

cd PDCurses/x11
./configure
make

wincon (Windows Console)

Building with MinGW using MSys

cd PDCurses/wincon
set PDCURSES_SRCDIR=c:\tmp\PDCurses
make DLL=Y

NOTE: To clean the build you will need to run rm *.o *.dll *.a since make clean was written expecting to run from a Windows Console (i.e. uses DEL).

Building for PDCurses

To build for PDCurses you first need some added agruments for the configure prior to the make. The configure options are defined as:

PDCURSES_INSTALL If you have the PDCurses libs/headers installed you can simply use just this flag. The other options will be filled in for you. Currently support: "x11" NOTE: Other arguments not needed.
PDCURSES_INCDIR Directory containing the curses/panel headers
PDCURSES_LIBDIR Directory containing the PDCurses library
PDCURSES_LIB Name of the PDCurses library, defaults to 'libXCurses' (Linux), 'pdcurses' (Windows)
PDCURSES_DEP_LIBS List of the PDCurses dependant library (exclude PDCURSES_LIB).

NOTE: If you are pointing to the PDCurses github directory built for a specific OS/terminal you can omit the PDCURSES_INCDIR.

Windows Requirements

Built using MinGW from MSys. Install the following:

  • pacman -S mingw-w64-x86_64-pkg-config
  • pacman -S automake autoconf

Examples

This example builds from installed PDCurses for Linux X11:
NOTE: The build tools will setup all the other PDCURSES_xxx arguments for us.

./autogen.sh
PDCURSES_INSTALL=x11 ./configure
make

This example builds from PDCurses source for Linux X11:
NOTE: PDCURSES_LIB defaults to libXCurses so we don't need to specify it

./autogen.sh
PDCURSES_LIBDIR=/home/username/github/PDCurses/x11 ./configure
make

This is a complete example (ignores the fact that some variables are not needed):

./autogen.sh
PDCURSES_LIBDIR=/home/username/github/PDCurses/x11 \
PDCURSES_INCDIR=/home/username/github/PDCurses \
PDCURSES_LIB=libXCurses \
PDCURSES_DEP_LIBS=Xaw Xmu Xt X11 Xpm SM ICE Xext \
./configure
make

This example builds from PDCurses source for Windows:

./autogen.sh
PDCURSES_LIBDIR=/c/tmp/PDCurses/wincon ./configure
make

NOTE: To generate a debug build append --enable-debug to the configure statement.

Screenshots

PDCurses Ubuntu 16.04 X11

PDCurses Tested:

  • Ubuntu 16.04, PDCurses X11
  • Windows 10, PDCurses wincon
    • Build with MSys/MinGW

Note

If you like it, send a postcard from your home country to my address, please:

Pavel Stehule
Skalice 12
256 01 Benesov u Prahy
Czech Republic

I invite any questions, comments, bug reports, patches on mail address [email protected]

ncurses-st-menu's People

Contributors

okbob avatar tysenmoore-xse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar

ncurses-st-menu's Issues

remove autogen + configure-generated files

  • configure (generated from configure.ac when running autogen.sh and heavily different depending on the actual version of the installed tools, so very likely to get conflicts when generated with a different version)
  • st_menu.pc (generated during configure from st_menu.pc.in)
  • config.make (generated during configure from config.make.in)

When looking at @tysenmoore-xse's repo we also see that as long as the generated files are in it happens that those are adjusted and committed, instead of the "sources", which is another reason to remove them.

Together with the deletion I suggest to add those files to git ignore.

add new "control types" checkbox and option

  • a checkbox would have an additional pointer to an int/char variable (and possibly if a "triple state" is possible [would evaluate to -1], off = 0, on = 1)

  • for options we likely would have two set of definitions:

    • an option group which defines a pointer to an int/char variable and the place the option group is placed and possibly if a triple state is possible
    • the actual options (common definitions like short cuts and text here + the value that is used for this option)

@okbob Is it understandable what I mean? Should those two additional control types be split to two issues?

compiling demo

Hello
I have an error compiling demo
demo/demo.c: In function ‘get_event’:
demo/demo.c:57:2: error: unknown type name ‘wint_t’
wint_t ch;
^~~~~~
demo/demo.c:68:8: warning: implicit declaration of function ‘get_wch’ [-Wimplicit-function-declaration]
ret = get_wch(&ch);
^~~~~~~
Makefile:35: recipe for target 'demoapp' failed

gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)

I'm a newbie in C
thanks in advance

NetBSD failure to build

I'm having an issue setting this up on NetBSD. I first get an error with ./autogen.sh
autogensh

Then doing the command again appears to work for some reason
autogenshfixed

And then running ./configure tells me that netbsd isn't supported despite the documentation stating it does
configurefailed

Is there a dependency I'm missing?

Edit: I just wanted to add I get the same exact errors in OpenBSD too. So this appears to be a *BSD issue rather than a specific OS issue.

Edit 2: autogen.sh also fails on linux, but regular configure and make works without issue.

Use as popup-menu (context-menu)

Is it possible to use ncurses-st-menu as context menu (a panel including the "normal" menu definition horizontally) already?

If not: please consider this feature request.

Selections not working from mouse

If I change the demo.c (for example) to to not block waiting for an input event the menu does not work correctly. I added the following to the main()

nodelay(stdscr, TRUE);

I can no longer get selections while using the mouse. For example, go into the menu and select something, it does not work. If I use the command bar key presses they work. I also noticed the submenus open just fine. The selection of any item using the mouse seems to be the only problem.

I also tried to step through the code and it sometimes works.

Is this expected behavior? (I assume no) Has anyone experienced this before? Is this mode supported by the menu? Or, am I not using this feature properly?

Thanks for the time and any support.

SDL2 support?

The readme suggests that X11/WinCon are the only options when using PDCurses.
Does st-menu support PDCurses + SDL2 ?

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.