Shell.h revision abc4720231b10f87fa94d5d1e47d18650cf457de
1/*
2 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
3 * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files or portions
8 * thereof (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject
12 * to the following conditions:
13 *
14 *  * Redistributions of source code must retain the above copyright notice,
15 *    this list of conditions and the following disclaimer.
16 *
17 *  * Redistributions in binary form must reproduce the above copyright notice
18 *    in the  binary, as well as this list of conditions and the following
19 *    disclaimer in the documentation and/or other materials provided with
20 *    the distribution.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 * THE SOFTWARE.
29 *
30 */
31
32#ifndef _SHELL_H
33#define _SHELL_H
34
35#define MAXPTTYS 16 * 4
36
37#ifndef CEOF
38#define CEOF ('D'&037)
39#endif
40#ifndef CSUSP
41#define CSUSP ('@'&037)
42#endif
43#ifndef CQUIT
44#define CQUIT ('\\'&037)
45#endif
46#ifndef CEOL
47#define CEOL 0
48#endif
49#ifndef CSTOP
50#define CSTOP ('Q'&037)
51#endif
52#ifndef CSTART
53#define CSTART ('S'&037)
54#endif
55#ifndef CSWTCH
56#define CSWTCH 0
57#endif
58
59/*
60 * ANSI emulation.
61 */
62#define INQ	0x05
63#define	FF	0x0C			/* C0, C1 control names		*/
64#define	LS1	0x0E
65#define	LS0	0x0F
66#define	CAN	0x18
67#define	SUB	0x1A
68#define	ESC	0x1B
69#define US	0x1F
70#define	DEL	0x7F
71#define HTS     ('H'+0x40)
72#define	SS2	0x8E
73#define	SS3	0x8F
74#define	DCS	0x90
75#define	OLDID	0x9A			/* ESC Z			*/
76#define	CSI	0x9B
77#define	ST	0x9C
78#define	OSC	0x9D
79#define	PM	0x9E
80#define	APC	0x9F
81#define	RDEL	0xFF
82
83
84// TODO: Maybe merge TermParse and Shell classes ?
85class TermParse;
86class TermView;
87class Shell {
88public:
89			Shell();
90	virtual		~Shell();
91
92	status_t	Open(int row, int col, const char *command, const char *coding);
93	void		Close();
94
95	const char *	TTYName() const;
96
97	ssize_t		Read(void *buffer, size_t numBytes);
98	ssize_t		Write(const void *buffer, size_t numBytes);
99
100	status_t	UpdateWindowSize(int row, int columns);
101	status_t	Signal(int signal);
102
103	status_t	GetAttr(struct termios &attr);
104	status_t	SetAttr(struct termios &attr);
105
106	int		FD() const;
107
108	virtual	void	ViewAttached(TermView *view);
109	virtual void	ViewDetached();
110
111private:
112	int		fFd;
113	pid_t		fProcessID;
114	TermParse	*fTermParse;
115	bool		fAttached;
116
117	status_t	_Spawn(int row, int col, const char *command, const char *coding);
118};
119
120#endif // _SHELL_H
121