* Removed the shell process ID from ActiveProcessInfo and moved it to new class
ShellInfo, which also contains a flag whether the shell is the default shell. * If the Terminal has been started with a custom shell, also replace "%p" in the title by its name, when active. * Also show the on-close alert for the custom shell. Fixes #6844. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39573 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
65b57677b5
commit
ca598670fb
@ -10,7 +10,6 @@
|
||||
ActiveProcessInfo::ActiveProcessInfo()
|
||||
:
|
||||
fID(-1),
|
||||
fShellID(-1),
|
||||
fName(),
|
||||
fCurrentDirectory()
|
||||
{
|
||||
@ -18,11 +17,10 @@ ActiveProcessInfo::ActiveProcessInfo()
|
||||
|
||||
|
||||
void
|
||||
ActiveProcessInfo::SetTo(pid_t id, pid_t shellID, const BString& name,
|
||||
ActiveProcessInfo::SetTo(pid_t id, const BString& name,
|
||||
const BString& currentDirectory)
|
||||
{
|
||||
fID = id;
|
||||
fShellID = shellID;
|
||||
fName = name;
|
||||
fCurrentDirectory = currentDirectory;
|
||||
}
|
||||
@ -32,7 +30,6 @@ void
|
||||
ActiveProcessInfo::Unset()
|
||||
{
|
||||
fID = -1;
|
||||
fShellID = -1;
|
||||
fName = BString();
|
||||
fCurrentDirectory = BString();
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ class ActiveProcessInfo {
|
||||
public:
|
||||
ActiveProcessInfo();
|
||||
|
||||
void SetTo(pid_t id, pid_t shellID,
|
||||
const BString& name,
|
||||
void SetTo(pid_t id, const BString& name,
|
||||
const BString& currentDirectory);
|
||||
void Unset();
|
||||
|
||||
bool IsValid() const { return fID >= 0; }
|
||||
|
||||
pid_t ID() const { return fID; }
|
||||
pid_t ShellProcessID() const { return fShellID; }
|
||||
|
||||
const BString& Name() const { return fName; }
|
||||
const BString& CurrentDirectory() const
|
||||
@ -30,7 +28,6 @@ public:
|
||||
|
||||
private:
|
||||
pid_t fID;
|
||||
pid_t fShellID;
|
||||
BString fName;
|
||||
BString fCurrentDirectory;
|
||||
};
|
||||
|
@ -22,6 +22,7 @@ Application Terminal :
|
||||
PrefWindow.cpp
|
||||
SetTitleDialog.cpp
|
||||
Shell.cpp
|
||||
ShellInfo.cpp
|
||||
ShellParameters.cpp
|
||||
SmartTabView.cpp
|
||||
TermApp.cpp
|
||||
|
@ -126,7 +126,6 @@ typedef struct
|
||||
Shell::Shell()
|
||||
:
|
||||
fFd(-1),
|
||||
fProcessID(-1),
|
||||
fTermParse(NULL),
|
||||
fAttached(false)
|
||||
{
|
||||
@ -167,8 +166,8 @@ Shell::Close()
|
||||
|
||||
if (fFd >= 0) {
|
||||
close(fFd);
|
||||
kill(-fProcessID, SIGHUP);
|
||||
fProcessID = -1;
|
||||
kill(-fShellInfo.ProcessID(), SIGHUP);
|
||||
fShellInfo.SetProcessID(-1);
|
||||
int status;
|
||||
wait(&status);
|
||||
fFd = -1;
|
||||
@ -244,7 +243,7 @@ bool
|
||||
Shell::HasActiveProcesses() const
|
||||
{
|
||||
pid_t running = tcgetpgrp(fFd);
|
||||
if (running == fProcessID || running == -1)
|
||||
if (running == fShellInfo.ProcessID() || running == -1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -284,7 +283,7 @@ Shell::GetActiveProcessInfo(ActiveProcessInfo& _info) const
|
||||
return false;
|
||||
|
||||
// set the result
|
||||
_info.SetTo(process, fProcessID, name, cwdPath.Path());
|
||||
_info.SetTo(process, name, cwdPath.Path());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -391,6 +390,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
||||
struct passwd passwdStruct;
|
||||
struct passwd *passwdResult;
|
||||
char stringBuffer[256];
|
||||
|
||||
if (argv == NULL || argc == 0) {
|
||||
if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer,
|
||||
sizeof(stringBuffer), &passwdResult)) {
|
||||
@ -399,7 +399,10 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
||||
|
||||
argv = defaultArgs;
|
||||
argc = 2;
|
||||
}
|
||||
|
||||
fShellInfo.SetDefaultShell(true);
|
||||
} else
|
||||
fShellInfo.SetDefaultShell(false);
|
||||
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
|
||||
@ -427,14 +430,15 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
||||
thread_id terminalThread = find_thread(NULL);
|
||||
|
||||
/* Fork a child process. */
|
||||
if ((fProcessID = fork()) < 0) {
|
||||
fShellInfo.SetProcessID(fork());
|
||||
if (fShellInfo.ProcessID() < 0) {
|
||||
close(master);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
handshake_t handshake;
|
||||
|
||||
if (fProcessID == 0) {
|
||||
if (fShellInfo.ProcessID() == 0) {
|
||||
// Now in child process.
|
||||
|
||||
// close the PTY master side
|
||||
@ -595,7 +599,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
||||
handshake.row = row;
|
||||
handshake.col = col;
|
||||
handshake.status = PTY_WS;
|
||||
send_handshake_message(fProcessID, handshake);
|
||||
send_handshake_message(fShellInfo.ProcessID(), handshake);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define _SHELL_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include "ShellInfo.h"
|
||||
|
||||
|
||||
class ActiveProcessInfo;
|
||||
@ -44,7 +44,10 @@ public:
|
||||
status_t SetAttr(const struct termios& attr);
|
||||
|
||||
int FD() const;
|
||||
pid_t ProcessID() const { return fProcessID; }
|
||||
pid_t ProcessID() const
|
||||
{ return fShellInfo.ProcessID(); }
|
||||
const ShellInfo& Info() const
|
||||
{ return fShellInfo; }
|
||||
|
||||
bool HasActiveProcesses() const;
|
||||
bool GetActiveProcessInfo(
|
||||
@ -58,6 +61,7 @@ private:
|
||||
const ShellParameters& parameters);
|
||||
|
||||
private:
|
||||
ShellInfo fShellInfo;
|
||||
int fFd;
|
||||
pid_t fProcessID;
|
||||
TermParse* fTermParse;
|
||||
|
15
src/apps/terminal/ShellInfo.cpp
Normal file
15
src/apps/terminal/ShellInfo.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "ShellInfo.h"
|
||||
|
||||
|
||||
ShellInfo::ShellInfo()
|
||||
:
|
||||
fProcessID(-1),
|
||||
fIsDefaultShell(true)
|
||||
{
|
||||
}
|
32
src/apps/terminal/ShellInfo.h
Normal file
32
src/apps/terminal/ShellInfo.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef SHELL_INFO_H
|
||||
#define SHELL_INFO_H
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
class ShellInfo {
|
||||
public:
|
||||
ShellInfo();
|
||||
|
||||
pid_t ProcessID() const
|
||||
{ return fProcessID; }
|
||||
void SetProcessID(pid_t processID)
|
||||
{ fProcessID = processID; }
|
||||
|
||||
bool IsDefaultShell() const
|
||||
{ return fIsDefaultShell; }
|
||||
void SetDefaultShell(bool isDefault)
|
||||
{ fIsDefaultShell = isDefault; }
|
||||
|
||||
private:
|
||||
pid_t fProcessID;
|
||||
bool fIsDefaultShell;
|
||||
};
|
||||
|
||||
|
||||
#endif // SHELL_INFO_H
|
@ -661,6 +661,19 @@ TermView::GetActiveProcessInfo(ActiveProcessInfo& _info) const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TermView::GetShellInfo(ShellInfo& _info) const
|
||||
{
|
||||
if (fShell == NULL) {
|
||||
_info = ShellInfo();
|
||||
return false;
|
||||
}
|
||||
|
||||
_info = fShell->Info();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* static */
|
||||
BArchivable *
|
||||
TermView::Instantiate(BMessage* data)
|
||||
|
@ -31,6 +31,7 @@ class BStringView;
|
||||
class BasicTerminalBuffer;
|
||||
class InlineInput;
|
||||
class ResizeWindow;
|
||||
class ShellInfo;
|
||||
class ShellParameters;
|
||||
class TermBuffer;
|
||||
class TerminalBuffer;
|
||||
@ -58,6 +59,7 @@ public:
|
||||
bool IsShellBusy() const;
|
||||
bool GetActiveProcessInfo(
|
||||
ActiveProcessInfo& _info) const;
|
||||
bool GetShellInfo(ShellInfo& _info) const;
|
||||
|
||||
const char* TerminalName() const;
|
||||
|
||||
|
@ -302,17 +302,25 @@ TermWindow::_CanClose(int32 index)
|
||||
// all names, separated by "\n\t"
|
||||
|
||||
if (index != -1) {
|
||||
ShellInfo shellInfo;
|
||||
ActiveProcessInfo info;
|
||||
if (_TermViewAt(index)->GetActiveProcessInfo(info)
|
||||
&& info.ID() != info.ShellProcessID()) {
|
||||
TermView* termView = _TermViewAt(index);
|
||||
if (termView->GetShellInfo(shellInfo)
|
||||
&& termView->GetActiveProcessInfo(info)
|
||||
&& (info.ID() != shellInfo.ProcessID()
|
||||
|| !shellInfo.IsDefaultShell())) {
|
||||
busyProcessCount++;
|
||||
busyProcessNames = info.Name();
|
||||
}
|
||||
} else {
|
||||
for (int32 i = 0; i < fSessions.CountItems(); i++) {
|
||||
ShellInfo shellInfo;
|
||||
ActiveProcessInfo info;
|
||||
if (_TermViewAt(i)->GetActiveProcessInfo(info)
|
||||
&& info.ID() != info.ShellProcessID()) {
|
||||
TermView* termView = _TermViewAt(i);
|
||||
if (termView->GetShellInfo(shellInfo)
|
||||
&& termView->GetActiveProcessInfo(info)
|
||||
&& (info.ID() != shellInfo.ProcessID()
|
||||
|| !shellInfo.IsDefaultShell())) {
|
||||
if (++busyProcessCount > 1)
|
||||
busyProcessNames << "\n\t";
|
||||
busyProcessNames << info.Name();
|
||||
@ -1576,15 +1584,20 @@ TermWindow::_UpdateSessionTitle(int32 index)
|
||||
if (session == NULL)
|
||||
return;
|
||||
|
||||
// get the active process info
|
||||
// get the shell and active process infos
|
||||
ShellInfo shellInfo;
|
||||
ActiveProcessInfo activeProcessInfo;
|
||||
if (!_TermViewAt(index)->GetActiveProcessInfo(activeProcessInfo))
|
||||
TermView* termView = _TermViewAt(index);
|
||||
if (!termView->GetShellInfo(shellInfo)
|
||||
|| !termView->GetActiveProcessInfo(activeProcessInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// evaluate the session title pattern
|
||||
BString sessionTitlePattern = session->title.patternUserDefined
|
||||
? session->title.pattern : fSessionTitlePattern;
|
||||
TabTitlePlaceholderMapper tabMapper(activeProcessInfo, session->index);
|
||||
TabTitlePlaceholderMapper tabMapper(shellInfo, activeProcessInfo,
|
||||
session->index);
|
||||
const BString& sessionTitle = PatternEvaluator::Evaluate(
|
||||
sessionTitlePattern, tabMapper);
|
||||
|
||||
@ -1602,7 +1615,7 @@ TermWindow::_UpdateSessionTitle(int32 index)
|
||||
return;
|
||||
|
||||
// evaluate the window title pattern
|
||||
WindowTitlePlaceholderMapper windowMapper(activeProcessInfo,
|
||||
WindowTitlePlaceholderMapper windowMapper(shellInfo, activeProcessInfo,
|
||||
fTerminalRoster.ID() + 1, sessionTitle);
|
||||
const BString& windowTitle = PatternEvaluator::Evaluate(fTitle.pattern,
|
||||
windowMapper);
|
||||
|
@ -10,9 +10,10 @@
|
||||
// #pragma mark - TitlePlaceholderMapper
|
||||
|
||||
|
||||
TitlePlaceholderMapper::TitlePlaceholderMapper(
|
||||
TitlePlaceholderMapper::TitlePlaceholderMapper(const ShellInfo& shellInfo,
|
||||
const ActiveProcessInfo& processInfo)
|
||||
:
|
||||
fShellInfo(shellInfo),
|
||||
fProcessInfo(processInfo)
|
||||
{
|
||||
}
|
||||
@ -46,10 +47,12 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
|
||||
}
|
||||
|
||||
case 'p':
|
||||
// process name -- use "--", if the shell is active
|
||||
if (fProcessInfo.ID() == fProcessInfo.ShellProcessID())
|
||||
// process name -- use "--", if the shell is active and it is the
|
||||
// default shell
|
||||
if (fProcessInfo.ID() == fShellInfo.ProcessID()
|
||||
&& fShellInfo.IsDefaultShell()) {
|
||||
_string = "--";
|
||||
else
|
||||
} else
|
||||
_string = fProcessInfo.Name();
|
||||
return true;
|
||||
}
|
||||
@ -62,10 +65,10 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
|
||||
|
||||
|
||||
WindowTitlePlaceholderMapper::WindowTitlePlaceholderMapper(
|
||||
const ActiveProcessInfo& processInfo, int32 windowIndex,
|
||||
const BString& tabTitle)
|
||||
const ShellInfo& shellInfo, const ActiveProcessInfo& processInfo,
|
||||
int32 windowIndex, const BString& tabTitle)
|
||||
:
|
||||
TitlePlaceholderMapper(processInfo),
|
||||
TitlePlaceholderMapper(shellInfo, processInfo),
|
||||
fWindowIndex(windowIndex),
|
||||
fTabTitle(tabTitle)
|
||||
{
|
||||
@ -97,10 +100,10 @@ WindowTitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
|
||||
// #pragma mark - TabTitlePlaceholderMapper
|
||||
|
||||
|
||||
TabTitlePlaceholderMapper::TabTitlePlaceholderMapper(
|
||||
TabTitlePlaceholderMapper::TabTitlePlaceholderMapper(const ShellInfo& shellInfo,
|
||||
const ActiveProcessInfo& processInfo, int32 tabIndex)
|
||||
:
|
||||
TitlePlaceholderMapper(processInfo),
|
||||
TitlePlaceholderMapper(shellInfo, processInfo),
|
||||
fTabIndex(tabIndex)
|
||||
{
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "ActiveProcessInfo.h"
|
||||
#include "PatternEvaluator.h"
|
||||
#include "ShellInfo.h"
|
||||
|
||||
|
||||
/*! Class mapping the placeholders common for window and tab titles.
|
||||
@ -15,6 +16,7 @@
|
||||
class TitlePlaceholderMapper : public PatternEvaluator::PlaceholderMapper {
|
||||
public:
|
||||
TitlePlaceholderMapper(
|
||||
const ShellInfo& shellInfo,
|
||||
const ActiveProcessInfo& processInfo);
|
||||
|
||||
virtual bool MapPlaceholder(char placeholder,
|
||||
@ -22,6 +24,7 @@ public:
|
||||
BString& _string);
|
||||
|
||||
private:
|
||||
ShellInfo fShellInfo;
|
||||
ActiveProcessInfo fProcessInfo;
|
||||
};
|
||||
|
||||
@ -29,6 +32,7 @@ private:
|
||||
class WindowTitlePlaceholderMapper : public TitlePlaceholderMapper {
|
||||
public:
|
||||
WindowTitlePlaceholderMapper(
|
||||
const ShellInfo& shellInfo,
|
||||
const ActiveProcessInfo& processInfo,
|
||||
int32 windowIndex, const BString& tabTitle);
|
||||
|
||||
@ -45,6 +49,7 @@ private:
|
||||
class TabTitlePlaceholderMapper : public TitlePlaceholderMapper {
|
||||
public:
|
||||
TabTitlePlaceholderMapper(
|
||||
const ShellInfo& shellInfo,
|
||||
const ActiveProcessInfo& processInfo,
|
||||
int32 tabIndex);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user