diff --git a/src/apps/terminal/Terminal.rdef b/src/apps/terminal/Terminal.rdef index 2d07407e0c..6783749bd1 100644 --- a/src/apps/terminal/Terminal.rdef +++ b/src/apps/terminal/Terminal.rdef @@ -141,7 +141,7 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array { $"FFFFFFFFFFFFFF0000000EFF00000EFF" }; -resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.Be-SHEL"; +resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.obos.terminal"; resource(2, "BEOS:TYPE") (#'MIMS') "application/x-vnd.Be-elfexecutable"; diff --git a/src/apps/terminal/TerminalApp.cpp b/src/apps/terminal/TerminalApp.cpp index 8ef0110cc8..389a7b79c4 100644 --- a/src/apps/terminal/TerminalApp.cpp +++ b/src/apps/terminal/TerminalApp.cpp @@ -1,10 +1,13 @@ -#include #include #include #include -#include "Constants.h" -#include "TerminalApp.h" -#include "TerminalWindow.h" + +#include +#include +#include + +#include +#include BPoint windowPoint(7,26); BPoint cascadeOffset(15,15); @@ -101,12 +104,93 @@ TerminalApp::RefsReceived(BMessage *message) } while (true); } -// TODO: find the arguments for Terminal and implement them all +void +TerminalApp::PrintUsage(const char * execname) { + if (execname == 0) { + execname = "Terminal"; + } + fprintf(stderr,"Usage: %s [OPTIONS] [SHELL]\n",execname); + fprintf(stderr,"Open a terminal window.\n"); + fprintf(stderr,"\n"); + fprintf(stderr," -curbg COLOR use COLOR as the cursor background color\n"); + fprintf(stderr," -curfg COLOR use COLOR as the cursor foreground (text) color\n"); + fprintf(stderr," -bg COLOR use COLOR as the background color\n"); + fprintf(stderr," -fg COLOR use COLOR as the foreground (text) color\n"); + fprintf(stderr," -g, -geom NxM use geometry N columns by M rows\n"); + fprintf(stderr," -h, -help print this help\n"); + fprintf(stderr," -m, -meta pass through the META key to the shell\n"); + fprintf(stderr," -p, -pref FILE use FILE as a Terminal preference file\n"); + fprintf(stderr," -selbg COLOR use COLOR as the selection background color\n"); + fprintf(stderr," -selfg COLOR use COLOR as the selection foreground (text) color\n"); + fprintf(stderr," -t, -title TITLE use TITLE as the window title\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"Report bugs to shatty@myrealbox.com\n"); + fprintf(stderr,"\n"); +} + +struct option curbg_opt = { "curbg", required_argument, 0, 1 } ; +struct option curfg_opt = { "curfg", required_argument, 0, 2 } ; +struct option bg_opt = { "bg", required_argument, 0, 3 } ; +struct option fg_opt = { "fg", required_argument, 0, 4 } ; +struct option geom_opt = { "geom", required_argument, 0, 'g' } ; +struct option help_opt = { "help", no_argument, 0, 'h' } ; +struct option meta_opt = { "meta", no_argument, 0, 'm' } ; +struct option pref_opt = { "pref", required_argument, 0, 'p' } ; +struct option selbg_opt = { "selbg", required_argument, 0, 5 } ; +struct option selfg_opt = { "selfg", required_argument, 0, 6 } ; +struct option title_opt = { "title", required_argument, 0, 't' } ; + +struct option options[] = + { curbg_opt, curfg_opt, bg_opt, fg_opt, + geom_opt, help_opt, meta_opt, pref_opt, + selbg_opt, selfg_opt, title_opt, 0 + }; + +// TODO: implement the arguments for Terminal void TerminalApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd) { - const char * execname = (argc >= 1 ? argv[0] : ""); - cout << execname << ": command line arguments not yet implemented" << endl; + if (argc <= 1) { + OpenTerminal(); + } else if (argv[1][0] != '-') { + argc--; + printf("execvp(%ld,%s ...)\n",argc,argv[1]); + OpenTerminal(); + } else { + const char * execname = (argc >= 1 ? argv[0] : ""); + const char * title = 0; + int indexptr = 0; + int ch; + char * const * optargv = (char * const *)argv; + while ((ch = getopt_long_only(argc, optargv, "g:hmp:t:", options, &indexptr)) != -1) { + switch (ch) { + case 'h': + PrintUsage(execname); + return; + break; + case 't': + title = optarg; + printf("title is %s\n", title); + break; + case ':': + switch (optopt) { + case 't': + printf("-t without title\n"); + break; + default: + printf("-%c missing argument\n", optopt); + } + break; + case '?': + printf("unknown arg %c\n", optopt); + break; + default: + printf("%s\n",argv[optind]); + return; + } + } + OpenTerminal(); + } return; } @@ -114,7 +198,7 @@ void TerminalApp::ReadyToRun() { if (fWindowCount == 0) { - OpenTerminal(); + Quit(); } } diff --git a/src/apps/terminal/TerminalApp.h b/src/apps/terminal/TerminalApp.h index 457e9a3974..a8a115ee68 100644 --- a/src/apps/terminal/TerminalApp.h +++ b/src/apps/terminal/TerminalApp.h @@ -24,6 +24,7 @@ public: void CloseTerminal(); private: + void PrintUsage(const char * execname); int32 fWindowCount; int32 fNext_Terminal_Window;