2 * Copyright (c) 2003, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * This file is part of the Contiki desktop OS.
31 * $Id: gui-shell.c,v 1.6 2008/11/10 22:10:32 oliverschmidt Exp $
35 #include "program-handler.h"
40 #include "lib/ctk-textentry-cmdline.h"
44 #ifdef SHELL_GUI_CONF_XSIZE
45 #define SHELL_GUI_XSIZE SHELL_GUI_CONF_XSIZE
47 #define SHELL_GUI_XSIZE 10
50 #ifdef SHELL_GUI_CONF_YSIZE
51 #define SHELL_GUI_YSIZE SHELL_GUI_CONF_YSIZE
53 #define SHELL_GUI_YSIZE 10
56 static struct ctk_window window
;
57 static char log
[SHELL_GUI_XSIZE
* SHELL_GUI_YSIZE
];
58 static struct ctk_label loglabel
=
59 {CTK_LABEL(0, 0, SHELL_GUI_XSIZE
, SHELL_GUI_YSIZE
, log
)};
60 static char command
[SHELL_GUI_XSIZE
- 1];
61 static struct ctk_textentry commandentry
=
62 {CTK_TEXTENTRY_INPUT(0, SHELL_GUI_YSIZE
, SHELL_GUI_XSIZE
- 2, 1, command
,
63 SHELL_GUI_XSIZE
- 2, ctk_textentry_cmdline_input
)};
65 PROCESS(shell_gui_process
, "Command shell");
67 AUTOSTART_PROCESSES(&shell_gui_process
);
69 /*-----------------------------------------------------------------------------------*/
71 shell_default_output(const char *str1
, int len1
, const char *str2
, int len2
)
73 static unsigned char i
;
75 for(i
= 1; i
< SHELL_GUI_YSIZE
; ++i
) {
76 memcpy(&log
[(i
- 1) * SHELL_GUI_XSIZE
],
77 &log
[i
* SHELL_GUI_XSIZE
], SHELL_GUI_XSIZE
);
80 if(str1
[len1
- 1] == '\n') {
83 if(str2
[len2
- 1] == '\n') {
87 strncpy(&log
[(SHELL_GUI_YSIZE
- 1) * SHELL_GUI_XSIZE
],
88 str1
, SHELL_GUI_XSIZE
);
89 if(len1
< SHELL_GUI_XSIZE
) {
90 strncpy(&log
[(SHELL_GUI_YSIZE
- 1) * SHELL_GUI_XSIZE
] + len1
,
91 str2
, SHELL_GUI_XSIZE
- len1
);
92 if(len1
+ len2
< SHELL_GUI_XSIZE
) {
93 log
[(SHELL_GUI_YSIZE
- 1) * SHELL_GUI_XSIZE
+ len1
+ len2
] = 0;
97 CTK_WIDGET_REDRAW(&loglabel
);
99 /*-----------------------------------------------------------------------------------*/
101 shell_prompt(char *str
)
104 /*-----------------------------------------------------------------------------------*/
105 PROCESS_THREAD(shell_gui_process
, ev
, data
)
109 ctk_window_new(&window
, SHELL_GUI_XSIZE
,
110 SHELL_GUI_YSIZE
+ 1, "Command shell");
111 CTK_WIDGET_ADD(&window
, &loglabel
);
112 /* CTK_WIDGET_SET_FLAG(&loglabel, CTK_WIDGET_FLAG_MONOSPACE);*/
113 CTK_WIDGET_ADD(&window
, &commandentry
);
114 /* CTK_WIDGET_SET_FLAG(&commandentry, CTK_WIDGET_FLAG_MONOSPACE);*/
115 CTK_WIDGET_FOCUS(&window
, &commandentry
);
125 ctk_window_open(&window
);
128 PROCESS_WAIT_EVENT();
130 if(ev
== ctk_signal_widget_activate
&&
131 data
== (process_data_t
)&commandentry
) {
132 int command_len
= (int)strlen(command
);
133 shell_default_output("> ", 2, command
, command_len
);
134 shell_input(command
, command_len
);
135 if(shell_gui_process
.state
) {
136 CTK_TEXTENTRY_CLEAR(&commandentry
);
137 CTK_WIDGET_REDRAW(&commandentry
);
139 } else if(ev
== ctk_signal_window_close
||
140 ev
== PROCESS_EVENT_EXIT
) {
142 ctk_window_close(&window
);
143 process_exit(&shell_gui_process
);
149 /*-----------------------------------------------------------------------------------*/