|
|
|
@@ -33,6 +33,32 @@ bool usage_requested = false;
|
|
|
|
|
bool geometry_requested = false;
|
|
|
|
|
bool color_requested = false;
|
|
|
|
|
|
|
|
|
|
struct standard_args {
|
|
|
|
|
char *name;
|
|
|
|
|
char *longname;
|
|
|
|
|
int priority;
|
|
|
|
|
int nargs;
|
|
|
|
|
const char *prefname;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct standard_args standard_args[] = {
|
|
|
|
|
{ "-h", "--help", 90, 0, NULL },
|
|
|
|
|
{ "-p", "--preference", 80, 1, NULL },
|
|
|
|
|
{ "-t", "--title", 70, 1, NULL },
|
|
|
|
|
{ "-geom", "--geometry", 50, 1, NULL },
|
|
|
|
|
#if 0
|
|
|
|
|
{ "-fg", "--text-fore-color", 40, 1, PREF_TEXT_FORE_COLOR },
|
|
|
|
|
{ "-bg", "--text-back-color", 35, 1, PREF_TEXT_BACK_COLOR },
|
|
|
|
|
{ "-curfg", "--cursor-fore-color", 30, 1, PREF_CURSOR_FORE_COLOR },
|
|
|
|
|
{ "-curbg", "--cursor-back-color", 25, 1, PREF_CURSOR_BACK_COLOR },
|
|
|
|
|
{ "-selfg", "--select-fore-color", 20, 1, PREF_SELECT_FORE_COLOR },
|
|
|
|
|
{ "-selbg", "--select-back-color", 15, 1, PREF_SELECT_BACK_COLOR },
|
|
|
|
|
{ "-imfg", "--im-fore-color", 10, 1, PREF_IM_FORE_COLOR },
|
|
|
|
|
{ "-imbg", "--im-back-color", 5, 1, PREF_IM_BACK_COLOR },
|
|
|
|
|
{ "-imsel", "--im-select-color", 0, 1, PREF_IM_SELECT_COLOR },
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int argmatch(char **, int, char *, char *, int, char **, int *);
|
|
|
|
|
void sort_args(int, char **);
|
|
|
|
|
int text_to_rgb(char *, rgb_color *, char *);
|
|
|
|
@@ -42,20 +68,22 @@ const ulong MSG_ACTIVATE_TERM = 'msat';
|
|
|
|
|
const ulong MSG_TERM_IS_MINIMIZE = 'mtim';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TermApp::TermApp(void)
|
|
|
|
|
TermApp::TermApp()
|
|
|
|
|
: BApplication(TERM_SIGNATURE)
|
|
|
|
|
{
|
|
|
|
|
BList teams;
|
|
|
|
|
|
|
|
|
|
be_roster->GetAppList(TERM_SIGNATURE, &teams);
|
|
|
|
|
fWindowNumber = teams.CountItems();
|
|
|
|
|
|
|
|
|
|
if(fWindowNumber == 0)
|
|
|
|
|
{
|
|
|
|
|
if (fWindowNumber == 0) {
|
|
|
|
|
be_roster->GetAppList(R5_TERM_SIGNATURE, &teams);
|
|
|
|
|
fWindowNumber = teams.CountItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char title[256];
|
|
|
|
|
snprintf(title, sizeof(title), "Terminal %d", fWindowNumber);
|
|
|
|
|
fWindowTitle = title;
|
|
|
|
|
|
|
|
|
|
int i = fWindowNumber / 16;
|
|
|
|
|
int j = fWindowNumber % 16;
|
|
|
|
|
|
|
|
|
@@ -70,14 +98,14 @@ TermApp::TermApp(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TermApp::~TermApp(void)
|
|
|
|
|
TermApp::~TermApp()
|
|
|
|
|
{
|
|
|
|
|
// delete gTermPref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::ReadyToRun(void)
|
|
|
|
|
TermApp::ReadyToRun()
|
|
|
|
|
{
|
|
|
|
|
// Prevent opeing window when option -h is given.
|
|
|
|
|
if(usage_requested)
|
|
|
|
@@ -92,7 +120,6 @@ TermApp::ReadyToRun(void)
|
|
|
|
|
// Get encoding name (setenv TTYPE in spawn_shell functions)
|
|
|
|
|
const etable *p = encoding_table;
|
|
|
|
|
while (p->name) {
|
|
|
|
|
|
|
|
|
|
if (!strcmp(p->name, encoding)) {
|
|
|
|
|
encoding = p->shortname;
|
|
|
|
|
break;
|
|
|
|
@@ -123,10 +150,9 @@ TermApp::ReadyToRun(void)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::Quit(void)
|
|
|
|
|
TermApp::Quit()
|
|
|
|
|
{
|
|
|
|
|
if (!usage_requested){
|
|
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
kill(-sh_pid, SIGHUP);
|
|
|
|
@@ -134,7 +160,6 @@ TermApp::Quit(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete gTermPref;
|
|
|
|
|
|
|
|
|
|
BApplication::Quit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -163,23 +188,19 @@ TermApp::AboutRequested()
|
|
|
|
|
void
|
|
|
|
|
TermApp::MessageReceived(BMessage* msg)
|
|
|
|
|
{
|
|
|
|
|
switch(msg->what)
|
|
|
|
|
{
|
|
|
|
|
switch (msg->what) {
|
|
|
|
|
case MENU_NEW_TREM:
|
|
|
|
|
{
|
|
|
|
|
RunNewTerm();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case MENU_SWITCH_TERM:
|
|
|
|
|
{
|
|
|
|
|
SwitchTerm();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case MSG_ACTIVATE_TERM:
|
|
|
|
|
{
|
|
|
|
|
fTermWindow->TermWinActivate();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case MSG_TERM_IS_MINIMIZE:
|
|
|
|
|
{
|
|
|
|
|
BMessage reply(B_REPLY);
|
|
|
|
@@ -187,46 +208,19 @@ TermApp::MessageReceived(BMessage* msg)
|
|
|
|
|
msg->SendReply(&reply);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
BApplication::MessageReceived(msg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct standard_args
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
char *longname;
|
|
|
|
|
int priority;
|
|
|
|
|
int nargs;
|
|
|
|
|
const char *prefname;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct standard_args standard_args[] =
|
|
|
|
|
{
|
|
|
|
|
{ "-h", "--help", 90, 0, NULL },
|
|
|
|
|
{ "-p", "--preference", 80, 1, NULL },
|
|
|
|
|
{ "-t", "--title", 70, 1, NULL },
|
|
|
|
|
{ "-geom", "--geometry", 50, 1, NULL },
|
|
|
|
|
{ "-fg", "--text-fore-color", 40, 1, PREF_TEXT_FORE_COLOR },
|
|
|
|
|
{ "-bg", "--text-back-color", 35, 1, PREF_TEXT_BACK_COLOR },
|
|
|
|
|
{ "-curfg", "--cursor-fore-color", 30, 1, PREF_CURSOR_FORE_COLOR },
|
|
|
|
|
{ "-curbg", "--cursor-back-color", 25, 1, PREF_CURSOR_BACK_COLOR },
|
|
|
|
|
{ "-selfg", "--select-fore-color", 20, 1, PREF_SELECT_FORE_COLOR },
|
|
|
|
|
{ "-selbg", "--select-back-color", 15, 1, PREF_SELECT_BACK_COLOR },
|
|
|
|
|
{ "-imfg", "--im-fore-color", 10, 1, PREF_IM_FORE_COLOR },
|
|
|
|
|
{ "-imbg", "--im-back-color", 5, 1, PREF_IM_BACK_COLOR },
|
|
|
|
|
{ "-imsel", "--im-select-color", 0, 1, PREF_IM_SELECT_COLOR },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int skip_args = 0;
|
|
|
|
|
char *value = 0;
|
|
|
|
|
rgb_color color;
|
|
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
|
return;
|
|
|
|
@@ -238,7 +232,6 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
|
|
|
|
|
// Print usage
|
|
|
|
|
if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)) {
|
|
|
|
|
|
|
|
|
|
Usage(argv[0]);
|
|
|
|
|
usage_requested = true;
|
|
|
|
|
PostMessage(B_QUIT_REQUESTED);
|
|
|
|
@@ -250,17 +243,15 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
|
|
|
|
|
// Set window title
|
|
|
|
|
if (argmatch(argv ,argc, "-t", "--title", 3, &value, &skip_args))
|
|
|
|
|
strcpy(gWindowName, value);
|
|
|
|
|
fWindowTitle = value;
|
|
|
|
|
|
|
|
|
|
// Set window geometry
|
|
|
|
|
if (argmatch(argv, argc, "-geom", "--geometry", 4, &value, &skip_args)) {
|
|
|
|
|
|
|
|
|
|
int width, height, xpos, ypos;
|
|
|
|
|
|
|
|
|
|
sscanf(value, "%dx%d+%d+%d", &width, &height, &xpos, &ypos);
|
|
|
|
|
if (width < 0 || height < 0 || xpos < 0 || ypos < 0
|
|
|
|
|
|| width >= 256 || height >= 256 || xpos >= 2048 || ypos >= 2048) {
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: invalid geometry format or value.\n", argv[0]);
|
|
|
|
|
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
|
|
|
|
|
usage_requested = true;
|
|
|
|
@@ -273,15 +264,13 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
geometry_requested = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
// Open '/etc/rgb.txt' file
|
|
|
|
|
BFile inFile;
|
|
|
|
|
status_t sts;
|
|
|
|
|
off_t size = 0;
|
|
|
|
|
|
|
|
|
|
sts = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY);
|
|
|
|
|
|
|
|
|
|
if(sts != B_OK) {
|
|
|
|
|
|
|
|
|
|
status_t status = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY);
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
|
fprintf(stderr, "%s: Can't open /etc/rgb.txt file.\n", argv[0]);
|
|
|
|
|
usage_requested = true;
|
|
|
|
|
PostMessage(B_QUIT_REQUESTED);
|
|
|
|
@@ -295,7 +284,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
for (int i = 4; i < 13; i++) {
|
|
|
|
|
if (argmatch(argv, argc, standard_args[i].name, standard_args[i].longname,
|
|
|
|
|
9, &value, &skip_args)) {
|
|
|
|
|
|
|
|
|
|
rgb_color color;
|
|
|
|
|
if (text_to_rgb(value, &color, buffer))
|
|
|
|
|
gTermPref->setRGB(standard_args[i].prefname, color);
|
|
|
|
|
else
|
|
|
|
@@ -304,7 +293,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
skip_args++;
|
|
|
|
|
|
|
|
|
|
if (skip_args < argc) {
|
|
|
|
@@ -346,7 +335,7 @@ void
|
|
|
|
|
TermApp::RefsReceived(BMessage *message)
|
|
|
|
|
{
|
|
|
|
|
// Works Only Launced by Double-Click file, or Drags file to App.
|
|
|
|
|
if(!(IsLaunching()))
|
|
|
|
|
if (!IsLaunching())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
@@ -372,31 +361,33 @@ TermApp::RefsReceived(BMessage *message)
|
|
|
|
|
|
|
|
|
|
// if App opened by Shell Script
|
|
|
|
|
if (!strcmp(mimetype, "text/x-haiku-shscript")){
|
|
|
|
|
|
|
|
|
|
// Not implemented.
|
|
|
|
|
// beep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::MakeTermWindow(BRect &frame)
|
|
|
|
|
{
|
|
|
|
|
fTermWindow = new TermWindow(frame, fWindowNumber);
|
|
|
|
|
fTermWindow = new TermWindow(frame, fWindowTitle.String());
|
|
|
|
|
fTermWindow->Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::RunNewTerm(void)
|
|
|
|
|
TermApp::RunNewTerm()
|
|
|
|
|
{
|
|
|
|
|
app_info info;
|
|
|
|
|
be_app->GetAppInfo(&info);
|
|
|
|
|
|
|
|
|
|
// try launching two different ways to work around possible problems
|
|
|
|
|
if(be_roster->Launch(&(info.ref))!=B_OK)
|
|
|
|
|
if (be_roster->Launch(&info.ref)!=B_OK)
|
|
|
|
|
be_roster->Launch(TERM_SIGNATURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::ActivateTermWindow(team_id id)
|
|
|
|
|
{
|
|
|
|
@@ -408,6 +399,7 @@ TermApp::ActivateTermWindow(team_id id)
|
|
|
|
|
app.SendMessage(MSG_ACTIVATE_TERM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TermApp::SwitchTerm()
|
|
|
|
|
{
|
|
|
|
@@ -436,6 +428,7 @@ TermApp::SwitchTerm()
|
|
|
|
|
ActivateTermWindow(reinterpret_cast<team_id>(teams.ItemAt(i)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TermApp::IsMinimize(team_id id)
|
|
|
|
|
{
|
|
|
|
@@ -451,7 +444,6 @@ TermApp::IsMinimize(team_id id)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
reply.FindBool("result", &hidden);
|
|
|
|
|
|
|
|
|
|
return hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -494,6 +486,7 @@ TermApp::Usage(char *name)
|
|
|
|
|
PR(" -t, --title set window title\n");
|
|
|
|
|
PR(" -geom, --geometry set window geometry\n");
|
|
|
|
|
PR(" An example of geometry is \"80x25+100+100\"\n");
|
|
|
|
|
#if 0
|
|
|
|
|
PR(" -fg, --text-fore-color set window foreground color\n");
|
|
|
|
|
PR(" -bg, --text-back-color set window background color\n");
|
|
|
|
|
PR(" -curfg, --cursor-fore-color set cursor foreground color\n");
|
|
|
|
@@ -501,6 +494,7 @@ TermApp::Usage(char *name)
|
|
|
|
|
PR(" -selfg, --select-fore-color set selection area foreground color\n");
|
|
|
|
|
PR(" -selbg, --select-back-color set selection area background color\n");
|
|
|
|
|
PR(" Examples of color are \"#FF00FF\" and \"purple\"\n");
|
|
|
|
|
#endif
|
|
|
|
|
PR("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -508,7 +502,6 @@ int
|
|
|
|
|
text_to_rgb(char *name, rgb_color *color, char *buffer)
|
|
|
|
|
{
|
|
|
|
|
if (name[0] != '#') {
|
|
|
|
|
|
|
|
|
|
// Convert from /etc/rgb.txt.
|
|
|
|
|
BString inStr(buffer);
|
|
|
|
|
int32 point, offset = 0;
|
|
|
|
@@ -522,7 +515,6 @@ text_to_rgb(char *name, rgb_color *color, char *buffer)
|
|
|
|
|
} while(*(buffer + point -1) != '\t');
|
|
|
|
|
|
|
|
|
|
char *p = buffer + point;
|
|
|
|
|
|
|
|
|
|
while (*p != '\n')
|
|
|
|
|
p--;
|
|
|
|
|
p++;
|
|
|
|
@@ -530,17 +522,14 @@ text_to_rgb(char *name, rgb_color *color, char *buffer)
|
|
|
|
|
if (sscanf(p, "%d %d %d", (int *)&color->red, (int *)&color->green,
|
|
|
|
|
(int *)&color->blue) == EOF)
|
|
|
|
|
return false;
|
|
|
|
|
color->alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if(name[0] == '#') {
|
|
|
|
|
|
|
|
|
|
color->alpha = 0;
|
|
|
|
|
} else if (name[0] == '#') {
|
|
|
|
|
// Convert from #RRGGBB format
|
|
|
|
|
sscanf(name, "#%2x%2x%2x", (int *)&color->red, (int *)&color->green,
|
|
|
|
|
(int *)&color->blue);
|
|
|
|
|
color->alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@@ -564,14 +553,11 @@ argmatch(char **argv, int argc, char *sstr, char *lstr,
|
|
|
|
|
if (arg == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if(strcmp(arg, sstr) == 0)
|
|
|
|
|
{
|
|
|
|
|
if(valptr != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(arg, sstr) == 0) {
|
|
|
|
|
if(valptr != NULL) {
|
|
|
|
|
*valptr = argv[*skipptr+2];
|
|
|
|
|
*skipptr += 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
*skipptr += 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
@@ -709,17 +695,14 @@ sort_args(int argc, char **argv)
|
|
|
|
|
|
|
|
|
|
// Copy the arguments, in order of decreasing priority, to NEW
|
|
|
|
|
newargv[0] = argv[0];
|
|
|
|
|
while(incoming_used < argc)
|
|
|
|
|
{
|
|
|
|
|
while (incoming_used < argc) {
|
|
|
|
|
int best = -1;
|
|
|
|
|
int best_priority = -9999;
|
|
|
|
|
|
|
|
|
|
// Find the highest priority remaining option.
|
|
|
|
|
// If several have equal priority, take the first of them.
|
|
|
|
|
for(from = 1; from < argc; from++)
|
|
|
|
|
{
|
|
|
|
|
if(argv[from] != 0 && priority[from] > best_priority)
|
|
|
|
|
{
|
|
|
|
|
for (from = 1; from < argc; from++) {
|
|
|
|
|
if (argv[from] != 0 && priority[from] > best_priority) {
|
|
|
|
|
best_priority = priority[from];
|
|
|
|
|
best = from;
|
|
|
|
|
}
|
|
|
|
@@ -734,8 +717,7 @@ sort_args(int argc, char **argv)
|
|
|
|
|
|
|
|
|
|
// Copy the highest priority remaining option, with its args, to NEW.
|
|
|
|
|
// Unless it is a duplicate of the previous one
|
|
|
|
|
if(!(options[best] == 0 && ! strcmp(newargv[to - 1], argv[best])))
|
|
|
|
|
{
|
|
|
|
|
if (!(options[best] == 0 && ! strcmp(newargv[to - 1], argv[best]))) {
|
|
|
|
|
newargv[to++] = argv[best];
|
|
|
|
|
for(i = 0; i < options[best]; i++)
|
|
|
|
|
newargv[to++] = argv[best + i + 1];
|
|
|
|
|