FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
Terminal Class Reference

A Terminal enables user to interact with the system. More...

#include <Terminal.h>

Inheritance diagram for Terminal:
Device File

Public Member Functions

 Terminal (const u32 inode, const char *inputFile, const char *outputFile, const Size width=80, const Size height=25)
 Class constructor. More...
 
virtual ~Terminal ()
 Class destructor. More...
 
Size getWidth ()
 Retrieve the width of the Terminal. More...
 
Size getHeight ()
 Retrieve the height of the Terminal. More...
 
int getInput ()
 Retrieve file descriptor of the input source. More...
 
int getOutput ()
 Retrieve file descriptor of the output source. More...
 
u16getBuffer ()
 Retrieve a pointer to the local buffer. More...
 
u16getCursorValue ()
 Saved byte and attribute value at cursor position. More...
 
void hideCursor ()
 Hides the cursor from the VGA screen. More...
 
void setCursor (const teken_pos_t *pos)
 Sets the new position of the cursor. More...
 
void showCursor ()
 Show the VGA cursor. More...
 
virtual FileSystem::Result initialize ()
 Initialize the Terminal. More...
 
virtual FileSystem::Result read (IOBuffer &buffer, Size &size, const Size offset)
 Read bytes from the Terminal. More...
 
virtual FileSystem::Result write (IOBuffer &buffer, Size &size, const Size offset)
 Write bytes to the Terminal. More...
 
- Public Member Functions inherited from Device
 Device (const u32 inode, const FileSystem::FileType type)
 Constructor. More...
 
virtual ~Device ()
 Destructor. More...
 
virtual const StringgetIdentifier () const
 Get unique device identifier. More...
 
virtual FileSystem::Result interrupt (const Size vector)
 Called when an interrupt has been triggered for this device. More...
 
- Public Member Functions inherited from File
 File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO)
 Constructor function. More...
 
virtual ~File ()
 Destructor function. More...
 
u32 getInode () const
 Get inode number. More...
 
FileSystem::FileType getType () const
 Retrieve our filetype. More...
 
virtual FileSystem::Result status (FileSystem::FileStat &st)
 Retrieve file statistics. More...
 
virtual bool canRead () const
 Check if the File has data ready for reading. More...
 
virtual bool canWrite () const
 Check if the File can be written to. More...
 

Private Member Functions

FileSystem::Result writeTerminal (const u8 *bytes, const Size size)
 Write bytes to the output device. More...
 

Private Attributes

teken_t state
 Terminal state. More...
 
teken_funcs_t funcs
 Terminal function handlers. More...
 
u16buffer
 Buffer for local Terminal updates. More...
 
teken_pos_t cursorPos
 Saved cursor position. More...
 
u16 cursorValue
 Saved value at cursor position. More...
 
const char * inputFile
 Path to the input and output files. More...
 
const char * outputFile
 
const Size width
 Width and height of the Terminal. More...
 
const Size height
 
int input
 Input and output file descriptors. More...
 
int output
 

Additional Inherited Members

- Protected Attributes inherited from Device
String m_identifier
 Unique identifier for this Device. More...
 
- Protected Attributes inherited from File
const u32 m_inode
 Inode number. More...
 
const FileSystem::FileType m_type
 Type of this file. More...
 
UserID m_uid
 Owner of the file. More...
 
GroupID m_gid
 Group of the file. More...
 
FileSystem::FileModes m_access
 Access permissions. More...
 
Size m_size
 Size of the file, in bytes. More...
 

Detailed Description

A Terminal enables user to interact with the system.

Definition at line 44 of file Terminal.h.

Constructor & Destructor Documentation

◆ Terminal()

Terminal::Terminal ( const u32  inode,
const char *  inputFile,
const char *  outputFile,
const Size  width = 80,
const Size  height = 25 
)

Class constructor.

Parameters
inodeInode number
inputFilePath to the (device) file to use as input source.
outputFilePath to the (device) file to use as an output source.
widthWidth of the Terminal.
heightHeight of the Terminal.

Definition at line 42 of file Terminal.cpp.

References buffer, height, Device::m_identifier, and width.

◆ ~Terminal()

Terminal::~Terminal ( )
virtual

Class destructor.

Definition at line 108 of file Terminal.cpp.

References buffer, close(), input, and output.

Member Function Documentation

◆ getBuffer()

u16 * Terminal::getBuffer ( )

Retrieve a pointer to the local buffer.

Returns
Pointer to the local buffer.

Definition at line 135 of file Terminal.cpp.

References buffer.

Referenced by copy(), fill(), and putchar().

◆ getCursorValue()

u16 * Terminal::getCursorValue ( )

Saved byte and attribute value at cursor position.

Returns
Saved value.

Definition at line 140 of file Terminal.cpp.

References cursorValue.

◆ getHeight()

Size Terminal::getHeight ( )

Retrieve the height of the Terminal.

Returns
Terminal height.

Definition at line 120 of file Terminal.cpp.

References height.

◆ getInput()

int Terminal::getInput ( )

Retrieve file descriptor of the input source.

Returns
File descriptor number.

Definition at line 125 of file Terminal.cpp.

References input.

◆ getOutput()

int Terminal::getOutput ( )

Retrieve file descriptor of the output source.

Returns
File descriptor number.

Definition at line 130 of file Terminal.cpp.

References output.

◆ getWidth()

Size Terminal::getWidth ( )

Retrieve the width of the Terminal.

Returns
Terminal width.

Definition at line 115 of file Terminal.cpp.

References width.

Referenced by copy(), fill(), and putchar().

◆ hideCursor()

void Terminal::hideCursor ( )

Hides the cursor from the VGA screen.

Definition at line 202 of file Terminal.cpp.

References buffer, cursorPos, cursorValue, teken_pos_t::tp_col, teken_pos_t::tp_row, and width.

Referenced by copy(), cursor(), fill(), and putchar().

◆ initialize()

FileSystem::Result Terminal::initialize ( )
virtual

◆ read()

FileSystem::Result Terminal::read ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Read bytes from the Terminal.

Parameters
bufferInput/Output buffer to output bytes to.
sizeMaximum number of bytes to read on input. On output, the actual number of bytes read.
offsetOffset inside the file to start reading.
Returns
Result code

Reimplemented from File.

Definition at line 145 of file Terminal.cpp.

References buffer, input, FileSystem::IOError, and FileSystem::Success.

Referenced by writeTerminal().

◆ setCursor()

void Terminal::setCursor ( const teken_pos_t pos)

Sets the new position of the cursor.

Parameters
posNew position coordinates.

Definition at line 211 of file Terminal.cpp.

References buffer, cursorPos, cursorValue, teken_pos_t::tp_col, teken_pos_t::tp_row, and width.

Referenced by cursor(), and showCursor().

◆ showCursor()

void Terminal::showCursor ( )

Show the VGA cursor.

Definition at line 218 of file Terminal.cpp.

References buffer, cursorPos, LIGHTGREY, setCursor(), teken_pos_t::tp_col, teken_pos_t::tp_row, VGA_ATTR, and width.

Referenced by copy(), cursor(), fill(), and putchar().

◆ write()

FileSystem::Result Terminal::write ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Write bytes to the Terminal.

Parameters
bufferInput/Output buffer to input bytes from.
sizeMaximum number of bytes to write on input. On output, the actual number of bytes written.
offsetOffset inside the file to start writing.
Returns
Result code

Reimplemented from File.

Definition at line 166 of file Terminal.cpp.

References buffer, and writeTerminal().

Referenced by writeTerminal().

◆ writeTerminal()

FileSystem::Result Terminal::writeTerminal ( const u8 bytes,
const Size  size 
)
private

Write bytes to the output device.

Parameters
bytesInput bytes
sizeNumber of input bytes
Returns
Result code

Definition at line 173 of file Terminal.cpp.

References buffer, height, lseek(), output, read(), SEEK_SET, state, FileSystem::Success, teken_input(), width, and write().

Referenced by initialize(), and write().

Field Documentation

◆ buffer

u16* Terminal::buffer
private

Buffer for local Terminal updates.

Definition at line 185 of file Terminal.h.

Referenced by getBuffer(), hideCursor(), read(), setCursor(), showCursor(), Terminal(), write(), writeTerminal(), and ~Terminal().

◆ cursorPos

teken_pos_t Terminal::cursorPos
private

Saved cursor position.

Definition at line 188 of file Terminal.h.

Referenced by hideCursor(), initialize(), setCursor(), and showCursor().

◆ cursorValue

u16 Terminal::cursorValue
private

Saved value at cursor position.

Definition at line 191 of file Terminal.h.

Referenced by getCursorValue(), hideCursor(), and setCursor().

◆ funcs

teken_funcs_t Terminal::funcs
private

Terminal function handlers.

Definition at line 182 of file Terminal.h.

Referenced by initialize().

◆ height

const Size Terminal::height
private

Definition at line 201 of file Terminal.h.

Referenced by getHeight(), Terminal(), and writeTerminal().

◆ input

int Terminal::input
private

Input and output file descriptors.

Definition at line 204 of file Terminal.h.

Referenced by getInput(), initialize(), read(), and ~Terminal().

◆ inputFile

const char* Terminal::inputFile
private

Path to the input and output files.

Definition at line 196 of file Terminal.h.

Referenced by initialize().

◆ output

int Terminal::output
private

Definition at line 204 of file Terminal.h.

Referenced by getOutput(), initialize(), writeTerminal(), and ~Terminal().

◆ outputFile

const char * Terminal::outputFile
private

Definition at line 196 of file Terminal.h.

Referenced by initialize().

◆ state

teken_t Terminal::state
private

Terminal state.

Definition at line 179 of file Terminal.h.

Referenced by initialize(), and writeTerminal().

◆ width

const Size Terminal::width
private

Width and height of the Terminal.

Definition at line 201 of file Terminal.h.

Referenced by getWidth(), hideCursor(), setCursor(), showCursor(), Terminal(), and writeTerminal().


The documentation for this class was generated from the following files: