All Projects → ulfalizer → readline-and-ncurses

ulfalizer / readline-and-ncurses

Licence: ISC license
Example demonstrating combining of readline and ncurses

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to readline-and-ncurses

Twterm
A full-featured TUI Twitter client
Stars: ✭ 186 (+272%)
Mutual labels:  ncurses, readline
Ncpamixer
ncurses PulseAudio Mixer
Stars: ✭ 234 (+368%)
Mutual labels:  ncurses
Mandown
man-page inspired Markdown viewer
Stars: ✭ 173 (+246%)
Mutual labels:  ncurses
Cursive
A Text User Interface library for the Rust programming language
Stars: ✭ 2,613 (+5126%)
Mutual labels:  ncurses
2048 Cli
The game 2048 for your Linux terminal (https://github.com/gabrielecirulli/2048)
Stars: ✭ 176 (+252%)
Mutual labels:  ncurses
Viw
VI Worsened, a lightweight and fun VI clone.
Stars: ✭ 212 (+324%)
Mutual labels:  ncurses
Mocp
Music On Console Player
Stars: ✭ 171 (+242%)
Mutual labels:  ncurses
NCURSES-Programming-HOWTO-examples
CMake examples for code in http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html
Stars: ✭ 114 (+128%)
Mutual labels:  ncurses
Joshuto
ranger-like terminal file manager written in Rust
Stars: ✭ 224 (+348%)
Mutual labels:  ncurses
Goaccess
GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
Stars: ✭ 14,096 (+28092%)
Mutual labels:  ncurses
Tty Solitaire
Play solitaire in your terminal!
Stars: ✭ 178 (+256%)
Mutual labels:  ncurses
Neomutt
✉️ Teaching an Old Dog New Tricks -- IRC: #neomutt on irc.libera.chat
Stars: ✭ 2,343 (+4586%)
Mutual labels:  ncurses
Chkservice
Systemd units manager with ncurses, terminal interface
Stars: ✭ 219 (+338%)
Mutual labels:  ncurses
Tremc
Curses interface for transmission
Stars: ✭ 174 (+248%)
Mutual labels:  ncurses
Fui
Add CLI & form interface to your program. Docs: https://docs.rs/fui
Stars: ✭ 244 (+388%)
Mutual labels:  ncurses
Corewar
A reproduction of the Core War game. Assembly compiler, Virtual Machine and GUI.
Stars: ✭ 173 (+246%)
Mutual labels:  ncurses
Cuishark
A protocol analyzer like a wireshark on CUI. cuishark is using libwireshark to analyze packets. https://cuishark.slankdev.net
Stars: ✭ 208 (+316%)
Mutual labels:  ncurses
todo list rust
Simple Ncurses Todo List ☑
Stars: ✭ 19 (-62%)
Mutual labels:  ncurses
Sc Im
sc-im - Spreadsheet Calculator Improvised -- An ncurses spreadsheet program for terminal
Stars: ✭ 3,081 (+6062%)
Mutual labels:  ncurses
Tmatrix
Terminal based replica of the digital rain from The Matrix.
Stars: ✭ 227 (+354%)
Mutual labels:  ncurses

Example demonstrating combining of readline and ncurses

Features

Supports seamless and efficient terminal resizing and multibyte/combining/wide characters. (Wide characters are those that use more than one terminal column.)

One of the trickier aspects is that readline only exports the cursor position as a byte offset (rl_point), which won't correspond to the correct terminal cursor column for many strings with special characters. We therefore have to calculate the terminal cursor column ourselves. readline itself does it as part of the default rl_redisplay() function.

Limitations

  • Some invalid strings and meta characters could still cause the cursor position to be off (though it's only a visual annoyance).

  • Entering multibyte characters during search (e.g., Ctrl-R) does not work, due to a readline issue. The only workaround I've found is to let readline directly from stdin instead (e.g., via a select(2) loop: The readline manual has an example program). Buffering bytes until they form a complete multibyte character (e.g., via get_wch() + wcrtomb(3)) doesn't help either.

    A neat setup on Linux is to use signalfd(2) (libevent might be a portable option) to catch the SIGWINCH generated by the terminal resize in the select(2) (or epoll(7)) loop and then calling resizeterm() and updating the windows (the manual resizeterm() is needed since we override ncurses' default SIGWINCH handler). I have a WIP that uses that approach in a branch for another project. I could push it on request.

  • To keep things simple, the readline (bottom) window does not scroll horizontally. It would require some care to get special characters right.

Screenshot

screenshot

The contents of the top window is set to whatever is entered. To exit, press Ctrl-D on an empty line.

License

See LICENSE.txt. SPDX license identifiers are used in the source code.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].