author | Tero Marttila <terom@fixme.fi> |
Wed, 27 May 2009 23:57:48 +0300 | |
branch | new-lib-errors |
changeset 217 | 7728d6ec3abf |
parent 212 | ddc79529a1e0 |
permissions | -rw-r--r-- |
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 |
} |
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
|
118 |
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
|
119 |
{ |
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 |
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
|
121 |
|
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 |
(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
|
123 |
|
212
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
124 |
if (console->waiting) { |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
125 |
// notify user |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
126 |
if (console->callbacks->on_interrupt) |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
127 |
console->callbacks->on_interrupt(console->cb_arg); |
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
|
128 |
|
212
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
129 |
} else { |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
130 |
// interrupt the input line |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
131 |
// XXX: is this the right function to call? |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
132 |
rl_free_line_state(); |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
133 |
|
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
134 |
// redisplay on new line |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
135 |
rl_crlf(); |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
136 |
rl_callback_handler_install(console->config.prompt, console_line); |
ddc79529a1e0
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
Tero Marttila <terom@fixme.fi>
parents:
206
diff
changeset
|
137 |
} |
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
|
138 |
} |
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
|
139 |
|
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
140 |
err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config, |
217 | 141 |
const struct console_callbacks *callbacks, void *cb_arg, error_t *err) |
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
142 |
{ |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
143 |
struct console *console = &_console; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
144 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
145 |
// check it's not already initialized |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
146 |
assert(!console->initialized); |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
147 |
|
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
|
148 |
// 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
|
149 |
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
|
150 |
|
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
|
151 |
// 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
|
152 |
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
|
153 |
console_set_callbacks(console, callbacks, cb_arg); |
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
154 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
155 |
// setup the input event |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
|
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
|
159 |
// 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
|
160 |
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
|
161 |
|
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
|
162 |
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
|
163 |
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
|
164 |
sigaction(SIGINT, &sigact, &console->old_sigint); |
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
165 |
|
206
47837a6bbbea
fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents:
203
diff
changeset
|
166 |
// 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
|
167 |
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
|
168 |
|
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
169 |
// 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
|
170 |
rl_callback_handler_install(config->prompt, console_line); |
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
171 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
172 |
// mark it as initialized |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
173 |
console->initialized = true; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
174 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
// enable input |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
176 |
if (event_add(console->ev, NULL)) |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
JUMP_SET_ERROR(err, ERR_EVENT_ADD); |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
178 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
179 |
// ok |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
180 |
*console_ptr = console; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
181 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
182 |
return SUCCESS; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
183 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
184 |
error: |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
185 |
console_destroy(console); |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
186 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
187 |
return ERROR_CODE(err); |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
188 |
} |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
189 |
|
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
|
190 |
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
|
191 |
{ |
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
|
192 |
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
|
193 |
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
|
194 |
} |
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
|
195 |
|
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
|
196 |
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
|
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 (!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
|
199 |
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
|
200 |
|
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 |
// 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
|
202 |
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
|
203 |
|
206
47837a6bbbea
fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents:
203
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
|
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
|
207 |
// 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
|
208 |
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
|
209 |
|
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
|
210 |
// 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
|
211 |
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
|
212 |
} |
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
|
213 |
|
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
214 |
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
|
215 |
{ |
206
47837a6bbbea
fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents:
203
diff
changeset
|
216 |
if (console->have_prompt) |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
217 |
// don't interrupt current input line |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
218 |
rl_crlf(); |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
219 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
220 |
// output the line |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
221 |
if (printf("%s\n", line) < 0) |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
222 |
return _ERR_GENERAL; |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
223 |
|
206
47837a6bbbea
fix console to ignore input while waiting, and rename have_input -> have_prompt
Tero Marttila <terom@fixme.fi>
parents:
203
diff
changeset
|
224 |
if (console->have_prompt) { |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
225 |
// restore input |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
226 |
rl_on_new_line(); |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
227 |
rl_redisplay(); |
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 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
230 |
// ok |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
231 |
return SUCCESS; |
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 |
|
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 |
* Our log_output_func implementation |
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 |
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
|
238 |
{ |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
239 |
struct console *console = _console; |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
240 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
241 |
console_print(console, line); |
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 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
244 |
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
|
245 |
{ |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
246 |
// replace old one |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
247 |
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
|
248 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
249 |
// mark |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
250 |
console->log_output = true; |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
251 |
} |
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 |
void console_destroy (struct console *console) |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
254 |
{ |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
255 |
if (console->log_output) |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
256 |
// unset ourselves as the log handler |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
257 |
log_set_func(NULL, NULL); |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
95
diff
changeset
|
258 |
|
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
259 |
// remove the input event |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
260 |
if (console->ev) |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
261 |
event_free(console->ev); |
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->ev = NULL; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
264 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
265 |
// de-init rl? |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
266 |
if (console->initialized) |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
267 |
rl_callback_handler_remove(); |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
268 |
|
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
269 |
console->initialized = false; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
270 |
|
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
|
271 |
// 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
|
272 |
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
|
273 |
|
92
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
274 |
// remove stored stuff |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
275 |
console->callbacks = console->cb_arg = NULL; |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
276 |
} |
99661e5aac91
add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
277 |