4

When I execute sudo dpkg-reconfigure lightdm in the terminal I see a simplistic window-like listmenu. Is there an way to make something like that in C++?

This looks something like:
enter image description here

2
  • This is about programming, it is OT for Ask Ubuntu. Technically it belongs on Stack Overflow but it will be removed from there for lack of research - include what you have tried when you re ask it there.
    – Tim
    Aug 26, 2014 at 16:22
  • @Tim I don't agree this is off-topic here. It's asking how to implement something that appears in a highly distro-specific context. (If this had to be done from scratch each time--it doesn't--and answers had to give lots and lots of code, this might be a bad fit here.) I think an answer should mainly say what library provides the menu interface seen when using dpkg-reconfigure and how to install that library, link against it, and view its documentation on Ubuntu (which would be on-topic even without the mention of dpkg-reconfigure). I'm writing an answer now. Aug 26, 2014 at 16:29

1 Answer 1

5

The text-based window-like interface, contained within a terminal, that you see when you run sudo dpkg-reconfigure lightdm is coded using the ncurses library. So if you want your program to provide an interface that looks like that, you can use ncurses too.

To build software using ncurses in Ubuntu, you should get the appropriate header files package. Unless you're cross-compiling, this will be:

  • For programs using traditional strings where most characters are represented by a single byte (for example, UTF-8), use libncurses5 Install libncurses5.

    This is probably what you want if your strings are arrays of char (in C and other C-based languages) or std::string (in C++).

  • For programs requiring wide character support, use libncursesw5 Install libncursesw5.

    You'll especially need this if your strings are arrays of wchar_t (in C and other C-based languages) or std::wstring, std::u16string, or std::u32string (in C++).

Optionally, for help debugging your program, you might also want debug symbols (for debuggers such as gdb). For that, install libncurses5-dbg Install libncurses5-dbg or libncursesw5-dbg Install libncursesw5-dbg too.

See also the ncurses in Ubuntu page on Launchpad, which contains a list of the major ncurses packages in Ubuntu as well as version information for each currently supported Ubuntu release.

When you build your program with GCC (e.g., with the gcc or g++ commands), give it the argument -lncurses or -lncursesw, usually at the very end of the command. This links your program to the ncurses library. For example:

g++ -Wall -g -o hello hello.cpp -lncurses

That compiles hello.cpp to produce an executable with debug symbols (-g), called hello (-o hello), warning on most things you might want a warning about (-Wall), and linking to the regular (not wide character) ncurses library (-lncurses).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .