3 * Basic shell for Quarn
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 class shell
: public hydra::application
{
32 void command(p
<hydra::form
>);
35 hydra_app_class(shell
)
38 set_ui(hydra::ui::ui_console
);
39 delegate
<void, p
<hydra::form
> > onFilled
;
40 onFilled
.method(this, &shell::command
);
42 hydra::form
*welc
= new hydra::form(this);
43 new hydra::label(welc
, "Welcome to Quarn OS\n\n","welcome");
45 hydra::form
*main
= new hydra::form(this, onFilled
);
46 new hydra::label(main
, "quarnos> ", "cmd_prompt");
47 new hydra::edit(main
, "cmd");
50 void shell::command(p
<hydra::form
> query
) {
51 string cmd
= query
.cast
<hydra::form
>()->get_element("cmd").cast
<hydra::edit
>()->get_value();
53 if (!strcmp(cmd
,"exit"))
55 else if (!strcmp(cmd
,"info")) {
56 hydra::form
*msg
= new hydra::form(this);
57 new hydra::label(msg
, "Copyright (C) 2008-2009 Pawel Dziepak\n","copy");
58 } else if (!strncmp(cmd
, "cat ", 4)) {
59 string
name(&((const char*)cmd
)[4]);
60 hydra::io
*fp
= hydra::io::open_file(name
);
61 hydra::form
*msg
= new hydra::form(this);
62 new hydra::label(msg
, fp
->readall(), "file");
63 } else if (!strcmp(cmd
, "ls")) {
64 hydra::io
*dir
= hydra::io::enter_dir("/");
65 hydra::form
*msg
= new hydra::form(this);
66 list
<hydra::io
*> ldir
= dir
->list_dir();
67 for (int i
= 0; i
< ldir
.get_count(); i
++)
68 new hydra::label(msg
, ldir
[i
]->name() + "\n", "file");
69 } else if (!strcmp(cmd
, "help")) {
70 hydra::form
*msg
= new hydra::form(this);
71 new hydra::label(msg
, "Command list:\n\tcat\t\tshows content of the file\n\tinfo\t\tshows copyright information\n\thelp\t\tshows list of commands\n\tls\t\tshows files in current directory\n\texit\t\thalts shell\n","help");
73 hydra::form
*msg
= new hydra::form(this);
74 new hydra::label(msg
, "No such command, type `help' for more information\n","nocmd");