* Added new class ShellParameters that bundles all parameters passed to the
shell. * Also added a parameter for the current working directory and. If supplied, it is applied in Shell::_Spawn(). * Pass the current working directory of the active tab when opening a new tab. Implements part of #6712. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39457 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,6 +20,7 @@ Application Terminal :
|
|||||||
PrefHandler.cpp
|
PrefHandler.cpp
|
||||||
PrefWindow.cpp
|
PrefWindow.cpp
|
||||||
Shell.cpp
|
Shell.cpp
|
||||||
|
ShellParameters.cpp
|
||||||
SmartTabView.cpp
|
SmartTabView.cpp
|
||||||
TermApp.cpp
|
TermApp.cpp
|
||||||
TerminalBuffer.cpp
|
TerminalBuffer.cpp
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <extended_system_info_defs.h>
|
#include <extended_system_info_defs.h>
|
||||||
|
|
||||||
#include "ActiveProcessInfo.h"
|
#include "ActiveProcessInfo.h"
|
||||||
|
#include "ShellParameters.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
#include "TermParse.h"
|
#include "TermParse.h"
|
||||||
#include "TerminalBuffer.h"
|
#include "TerminalBuffer.h"
|
||||||
@@ -139,12 +140,12 @@ Shell::~Shell()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Shell::Open(int row, int col, const char *encoding, int argc, const char **argv)
|
Shell::Open(int row, int col, const ShellParameters& parameters)
|
||||||
{
|
{
|
||||||
if (fFd >= 0)
|
if (fFd >= 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
status_t status = _Spawn(row, col, encoding, argc, argv);
|
status_t status = _Spawn(row, col, parameters);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -382,8 +383,10 @@ initialize_termios(struct termios &tio)
|
|||||||
#define B_TRANSLATE_CONTEXT "Terminal Shell"
|
#define B_TRANSLATE_CONTEXT "Terminal Shell"
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **argv)
|
Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
||||||
{
|
{
|
||||||
|
const char** argv = (const char**)parameters.Arguments();
|
||||||
|
int argc = parameters.ArgumentCount();
|
||||||
const char* defaultArgs[3] = {kDefaultShell, "-l", NULL};
|
const char* defaultArgs[3] = {kDefaultShell, "-l", NULL};
|
||||||
struct passwd passwdStruct;
|
struct passwd passwdStruct;
|
||||||
struct passwd *passwdResult;
|
struct passwd *passwdResult;
|
||||||
@@ -533,7 +536,11 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg
|
|||||||
*/
|
*/
|
||||||
setenv("TERM", "xterm", true);
|
setenv("TERM", "xterm", true);
|
||||||
setenv("TTY", ttyName, true);
|
setenv("TTY", ttyName, true);
|
||||||
setenv("TTYPE", encoding, true);
|
setenv("TTYPE", parameters.Encoding(), true);
|
||||||
|
|
||||||
|
// set the current working directory, if one is given
|
||||||
|
if (parameters.CurrentDirectory().Length() > 0)
|
||||||
|
chdir(parameters.CurrentDirectory().String());
|
||||||
|
|
||||||
execve(argv[0], (char * const *)argv, environ);
|
execve(argv[0], (char * const *)argv, environ);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class ActiveProcessInfo;
|
class ActiveProcessInfo;
|
||||||
|
class ShellParameters;
|
||||||
// TODO: Maybe merge TermParse and Shell classes ?
|
// TODO: Maybe merge TermParse and Shell classes ?
|
||||||
class TerminalBuffer;
|
class TerminalBuffer;
|
||||||
class TermParse;
|
class TermParse;
|
||||||
@@ -28,8 +29,8 @@ public:
|
|||||||
Shell();
|
Shell();
|
||||||
virtual ~Shell();
|
virtual ~Shell();
|
||||||
|
|
||||||
status_t Open(int row, int col, const char* encoding,
|
status_t Open(int row, int col,
|
||||||
int argc, const char** argv);
|
const ShellParameters& parameters);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
const char* TTYName() const;
|
const char* TTYName() const;
|
||||||
@@ -53,8 +54,8 @@ public:
|
|||||||
virtual void DetachBuffer();
|
virtual void DetachBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _Spawn(int row, int col, const char* encoding,
|
status_t _Spawn(int row, int col,
|
||||||
int argc, const char** argv);
|
const ShellParameters& parameters);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fFd;
|
int fFd;
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ShellParameters.h"
|
||||||
|
|
||||||
|
|
||||||
|
ShellParameters::ShellParameters(int argc, const char* const* argv,
|
||||||
|
const BString& currentDirectory)
|
||||||
|
:
|
||||||
|
fArguments(argv),
|
||||||
|
fArgumentCount(argc),
|
||||||
|
fCurrentDirectory(currentDirectory),
|
||||||
|
fEncoding("UTF8")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShellParameters::SetArguments(int argc, const char* const* argv)
|
||||||
|
{
|
||||||
|
fArguments = argv;
|
||||||
|
fArgumentCount = argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShellParameters::SetCurrentDirectory(const BString& currentDirectory)
|
||||||
|
{
|
||||||
|
fCurrentDirectory = currentDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShellParameters::SetEncoding(const BString& encoding)
|
||||||
|
{
|
||||||
|
fEncoding = encoding;
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef SHELL_PARAMETERS_H
|
||||||
|
#define SHELL_PARAMETERS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
class ShellParameters {
|
||||||
|
public:
|
||||||
|
ShellParameters(int argc,
|
||||||
|
const char* const* argv,
|
||||||
|
const BString& currentDirectory
|
||||||
|
= BString());
|
||||||
|
|
||||||
|
void SetArguments(int argc, const char* const* argv);
|
||||||
|
const char* const* Arguments() const
|
||||||
|
{ return fArguments; }
|
||||||
|
int ArgumentCount() const
|
||||||
|
{ return fArgumentCount; }
|
||||||
|
|
||||||
|
void SetCurrentDirectory(
|
||||||
|
const BString& currentDirectory);
|
||||||
|
const BString& CurrentDirectory() const
|
||||||
|
{ return fCurrentDirectory; }
|
||||||
|
|
||||||
|
void SetEncoding(const BString& encoding);
|
||||||
|
const BString& Encoding() const
|
||||||
|
{ return fEncoding; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* const* fArguments;
|
||||||
|
int fArgumentCount;
|
||||||
|
BString fCurrentDirectory;
|
||||||
|
BString fEncoding;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SHELL_PARAMETERS_H
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
#include "InlineInput.h"
|
#include "InlineInput.h"
|
||||||
#include "Shell.h"
|
#include "Shell.h"
|
||||||
|
#include "ShellParameters.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
#include "TerminalBuffer.h"
|
#include "TerminalBuffer.h"
|
||||||
#include "TerminalCharClassifier.h"
|
#include "TerminalCharClassifier.h"
|
||||||
@@ -422,7 +423,8 @@ private:
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize)
|
TermView::TermView(BRect frame, const ShellParameters& shellParameters,
|
||||||
|
int32 historySize)
|
||||||
: BView(frame, "termview", B_FOLLOW_ALL,
|
: BView(frame, "termview", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
|
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fColumns(COLUMNS_DEFAULT),
|
fColumns(COLUMNS_DEFAULT),
|
||||||
@@ -435,15 +437,15 @@ TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize
|
|||||||
fReportButtonMouseEvent(false),
|
fReportButtonMouseEvent(false),
|
||||||
fReportAnyMouseEvent(false)
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
status_t status = _InitObject(argc, argv);
|
status_t status = _InitObject(shellParameters);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
throw status;
|
throw status;
|
||||||
SetTermSize(frame);
|
SetTermSize(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
TermView::TermView(int rows, int columns,
|
||||||
int32 historySize)
|
const ShellParameters& shellParameters, int32 historySize)
|
||||||
: BView(BRect(0, 0, 0, 0), "termview", B_FOLLOW_ALL,
|
: BView(BRect(0, 0, 0, 0), "termview", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
|
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fColumns(columns),
|
fColumns(columns),
|
||||||
@@ -456,7 +458,7 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
|||||||
fReportButtonMouseEvent(false),
|
fReportButtonMouseEvent(false),
|
||||||
fReportAnyMouseEvent(false)
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
status_t status = _InitObject(argc, argv);
|
status_t status = _InitObject(shellParameters);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
throw status;
|
throw status;
|
||||||
|
|
||||||
@@ -507,7 +509,7 @@ TermView::TermView(BMessage* archive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Retrieve colors, history size, etc. from archive
|
// TODO: Retrieve colors, history size, etc. from archive
|
||||||
status_t status = _InitObject(argc, argv);
|
status_t status = _InitObject(ShellParameters(argc, argv));
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
throw status;
|
throw status;
|
||||||
|
|
||||||
@@ -524,7 +526,7 @@ TermView::TermView(BMessage* archive)
|
|||||||
already be initialized; they are not touched by this method.
|
already be initialized; they are not touched by this method.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
TermView::_InitObject(int32 argc, const char** argv)
|
TermView::_InitObject(const ShellParameters& shellParameters)
|
||||||
{
|
{
|
||||||
SetFlags(Flags() | B_WILL_DRAW | B_FRAME_EVENTS
|
SetFlags(Flags() | B_WILL_DRAW | B_FRAME_EVENTS
|
||||||
| B_FULL_UPDATE_ON_RESIZE/* | B_INPUT_METHOD_AWARE*/);
|
| B_FULL_UPDATE_ON_RESIZE/* | B_INPUT_METHOD_AWARE*/);
|
||||||
@@ -596,8 +598,11 @@ TermView::_InitObject(int32 argc, const char** argv)
|
|||||||
|
|
||||||
SetTermFont(be_fixed_font);
|
SetTermFont(be_fixed_font);
|
||||||
|
|
||||||
error = fShell->Open(fRows, fColumns,
|
// set the shell parameters' encoding
|
||||||
EncodingAsShortString(fEncoding), argc, argv);
|
ShellParameters modifiedShellParameters(shellParameters);
|
||||||
|
modifiedShellParameters.SetEncoding(EncodingAsShortString(fEncoding));
|
||||||
|
|
||||||
|
error = fShell->Open(fRows, fColumns, modifiedShellParameters);
|
||||||
|
|
||||||
if (error < B_OK)
|
if (error < B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
@@ -29,16 +29,19 @@ class BStringView;
|
|||||||
class BasicTerminalBuffer;
|
class BasicTerminalBuffer;
|
||||||
class InlineInput;
|
class InlineInput;
|
||||||
class ResizeWindow;
|
class ResizeWindow;
|
||||||
|
class ShellParameters;
|
||||||
class TermBuffer;
|
class TermBuffer;
|
||||||
class TerminalBuffer;
|
class TerminalBuffer;
|
||||||
class Shell;
|
class Shell;
|
||||||
|
|
||||||
class TermView : public BView {
|
class TermView : public BView {
|
||||||
public:
|
public:
|
||||||
TermView(BRect frame, int32 argc, const char** argv,
|
TermView(BRect frame,
|
||||||
|
const ShellParameters& shellParameters,
|
||||||
|
int32 historySize);
|
||||||
|
TermView(int rows, int columns,
|
||||||
|
const ShellParameters& shellParameters,
|
||||||
int32 historySize);
|
int32 historySize);
|
||||||
TermView(int rows, int columns, int32 argc,
|
|
||||||
const char** argv, int32 historySize);
|
|
||||||
TermView(BMessage* archive);
|
TermView(BMessage* archive);
|
||||||
~TermView();
|
~TermView();
|
||||||
|
|
||||||
@@ -133,7 +136,7 @@ private:
|
|||||||
inline void _InvalidateTextRect(int32 x1, int32 y1, int32 x2,
|
inline void _InvalidateTextRect(int32 x1, int32 y1, int32 x2,
|
||||||
int32 y2);
|
int32 y2);
|
||||||
|
|
||||||
status_t _InitObject(int32 argc, const char** argv);
|
status_t _InitObject(const ShellParameters& shellParameters);
|
||||||
|
|
||||||
status_t _AttachShell(Shell* shell);
|
status_t _AttachShell(Shell* shell);
|
||||||
void _DetachShell();
|
void _DetachShell();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include "ActiveProcessInfo.h"
|
||||||
#include "Arguments.h"
|
#include "Arguments.h"
|
||||||
#include "AppearPrefView.h"
|
#include "AppearPrefView.h"
|
||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "PrefWindow.h"
|
#include "PrefWindow.h"
|
||||||
#include "PrefHandler.h"
|
#include "PrefHandler.h"
|
||||||
|
#include "ShellParameters.h"
|
||||||
#include "SmartTabView.h"
|
#include "SmartTabView.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
#include "TermScrollView.h"
|
#include "TermScrollView.h"
|
||||||
@@ -61,7 +63,8 @@ const static uint32 kSetActiveTab = 'STab';
|
|||||||
|
|
||||||
class CustomTermView : public TermView {
|
class CustomTermView : public TermView {
|
||||||
public:
|
public:
|
||||||
CustomTermView(int32 rows, int32 columns, int32 argc, const char **argv, int32 historySize = 1000);
|
CustomTermView(int32 rows, int32 columns,
|
||||||
|
const ShellParameters& shellParameters, int32 historySize = 1000);
|
||||||
virtual void NotifyQuit(int32 reason);
|
virtual void NotifyQuit(int32 reason);
|
||||||
virtual void SetTitle(const char *title);
|
virtual void SetTitle(const char *title);
|
||||||
};
|
};
|
||||||
@@ -690,7 +693,12 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
if (fTabView->CountTabs() < kMaxTabs) {
|
if (fTabView->CountTabs() < kMaxTabs) {
|
||||||
if (fFullScreen)
|
if (fFullScreen)
|
||||||
_ActiveTermView()->ScrollBar()->Show();
|
_ActiveTermView()->ScrollBar()->Show();
|
||||||
_AddTab(NULL);
|
|
||||||
|
ActiveProcessInfo info;
|
||||||
|
if (_ActiveTermView()->GetActiveProcessInfo(info))
|
||||||
|
_AddTab(NULL, info.CurrentDirectory());
|
||||||
|
else
|
||||||
|
_AddTab(NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -828,22 +836,19 @@ TermWindow::_DoPrint()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::_AddTab(Arguments* args)
|
TermWindow::_AddTab(Arguments* args, const BString& currentDirectory)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char* const* argv = NULL;
|
const char* const* argv = NULL;
|
||||||
if (args != NULL)
|
if (args != NULL)
|
||||||
args->GetShellArguments(argc, argv);
|
args->GetShellArguments(argc, argv);
|
||||||
|
ShellParameters shellParameters(argc, argv, currentDirectory);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Note: I don't pass the Arguments class directly to the termview,
|
|
||||||
// only to avoid adding it as a dependency: in other words, to keep
|
|
||||||
// the TermView class as agnostic as possible about the surrounding
|
|
||||||
// world.
|
|
||||||
CustomTermView* view = new CustomTermView(
|
CustomTermView* view = new CustomTermView(
|
||||||
PrefHandler::Default()->getInt32(PREF_ROWS),
|
PrefHandler::Default()->getInt32(PREF_ROWS),
|
||||||
PrefHandler::Default()->getInt32(PREF_COLS),
|
PrefHandler::Default()->getInt32(PREF_COLS),
|
||||||
argc, (const char**)argv,
|
shellParameters,
|
||||||
PrefHandler::Default()->getInt32(PREF_HISTORY_SIZE));
|
PrefHandler::Default()->getInt32(PREF_HISTORY_SIZE));
|
||||||
|
|
||||||
TermViewContainerView* containerView = new TermViewContainerView(view);
|
TermViewContainerView* containerView = new TermViewContainerView(view);
|
||||||
@@ -1104,9 +1109,10 @@ TermWindow::_NewSessionID()
|
|||||||
|
|
||||||
|
|
||||||
// CustomTermView
|
// CustomTermView
|
||||||
CustomTermView::CustomTermView(int32 rows, int32 columns, int32 argc, const char **argv, int32 historySize)
|
CustomTermView::CustomTermView(int32 rows, int32 columns,
|
||||||
|
const ShellParameters& shellParameters, int32 historySize)
|
||||||
:
|
:
|
||||||
TermView(rows, columns, argc, argv, historySize)
|
TermView(rows, columns, shellParameters, historySize)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ private:
|
|||||||
void _GetPreferredFont(BFont &font);
|
void _GetPreferredFont(BFont &font);
|
||||||
status_t _DoPageSetup();
|
status_t _DoPageSetup();
|
||||||
void _DoPrint();
|
void _DoPrint();
|
||||||
void _AddTab(Arguments* args);
|
void _AddTab(Arguments* args,
|
||||||
|
const BString& currentDirectory
|
||||||
|
= BString());
|
||||||
void _RemoveTab(int32 index);
|
void _RemoveTab(int32 index);
|
||||||
bool _CanClose(int32 index);
|
bool _CanClose(int32 index);
|
||||||
TermViewContainerView* _ActiveTermViewContainerView() const;
|
TermViewContainerView* _ActiveTermViewContainerView() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user