3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <net/hostname.h>
30 static consolelog_t clog_list
;
31 static consolelog_t
*clog_curr
;
33 static unsigned clog_num
;
35 extern task_t
*_curr_task
;
45 //DPRINT ("currtty->task %s | _curr_task %s\n", currtty->task->name, _curr_task->name);
53 if (key
== 8 && currtty
->shell_len
== 0 || key
== 27)
56 if (currtty
->shell_len
< 64)
57 tty_write (currtty
, c
, 1);
59 if (key
== '\n') { // we press enter
60 currtty
->shell
[currtty
->shell_len
] = '\0';
61 currtty
->shell_len
= 0;
64 /* if you has wroted some text, and backspace is pressed, lets move cursor back */
65 if (key
== '\b' && currtty
->shell_len
> 0) {
66 currtty
->shell_len
--; // first we have to descrease text length
67 currtty
->shell
[currtty
->shell_len
] = '\0'; // we can put \0 character under cursor
68 //printf ("len: %d\n", currtty->shell_len);
70 else if (currtty
->shell_len
< 64) { /* you type normal text */
71 currtty
->shell
[currtty
->shell_len
] = key
;
72 currtty
->shell_len
++;
85 unsigned consolelog_list ()
89 for (c
= clog_list
.next
; c
!= &clog_list
; c
= c
->next
)
90 printf ("%s\n", c
->cmd
);
92 printf ("-> %d\n", clog_num
);
97 unsigned consolelog_prev ()
102 if (!currtty
->logged
)
108 /* go to previous entry of log list */
109 consolelog_t
*prev
= clog_curr
;
114 unsigned short l
= currtty
->shell_len
;
116 /* delete all current characters from line () */
118 tty_write (currtty
, "\b", 1);
123 memcpy (currtty
->shell
, prev
->cmd
, prev
->len
);
124 currtty
->shell
[prev
->len
] = '\0';
126 currtty
->shell_len
= prev
->len
;
130 tty_write (currtty
, currtty
->shell
, prev
->len
);
132 clog_curr
= prev
->prev
;
137 unsigned consolelog_next ()
139 if (!currtty
->active
)
142 if (!currtty
->logged
)
148 /* go to next entry of log list */
149 consolelog_t
*next
= clog_curr
->next
;
154 unsigned short l
= currtty
->shell_len
;
156 /* delete all current characters from line () */
158 tty_write (currtty
, "\b", 1);
163 memcpy (currtty
->shell
, next
->cmd
, next
->len
);
164 currtty
->shell
[next
->len
] = '\0';
166 currtty
->shell_len
= next
->len
;
170 tty_write (currtty
, currtty
->shell
, next
->len
);
177 unsigned int console_refresh ()
179 currtty
->shell_len
= 0;
182 if (currtty
->user
->attrib
== USER_GROUP_ADMIN
) {
184 printf ("%s@%s ", currtty
->user
->name
, hostname_get ());
186 printf ("%s # ", (char *) env_get ("PWD"));
189 printf ("%s@%s ", currtty
->user
->name
, hostname_get ());
191 printf ("%s $ ", (char *) env_get ("PWD"));
200 unsigned int init_console ()
205 clog_list
.next
= &clog_list
;
206 clog_list
.prev
= &clog_list
;
213 unsigned len
= strlen (currtty
->shell
);
215 /* commands are active only, if you type one or more chars */
220 /* save this command to consolelog now */
223 /* when we reach limit, lets delete first one from list */
224 if (clog_num
> CONFIG_UI_CONSOLELOG
) {
225 ctx
= clog_list
.next
;
227 if (ctx
!= &clog_list
&& ctx
) {
230 ctx
->next
->prev
= ctx
->prev
;
231 ctx
->prev
->next
= ctx
->next
;
239 // alloc and init context
240 ctx
= (consolelog_t
*) kmalloc (sizeof (consolelog_t
));
245 ctx
->cmd
= (char *) kmalloc (sizeof (char) * (len
+ 1));
250 memcpy (ctx
->cmd
, currtty
->shell
, len
);
251 ctx
->cmd
[len
] = '\0';
255 ctx
->next
= &clog_list
;
256 ctx
->prev
= clog_list
.prev
;
257 ctx
->prev
->next
= ctx
;
258 ctx
->next
->prev
= ctx
;
260 /* increase number of list content */
263 /* go to last entry */
268 for(i
= 0; i
< currtty
->shell_len
; i
++)
269 currtty
->shell
[i
] = '\0';