GithubHelp home page GithubHelp logo

ulfalizer / readline-and-ncurses Goto Github PK

View Code? Open in Web Editor NEW
54.0 7.0 4.0 41 KB

Example demonstrating combining of readline and ncurses

License: ISC License

Makefile 6.72% C 93.28%
readline ncurses

readline-and-ncurses's Introduction

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.

readline-and-ncurses's People

Contributors

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

readline-and-ncurses's Issues

Disable RL completion

// Disable completion. TODO: Is there a more robust way to do this?

You should be able to do this:

char buf[64] = "set disable-completion on";
rl_parse_and_bind(buf);

Just keep in mind that the rl_parse_and_bind() parameter could not be const, or it will segfault.
So rl_parse_and_bind("set disable-completion on"); is not possible.

Use keypad keycodes in ncurses

Hello !
Your code has greatly helped me to intergrate readline in ncurses for a student project.
I would like to replicate an irssi interface for an IRC-like protocol.
I want to catch keypresses events (like F(n) keys, or shift-arrow combinaisons) in the ncurses part and not forward them to readline. The catching is done with keypad, but as you wrote:

Do not enable keypad() since we want to pass unadulterated input to readline

How can I handle special keys events in the ncurses scope, while passing unadulterated input to readline ? Is is possible ? Maybe with a inverse transformation ?
What if I do keypad, then test if its a special char, if so disable keypad and somehow ungetch the character ?

Or is the only solution to wait and watch for the sequence of unadulterated input ? ncurses.faq.html#modified_keys

Thank you for your time.

PS: can I use your code ? Is is MIT licensed ?

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.