4 Copyright (C) 2001 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "fe-windows.h"
28 static GIOChannel *stdin_channel;
30 static GString *input;
32 static void sig_gui_printtext(WINDOW_REC *window, void *fgcolor,
33 void *bgcolor, void *pflags,
34 char *str, void *level)
44 static void sig_gui_printtext_finished(WINDOW_REC *window)
50 static void sig_window_created(WINDOW_REC *window)
56 static void readline(void)
58 unsigned char buffer[128];
62 ret = read(0, buffer, sizeof(buffer));
63 if (ret == 0 || (ret == -1 && errno != EINTR)) {
65 signal_emit("command quit", 1, "Lost terminal");
69 for (i = 0; i < ret; i++)
70 g_string_append_c(input, buffer[i]);
72 p = strchr(input->str, '\n');
75 signal_emit("send command", 3, input->str,
76 active_win->active_server, active_win->active);
78 g_string_erase(input, 0, (int) (p-input->str)+1);
82 void term_dummy_init(void)
85 input = g_string_new(NULL);
87 signal_add("gui print text", (SIGNAL_FUNC) sig_gui_printtext);
88 signal_add("gui print text finished", (SIGNAL_FUNC) sig_gui_printtext_finished);
89 signal_add("window created", (SIGNAL_FUNC) sig_window_created);
91 stdin_channel = g_io_channel_unix_new(0);
92 readtag = g_input_add_full(stdin_channel,
93 G_PRIORITY_HIGH, G_INPUT_READ,
94 (GInputFunction) readline, NULL);
95 g_io_channel_unref(stdin_channel);
98 void term_dummy_deinit(void)
100 signal_remove("gui print text", (SIGNAL_FUNC) sig_gui_printtext);
101 signal_remove("gui print text finished", (SIGNAL_FUNC) sig_gui_printtext_finished);
102 signal_remove("window created", (SIGNAL_FUNC) sig_window_created);
104 g_source_remove(readtag);
105 g_string_free(input, TRUE);