src/console.c
author Tero Marttila <terom@fixme.fi>
Thu, 21 May 2009 16:23:27 +0300
branchlua-threads
changeset 206 47837a6bbbea
parent 203 ffdf53fd0337
child 212 ddc79529a1e0
permissions -rw-r--r--
fix console to ignore input while waiting, and rename have_input -> have_prompt
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#include "console.h"
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
     2
#include "log.h"
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
     4
#include <stdlib.h>
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#include <unistd.h>
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include <stdio.h>
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include <readline/readline.h>
95
6bb8ef294689 add the add_history() call to console.c
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
     8
#include <readline/history.h>
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
     9
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    10
#include <signal.h>
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
#include <assert.h>
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    13
struct console {
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    14
    /** Configuration */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    15
    struct console_config config;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    16
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    17
    /** Input event */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    18
    struct event *ev;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    19
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    20
    /** Callback functions */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    21
    const struct console_callbacks *callbacks;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    22
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    23
    /** Callback context argument */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    24
    void *cb_arg;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    25
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    26
    /** Old SIGINT handler */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    27
    struct sigaction old_sigint;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    28
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    29
    /** Already initialized? */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    30
    bool initialized;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    31
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    32
    /** Set as log output function? */
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    33
    bool log_output;
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    34
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    35
    /** Prompt displayed? */
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    36
    bool have_prompt;
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    37
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    38
    /** Waiting for line to be processed */
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    39
    bool waiting;
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    40
};
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
    41
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
/** The global console state */
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
static struct console _console;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
/**
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
 * Our stdin input handler
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
 */
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
static void console_input (int fd, short what, void *arg)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
    struct console *console = arg;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
    (void) fd;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
    (void) what;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    55
    if (console->waiting)
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    56
        // can't feed readline input while it's disabled
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    57
        return log_warn("discrding input while waiting");
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    58
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    59
    else
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    60
        // tell readline to process it
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    61
        rl_callback_read_char();
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
/**
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
 * Our readline line handler
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
 */
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
static void console_line (char *line)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
    struct console *console = &_console;
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    70
    enum console_line_status status = CONSOLE_CONTINUE;
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    71
    
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    72
    // special-case EOF
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    73
    if (!line) {
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    74
        // prettify
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    75
        rl_crlf();
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    76
        rl_on_new_line();
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    78
        if (console->callbacks->on_eof)
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    79
            console->callbacks->on_eof(console->cb_arg);
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    80
        
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    81
        return;
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    82
    }
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
    83
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    84
    // update state for console_print during processing
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    85
    console->have_prompt = false;
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
    86
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
    // invoke the console callback
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
    88
    if (console->callbacks && console->callbacks->on_line)
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    89
        status = console->callbacks->on_line(line, console->cb_arg);
95
6bb8ef294689 add the add_history() call to console.c
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    90
    
6bb8ef294689 add the add_history() call to console.c
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    91
    // add to history mechanism
6bb8ef294689 add the add_history() call to console.c
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    92
    add_history(line);
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
    93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
    94
    // release the line
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
    95
    free(line);
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    96
    
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    97
    switch (status) {
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
    98
        case CONSOLE_CONTINUE:
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
    99
            // the prompt will be displayed again
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   100
            console->have_prompt = true;
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   101
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   102
            break;
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   103
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   104
        case CONSOLE_WAIT:
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   105
            // deactivate our read event
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   106
            if (event_del(console->ev))
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   107
                log_warn("unable to deactivate console read event");
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   108
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   109
            // remove the readline stuff to stop it from displaying the prompt
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   110
            rl_callback_handler_remove();
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   111
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   112
            // ignore input
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   113
            console->waiting = true;
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   114
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   115
            break;
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   116
    }
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   119
static void on_sigint (int sig)
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   120
{
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   121
    struct console *console = &_console;
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   122
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   123
    (void) sig;
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   124
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   125
    // interrupt the input line
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   126
    // XXX: is this the right function to call?
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   127
    rl_free_line_state();
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   128
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   129
    // redisplay on new line
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   130
    rl_crlf();
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   131
    rl_callback_handler_install(console->config.prompt, console_line);
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   132
}
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   133
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   134
err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config,
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   135
        const struct console_callbacks *callbacks, void *cb_arg, struct error_info *err)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
    struct console *console = &_console;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
    // check it's not already initialized
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
    assert(!console->initialized);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   142
    // store
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   143
    console->config = *config;
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   144
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   145
    // store callbacks?
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   146
    if (callbacks)
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   147
        console_set_callbacks(console, callbacks, cb_arg);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   149
    // setup the input event
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
    if ((console->ev = event_new(ev_base, STDIN_FILENO, EV_READ | EV_PERSIST, &console_input, console)) == NULL)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
        JUMP_SET_ERROR(err, ERR_EVENT_NEW);
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   152
    
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   153
    // set our SIGINT handler
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   154
    struct sigaction sigact;
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   155
    
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   156
    memset(&sigact, 0, sizeof(sigact));
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   157
    sigact.sa_handler = on_sigint;
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   158
    sigaction(SIGINT, &sigact, &console->old_sigint);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   160
    // setup state for initial readline prompt
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   161
    console->have_prompt = true;
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   162
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
    // setup readline
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 137
diff changeset
   164
    rl_callback_handler_install(config->prompt, console_line);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
    // mark it as initialized
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
    console->initialized = true;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
    // enable input
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    if (event_add(console->ev, NULL))
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        JUMP_SET_ERROR(err, ERR_EVENT_ADD);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
    // ok
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
    *console_ptr = console;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
    return SUCCESS;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
error:
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   179
    console_destroy(console);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   180
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   181
    return ERROR_CODE(err);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   184
void console_set_callbacks (struct console *console, const struct console_callbacks *callbacks, void *cb_arg)
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   185
{
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   186
    console->callbacks = callbacks;
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   187
    console->cb_arg = cb_arg;
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   188
}
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   189
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   190
void console_continue (struct console *console)
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   191
{
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   192
    if (!console->waiting)
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   193
        return;
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   194
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   195
    // re-enable input
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   196
    console->waiting = false;
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   197
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   198
    if (event_add(console->ev, NULL))
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   199
        log_fatal("unable to re-enable console read event");
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   200
    
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   201
    // the prompt will be displayed again
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   202
    console->have_prompt = true;
203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   203
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   204
    // re-setup readline with prompt
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   205
    rl_callback_handler_install(console->config.prompt, console_line);
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   206
}
ffdf53fd0337 implement lua_threads, nexus:sleep test func, and basic support in console/lua_console... doesn't actually work yet
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   207
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   208
err_t console_print (struct console *console, const char *line)
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   209
{
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   210
    if (console->have_prompt)
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   211
        // don't interrupt current input line
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   212
        rl_crlf();
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   213
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   214
    // output the line
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   215
    if (printf("%s\n", line) < 0)
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   216
        return _ERR_GENERAL;
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   217
    
206
47837a6bbbea fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents: 203
diff changeset
   218
    if (console->have_prompt) {
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   219
        // restore input
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   220
        rl_on_new_line();
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   221
        rl_redisplay();
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   222
    }
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   223
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   224
    // ok
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   225
    return SUCCESS;
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   226
}
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   227
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   228
/**
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   229
 * Our log_output_func implementation
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   230
 */
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   231
static void console_log_output_func (const char *line, void *_console)
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   232
{
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   233
    struct console *console = _console;
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   234
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   235
    console_print(console, line);
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   236
}
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   237
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   238
void console_set_log_output (struct console *console)
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   239
{
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   240
    // replace old one
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   241
    log_set_func(console_log_output_func, console);
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   242
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   243
    // mark
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   244
    console->log_output = true;
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   245
}
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   246
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   247
void console_destroy (struct console *console)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
{
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   249
    if (console->log_output)
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   250
        // unset ourselves as the log handler
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   251
        log_set_func(NULL, NULL);
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   252
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
    // remove the input event
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   254
    if (console->ev)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   255
        event_free(console->ev); 
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   256
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   257
    console->ev = NULL;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   258
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   259
    // de-init rl?
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   260
    if (console->initialized)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   261
        rl_callback_handler_remove();
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   262
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   263
    console->initialized = false;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   264
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   265
    // restore signal handler
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   266
    sigaction(SIGINT, &console->old_sigint, NULL);
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   267
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   268
    // remove stored stuff
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   269
    console->callbacks = console->cb_arg = NULL;
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   270
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   271