blob: 5f2f6aa9a4bb8a99ee9e81545c5ee02feb27d626 [file] [log] [blame]
adamdunkelsbe175262003-08-21 22:24:29 +00001/*
2 * Copyright (c) 2003, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
adamdunkels06f897e2004-06-06 05:59:20 +000013 * 3. The name of the author may not be used to endorse or promote
adamdunkelsbe175262003-08-21 22:24:29 +000014 * products derived from this software without specific prior
15 * written permission.
16 *
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.
28 *
29 * This file is part of the Contiki desktop OS.
30 *
oliverschmidted605d12005-05-05 23:32:01 +000031 * $Id: shell-gui.c,v 1.13 2005/05/05 23:32:01 oliverschmidt Exp $
adamdunkelsbe175262003-08-21 22:24:29 +000032 *
33 */
34
adamdunkelsf2f8cb22004-07-04 11:35:07 +000035#include "ek.h"
36
adamdunkelsbe175262003-08-21 22:24:29 +000037#include "program-handler.h"
38#include "loader.h"
adamdunkels09830602003-09-01 22:22:36 +000039
adamdunkelsbe175262003-08-21 22:24:29 +000040#include "uip.h"
adamdunkelsbe175262003-08-21 22:24:29 +000041#include "uip_arp.h"
42#include "resolv.h"
43
44#include "shell.h"
45
oliverschmidted605d12005-05-05 23:32:01 +000046#include "ctk-textentry-cmdline.h"
47
adamdunkelsf2f8cb22004-07-04 11:35:07 +000048#include "shell-gui-conf.h"
49
adamdunkelsbe175262003-08-21 22:24:29 +000050#include <string.h>
51
adamdunkelsbe175262003-08-21 22:24:29 +000052
53static struct ctk_window window;
adamdunkelsf2f8cb22004-07-04 11:35:07 +000054static char log[SHELL_GUI_CONF_XSIZE * SHELL_GUI_CONF_YSIZE];
adamdunkelsbe175262003-08-21 22:24:29 +000055static struct ctk_label loglabel =
adamdunkelsf2f8cb22004-07-04 11:35:07 +000056 {CTK_LABEL(0, 0, SHELL_GUI_CONF_XSIZE, SHELL_GUI_CONF_YSIZE, log)};
oliverschmidtd2f04de2005-04-28 20:56:15 +000057static char command[SHELL_GUI_CONF_XSIZE - 1];
adamdunkelsbe175262003-08-21 22:24:29 +000058static struct ctk_textentry commandentry =
oliverschmidted605d12005-05-05 23:32:01 +000059 {CTK_TEXTENTRY_INPUT(0, SHELL_GUI_CONF_YSIZE, SHELL_GUI_CONF_XSIZE - 2, 1, command,
PulkoMandyeb45bf92014-06-26 13:28:43 +020060 SHELL_GUI_CONF_XSIZE - 2, NULL /*ctk_textentry_cmdline_input*/)};
adamdunkelsbe175262003-08-21 22:24:29 +000061
adamdunkelsf2f8cb22004-07-04 11:35:07 +000062EK_EVENTHANDLER(eventhandler, ev, data);
63EK_PROCESS(p, "Command shell", EK_PRIO_NORMAL,
64 eventhandler, NULL, NULL);
65static ek_id_t id = EK_ID_NONE;
66
67/*static DISPATCHER_SIGHANDLER(sighandler, s, data);
adamdunkelsbe175262003-08-21 22:24:29 +000068static struct dispatcher_proc p =
69 {DISPATCHER_PROC("Command shell", shell_idle, sighandler,
70 NULL)};
adamdunkelsf2f8cb22004-07-04 11:35:07 +000071 static ek_id_t id;*/
adamdunkelsbe175262003-08-21 22:24:29 +000072
73/*-----------------------------------------------------------------------------------*/
74void
75shell_quit(char *str)
76{
77 ctk_window_close(&window);
adamdunkelsf2f8cb22004-07-04 11:35:07 +000078 ek_exit();
adamdunkelsbe175262003-08-21 22:24:29 +000079 id = EK_ID_NONE;
80 LOADER_UNLOAD();
81}
82/*-----------------------------------------------------------------------------------*/
83void
Adrien Destugues69a6e722017-06-03 10:17:17 +020084shell_output(const char *str1, const char *str2)
adamdunkelsbe175262003-08-21 22:24:29 +000085{
86 static unsigned char i, len;
87
adamdunkelsf2f8cb22004-07-04 11:35:07 +000088 for(i = 1; i < SHELL_GUI_CONF_YSIZE; ++i) {
89 memcpy(&log[(i - 1) * SHELL_GUI_CONF_XSIZE],
90 &log[i * SHELL_GUI_CONF_XSIZE], SHELL_GUI_CONF_XSIZE);
adamdunkelsbe175262003-08-21 22:24:29 +000091 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +000092 memset(&log[(SHELL_GUI_CONF_YSIZE - 1) * SHELL_GUI_CONF_XSIZE],
93 0, SHELL_GUI_CONF_XSIZE);
adamdunkelsbe175262003-08-21 22:24:29 +000094
95 len = strlen(str1);
96
adamdunkelsf2f8cb22004-07-04 11:35:07 +000097 strncpy(&log[(SHELL_GUI_CONF_YSIZE - 1) * SHELL_GUI_CONF_XSIZE],
98 str1, SHELL_GUI_CONF_XSIZE);
99 if(len < SHELL_GUI_CONF_XSIZE) {
100 strncpy(&log[(SHELL_GUI_CONF_YSIZE - 1) * SHELL_GUI_CONF_XSIZE] + len,
101 str2, SHELL_GUI_CONF_XSIZE - len);
adamdunkelsbe175262003-08-21 22:24:29 +0000102 }
103
104 CTK_WIDGET_REDRAW(&loglabel);
105}
106/*-----------------------------------------------------------------------------------*/
adamdunkels8e5d9902003-10-14 11:23:04 +0000107void
108shell_prompt(char *str)
109{
110
111}
112/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000113LOADER_INIT_FUNC(shell_gui_init, arg)
adamdunkelsbe175262003-08-21 22:24:29 +0000114{
adamdunkels8bb5cca2003-08-24 22:41:31 +0000115 arg_free(arg);
116
adamdunkelsbe175262003-08-21 22:24:29 +0000117 if(id == EK_ID_NONE) {
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000118 id = ek_start(&p);
adamdunkelsbe175262003-08-21 22:24:29 +0000119 }
adamdunkelsbe175262003-08-21 22:24:29 +0000120}
121/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000122EK_EVENTHANDLER(eventhandler, ev, data)
adamdunkelsbe175262003-08-21 22:24:29 +0000123{
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000124 EK_EVENTHANDLER_ARGS(ev, data);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000125
126 if(ev == EK_EVENT_INIT) {
PulkoMandyeb45bf92014-06-26 13:28:43 +0200127 commandentry.input = (void*)ctk_textentry_cmdline_input;
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000128 ctk_window_new(&window, SHELL_GUI_CONF_XSIZE,
129 SHELL_GUI_CONF_YSIZE + 1, "Command shell");
130 CTK_WIDGET_ADD(&window, &loglabel);
131 /* CTK_WIDGET_SET_FLAG(&loglabel, CTK_WIDGET_FLAG_MONOSPACE);*/
132 CTK_WIDGET_ADD(&window, &commandentry);
133 /* CTK_WIDGET_SET_FLAG(&commandentry, CTK_WIDGET_FLAG_MONOSPACE);*/
134 CTK_WIDGET_FOCUS(&window, &commandentry);
oliverschmidtd2f04de2005-04-28 20:56:15 +0000135 memset(log, 0, sizeof(log));
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000136
137 shell_init();
oliverschmidt02949e12005-04-24 13:38:35 +0000138 ctk_window_open(&window);
139 shell_start();
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000140 } else if(ev == ctk_signal_widget_activate &&
adamdunkelsbe175262003-08-21 22:24:29 +0000141 data == (ek_data_t)&commandentry) {
adamdunkels8e5d9902003-10-14 11:23:04 +0000142 shell_output("> ", command);
adamdunkelsbe175262003-08-21 22:24:29 +0000143 shell_input(command);
144 CTK_TEXTENTRY_CLEAR(&commandentry);
adamdunkelsbe175262003-08-21 22:24:29 +0000145 CTK_WIDGET_REDRAW(&commandentry);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000146 } else if(ev == ctk_signal_window_close ||
147 ev == EK_EVENT_REQUEST_EXIT) {
adamdunkelsbe175262003-08-21 22:24:29 +0000148 shell_quit(NULL);
adamdunkels30c70da2004-08-20 21:37:39 +0000149 } else {
150 shell_eventhandler(ev, data);
adamdunkelsbe175262003-08-21 22:24:29 +0000151 }
152}
153/*-----------------------------------------------------------------------------------*/