FreeNOS
Terminal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __TERMINAL_TERMINAL_H
19 #define __TERMINAL_TERMINAL_H
20 
21 #include <FreeNOS/Config.h>
22 #include <Device.h>
23 #include <Macros.h>
24 #include <Types.h>
25 #include <teken.h>
26 
38 #define BANNER \
39  "FreeNOS " RELEASE " [" ARCH "/" SYSTEM "] (" BUILDUSER "@" BUILDHOST ") (" COMPILER_VERSION ") " DATETIME "\r\n"
40 
44 class Terminal : public Device
45 {
46  public:
47 
58  Terminal(const u32 inode,
59  const char *inputFile,
60  const char *outputFile,
61  const Size width = 80,
62  const Size height = 25);
63 
67  virtual ~Terminal();
68 
74  Size getWidth();
75 
81  Size getHeight();
82 
88  int getInput();
89 
95  int getOutput();
96 
102  u16 * getBuffer();
103 
109  u16 * getCursorValue();
110 
114  void hideCursor();
115 
121  void setCursor(const teken_pos_t *pos);
122 
126  void showCursor();
127 
133  virtual FileSystem::Result initialize();
134 
146  Size & size,
147  const Size offset);
148 
160  Size & size,
161  const Size offset);
162 
163  private:
164 
173  FileSystem::Result writeTerminal(const u8 *bytes,
174  const Size size);
175 
176  private:
177 
180 
183 
186 
189 
192 
196  const char *inputFile, *outputFile;
197 
201  const Size width, height;
202 
204  int input, output;
205 };
206 
212 void bell(Terminal *term);
213 
222 void putchar(Terminal *term, const teken_pos_t *pos,
223  teken_char_t ch, const teken_attr_t *attr);
224 
231 void cursor(Terminal *term, const teken_pos_t *pos);
232 
241 void fill(Terminal *ctx, const teken_rect_t *rect,
242  teken_char_t ch, const teken_attr_t *attr);
243 
251 void copy(Terminal *ctx, const teken_rect_t *rect,
252  const teken_pos_t *pos);
253 
261 void param(Terminal *ctx, int key, int value);
262 
266 void respond(Terminal *ctx, const void *buf, size_t size);
267 
273 #endif /* __TERMINAL_TERMINAL_H */
Terminal::output
int output
Definition: Terminal.h:204
copy
void copy(Terminal *ctx, const teken_rect_t *rect, const teken_pos_t *pos)
Copy bytes to the terminal.
Definition: Terminal.cpp:282
Terminal::writeTerminal
FileSystem::Result writeTerminal(const u8 *bytes, const Size size)
Write bytes to the output device.
Definition: Terminal.cpp:173
Terminal::cursorPos
teken_pos_t cursorPos
Saved cursor position.
Definition: Terminal.h:188
Device.h
Terminal::inputFile
const char * inputFile
Path to the input and output files.
Definition: Terminal.h:196
Macros.h
Terminal::getInput
int getInput()
Retrieve file descriptor of the input source.
Definition: Terminal.cpp:125
Types.h
Terminal::setCursor
void setCursor(const teken_pos_t *pos)
Sets the new position of the cursor.
Definition: Terminal.cpp:211
Terminal::buffer
u16 * buffer
Buffer for local Terminal updates.
Definition: Terminal.h:185
Terminal::getCursorValue
u16 * getCursorValue()
Saved byte and attribute value at cursor position.
Definition: Terminal.cpp:140
Terminal::~Terminal
virtual ~Terminal()
Class destructor.
Definition: Terminal.cpp:108
Device
Abstract device class interface.
Definition: Device.h:35
teken_attr_t
Definition: teken.h:76
Terminal::state
teken_t state
Terminal state.
Definition: Terminal.h:179
Terminal::height
const Size height
Definition: Terminal.h:201
param
void param(Terminal *ctx, int key, int value)
Set terminal parameters.
Definition: Terminal.cpp:305
Terminal::showCursor
void showCursor()
Show the VGA cursor.
Definition: Terminal.cpp:218
Terminal::cursorValue
u16 cursorValue
Saved value at cursor position.
Definition: Terminal.h:191
Terminal::initialize
virtual FileSystem::Result initialize()
Initialize the Terminal.
Definition: Terminal.cpp:57
teken_funcs_t
Definition: teken.h:113
Terminal::funcs
teken_funcs_t funcs
Terminal function handlers.
Definition: Terminal.h:182
Terminal::getWidth
Size getWidth()
Retrieve the width of the Terminal.
Definition: Terminal.cpp:115
Terminal::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the Terminal.
Definition: Terminal.cpp:145
teken.h
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
cursor
void cursor(Terminal *term, const teken_pos_t *pos)
Sets the Terminal cursor.
Definition: Terminal.cpp:253
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
bell
void bell(Terminal *term)
Makes a sound (bell).
Definition: Terminal.cpp:230
teken_char_t
unsigned char teken_char_t
Definition: teken.h:49
Terminal::Terminal
Terminal(const u32 inode, const char *inputFile, const char *outputFile, const Size width=80, const Size height=25)
Class constructor.
Definition: Terminal.cpp:42
__teken
Definition: teken.h:131
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
Terminal::hideCursor
void hideCursor()
Hides the cursor from the VGA screen.
Definition: Terminal.cpp:202
Terminal::getBuffer
u16 * getBuffer()
Retrieve a pointer to the local buffer.
Definition: Terminal.cpp:135
teken_pos_t
Definition: teken.h:68
Terminal::getHeight
Size getHeight()
Retrieve the height of the Terminal.
Definition: Terminal.cpp:120
Terminal::width
const Size width
Width and height of the Terminal.
Definition: Terminal.h:201
Terminal::getOutput
int getOutput()
Retrieve file descriptor of the output source.
Definition: Terminal.cpp:130
respond
void respond(Terminal *ctx, const void *buf, size_t size)
Unused.
Definition: Terminal.cpp:310
Terminal::input
int input
Input and output file descriptors.
Definition: Terminal.h:204
fill
void fill(Terminal *ctx, const teken_rect_t *rect, teken_char_t ch, const teken_attr_t *attr)
Fills the Terminal buffer with a character.
Definition: Terminal.cpp:260
putchar
void putchar(Terminal *term, const teken_pos_t *pos, teken_char_t ch, const teken_attr_t *attr)
Output a new character.
Definition: Terminal.cpp:235
Terminal
A Terminal enables user to interact with the system.
Definition: Terminal.h:44
teken_rect_t
Definition: teken.h:72
Terminal::outputFile
const char * outputFile
Definition: Terminal.h:196
Terminal::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the Terminal.
Definition: Terminal.cpp:166