Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::drivers::console::ConsoleStream Class Reference

A stream that can be used to write to a console. More...

#include <console.h>

Inheritance diagram for MaxOS::drivers::console::ConsoleStream:
MaxOS::common::OutputStream MaxOS::common::GenericOutputStream< string > MaxOS::common::InputStreamProcessor< Type, ProcessorType > MaxOS::common::InputStreamEventHandler< Type > MaxOS::common::GenericInputStream< ProcessorType >

Public Member Functions

 ConsoleStream (Console *)
 Construct a new Console Stream object.
 
void write_char (char c) override
 write a character to the console stream
 
void set_cursor (uint16_t x, uint16_t y)
 Set the m_position of the cursor.
 
- Public Member Functions inherited from MaxOS::common::OutputStream
 OutputStream ()
 Constructs an OutputStream object that uses strings as the underlying data type.
 
virtual void line_feed ()
 Writes a newline to the output stream.
 
virtual void carriage_return ()
 Writes a carriage return to the output stream.
 
virtual void clear ()
 Clears the output stream.
 
void write (string string_to_write) override
 Writes a string to the output stream.
 
void write (const char *string_to_write)
 Writes a string to the output stream.
 
virtual void write_int (int int_to_write)
 Writes an integer to the output stream.
 
virtual void write_hex (uint64_t hex_to_write)
 Writes a hex to the output stream.
 
OutputStreamoperator<< (string string_to_write) override
 Writes a string to the output stream.
 
OutputStreamoperator<< (const char *string_to_write)
 Writes a string to the output stream.
 
OutputStreamoperator<< (int int_to_write)
 Writes a integer to the output stream.
 
OutputStreamoperator<< (uint64_t hex_to_write)
 Writes a hexadecimal to the output stream.
 
OutputStreamoperator<< (char char_to_write)
 Writes a character to the output stream.
 
- Public Member Functions inherited from MaxOS::common::GenericOutputStream< string >
 GenericOutputStream ()
 __________________________________________Templates__________________________________________________///
 
 ~GenericOutputStream ()
 Destructor of the GenericOutputStream class.
 
void on_stream_read (string) override
 Writes the date that was read from the input stream to the output stream.
 
void on_end_of_stream (GenericInputStream< string > *) override
 Close the stream and remove it from the list of streams when the end of the stream is reached.
 
virtual void write (string)
 write an element to the stream.
 
virtual void close ()
 Close the stream.
 
virtual GenericOutputStream< string > & operator<< (string)
 Overload the << operator to write an element to the stream.
 
- Public Member Functions inherited from MaxOS::common::InputStreamProcessor< Type, ProcessorType >
 InputStreamProcessor ()
 Creates a new InputStreamProcessor.
 
 InputStreamProcessor (InputStreamEventHandler< ProcessorType > *generic_stream_event_handler)
 Creates a new InputStreamProcessor.
 
 ~InputStreamProcessor ()
 Destroys the InputStreamProcessor.
 
void on_end_of_stream (GenericInputStream< Type > *stream) override
 Called when a stream has finished. Passes the event on to the handlers and then removes the stream from the array of streams.
 
- Public Member Functions inherited from MaxOS::common::InputStreamEventHandler< Type >
 InputStreamEventHandler ()
 _______________________________________________TEMPLATES_________________________________________________________________///
 
 ~InputStreamEventHandler ()
 Destroys the InputStreamProcessor and disconnects it from all streams.
 
- Public Member Functions inherited from MaxOS::common::GenericInputStream< ProcessorType >
 GenericInputStream ()
 Creates a new GenericInputStream.
 
 GenericInputStream (InputStreamEventHandler< ProcessorType > *)
 Creates a new GenericInputStream and connects it to the handler.
 
 ~GenericInputStream ()
 Destroys the GenericInputStream and disconnects all handlers.
 
void connect_input_stream_event_handler (InputStreamEventHandler< ProcessorType > *)
 Adds a inputStreamEventHandler to the list of internetProtocolHandlers.
 
void disconnect_input_stream_event_handler (InputStreamEventHandler< ProcessorType > *)
 Removes a handler from the list of handlers.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::common::InputStreamEventHandler< Type >
common::Vector< GenericInputStream< Type > * > m_generic_input_streams
 List of streams being observed by this handler.
 
- Protected Attributes inherited from MaxOS::common::GenericInputStream< ProcessorType >
common::Vector< InputStreamEventHandler< ProcessorType > * > m_input_stream_event_handlers
 List of streams being observed by this handler.
 

Detailed Description

A stream that can be used to write to a console.

Definition at line 91 of file console.h.

Constructor & Destructor Documentation

◆ ConsoleStream()

ConsoleStream::ConsoleStream ( Console console)
explicit

Construct a new Console Stream object.

Parameters
consoleThe console to create the stream on

Definition at line 424 of file console.cpp.

425 : m_console(console) {
426
427}

Member Function Documentation

◆ set_cursor()

void ConsoleStream::set_cursor ( uint16_t  x,
uint16_t  y 
)

Set the m_position of the cursor.

Parameters
xThe x coordinate of the cursor
yThe y coordinate of the cursor

Definition at line 510 of file console.cpp.

510 {
511
512 // Set the x and y coordinates
513 m_cursor_x = x;
514 m_cursor_y = y;
515}

Referenced by MaxOS::drivers::console::VESABootConsole::finish().

◆ write_char()

void ConsoleStream::write_char ( char  c)
overridevirtual

write a character to the console stream

Parameters
cThe character to write

Reimplemented from MaxOS::common::OutputStream.

Definition at line 436 of file console.cpp.

436 {
437
438 uint16_t spaces = 0;
439
440 // If the character placement is more than the width of the console go on a new line
441 if(m_cursor_x >= m_console->width() && c != '\n') {
442 line_feed();
443 write(" ");
444 }
445
446 // Check if the character is an ANSI escape code
447 if(c == '\033') is_ansi = true;
448
449 // Handle the character
450 switch(c) {
451 // New line
452 case '\n':
453 // Go to the next line, if it is more than what the console can fit then scroll
454 if(++m_cursor_y >= m_console->height()) {
455 m_console->scroll_up();
456
457 // Ensure there is space at the bottom to write
458 m_cursor_y = m_console->height() - 1;
459 }
460
461 // don't break here, we want to go to the next case because of the \r
462 [[fallthrough]];
463
464 // Carriage return
465 case '\r':
466 m_cursor_x = 0;
467 break;
468
469 // End of string
470 case '\0':
471 break;
472
473 // Backspace
474 case '\b':
475 m_cursor_x--;
476 break;
477
478 // Tab
479 case '\t':
480
481 // Pad with spaces until a tab is reached
482 spaces = 8 - (m_cursor_x % 8);
483 for(uint16_t i = 0; i < spaces; i++)
484 write_char(' '); //TODO: Recursive, dont
485 break;
486
487 default:
488 // Put the character on the console
489 m_console->put_character(m_cursor_x, m_cursor_y, c);
490
491 // Increment the x coordinate (ANSI aren't rendered)
492 if(!is_ansi)
493 m_cursor_x++;
494
495 break;
496
497 }
498
499 // Check if the ANSI code is complete
500 if(c == 'm') is_ansi = false;
501
502}
void write(string string_to_write) override
Writes a string to the output stream.
virtual void line_feed()
Writes a newline to the output stream.
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
void write_char(char c) override
write a character to the console stream
Definition console.cpp:436
virtual void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:142
virtual uint16_t height()
Get the height of the console in characters.
Definition console.cpp:34
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:45
virtual uint16_t width()
Get the width of the console in characters.
Definition console.cpp:25

References MaxOS::drivers::console::Console::height(), MaxOS::common::OutputStream::line_feed(), MaxOS::drivers::console::Console::put_character(), MaxOS::drivers::console::Console::scroll_up(), MaxOS::drivers::console::Console::width(), MaxOS::common::OutputStream::write(), and write_char().

Referenced by write_char().


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