NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/56647: Fix misbehaviour in libedit support for readline



Hi Christos,

On 1/24/22 15:28, Christos Zoulas wrote:
Hi Walter, thanks for taking the time to write a reproducer. Just attach it to a mail message
and it will be added to this request. In the meantime I will commit the changes.

Here is the test program I use to test my changes. I this based on and example I found and in the code found in connman [1][2] and bluez [3][4].

Unfortunately I still have issues, the message is not rendered properly. With the example I attach the output is

WOOP> Typingwarning something needs your attentionTypingWOOP> Typing

but it shoud be

WOOP> Typing
warning something needs your attention
WOOP> Typing

However at least now the message is seeing and the test typed is restored.

I'll keep trying to improve it as I still have time, but I'm not sure if I will be able to have a better solution.

Please note that my test are done under Apertis (Linux Debian derivative), but my understanding is that this type of changes should apply without issues on NetBSD.

Regards,

Walter

[1] https://salsa.debian.org/debian/connman
[2] https://gitlab.apertis.org/pkg/connman
[3] https://salsa.debian.org/bluetooth-team/bluez
[4] https://gitlab.apertis.org/pkg/bluez

Best,

christos


--
Walter Lozano
Collabora Ltd.
// Example from http://www.mcld.co.uk/blog/2009/simple-gnu-readline-callback-style-example.html

#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>  /* for free() */
#include <unistd.h> /* for usleep() */
#include <pthread.h>
#include <string.h>

char running = 1;

// The function that'll get passed each line of input
void my_rlhandler(char* line);
void my_rlhandler(char* line){
        if(line==NULL){
                // Ctrl-D will allow us to exit nicely
                printf("\nNULLBURGER\n");
                running = 0;
        }else{
                if(*line!=0){
                          // If line wasn't empty, store it so that uparrow retrieves it
                        add_history(line);
                }
                        printf("Your input was:\n%s\n", line);
                        free(line);
        }
}

//#define USE_PRINTF

void * print_warning(void * nothing){
        int saved_point;
        char * saved_line;

        usleep(5000000);
#ifdef USE_PRINTF
        printf("warning something needs your attention\n");
        rl_redisplay();
        usleep(1000000);
#else
        saved_point = rl_point;
        rl_save_prompt();
        saved_line = rl_copy_text(0, rl_end);
        rl_replace_line("", 0);
        rl_message("warning something needs your attention\n");
        rl_redisplay();
        //usleep(1000000);
        rl_restore_prompt();
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
#endif
        return NULL;
}

// The main entry-point for the program
int main()
{
        const char *prompt = "WOOP> ";
        pthread_t thread_id;

        // Install the handler
        rl_callback_handler_install(prompt, (rl_vcpfunc_t*) &my_rlhandler);

        // Enter the event loop (simple example, so it doesn't do much except wait)
        running = 1;

        pthread_create(&thread_id, NULL, &print_warning, NULL);

        while(running){
                //printf("waiting\n");
                usleep(10000);
                rl_callback_read_char();
        };
        printf("\nEvent loop has exited\n");

        // Remove the handler
        rl_callback_handler_remove();

        return 0; // happy ending
}


Home | Main Index | Thread Index | Old Index