Cleanup the terminal system

This commit is contained in:
Baptiste Wicht 2016-09-24 19:45:58 +02:00
parent 565c364f6f
commit 321c6dcf5d
9 changed files with 307 additions and 124 deletions

View File

@ -16,30 +16,68 @@
namespace stdio {
/*!
* \brief Init the console
*/
void init_console();
/*!
* \brief A console
*/
struct console {
/*!
* \brief Init the console
*/
void init();
/*!
* \brief Returns the number of columns of the console
*/
size_t get_columns() const;
/*!
* \brief Returns the number of rows of the console
*/
size_t get_rows() const;
/*!
* \brief Print the given char to the console
* \param c The character to print
*/
void print(char c);
/*!
* \brief Clear the console
*/
void wipeout();
/*!
* \brief Set the active status of the console
* \param active The active status of the console
*/
void set_active(bool active);
/*!
* \brief Save the state of the console
*/
void save();
/*!
* \brief Restore the state of the console
*/
void restore();
private:
/*!
* \brief Move to the next line
*/
void next_line();
size_t current_line = 0;
size_t current_column = 0;
size_t current_line = 0; ///< The current line of the console
size_t current_column = 0; ///< The current column of the console
void* buffer = nullptr;
bool active = false;
void* buffer = nullptr; ///< The buffer to save the state
bool active = false; ///< The active status of the console
};
} // end of namespace stdio

View File

@ -14,14 +14,40 @@
namespace stdio {
/*!
* \brief Initialize the terminals
*/
void init_terminals();
/*!
* \brief Register the devices into the devfs
*/
void register_devices();
/*!
* \brief Finalize the terminals
*/
void finalize();
/*!
* \brief Switch the active terminal to the terminal with the given id
* \param id The terminal to activate
*/
void switch_terminal(size_t id);
/*!
* \brief Returns the number of terminals
*/
size_t terminals_count();
/*!
* \brief Returns the active terminal
*/
virtual_terminal& get_active_terminal();
/*!
* \brief Returns the terminal with the given id
*/
virtual_terminal& get_terminal(size_t id);
} //end of namespace stdio

View File

@ -23,7 +23,13 @@ namespace stdio {
constexpr const size_t INPUT_BUFFER_SIZE = 256;
/*!
* \brief A virtual terminal
*/
struct virtual_terminal {
/*!
* \brief Construct a new virtual_terminal
*/
virtual_terminal(){}
virtual_terminal(const virtual_terminal& rhs) = delete;
@ -32,6 +38,10 @@ struct virtual_terminal {
virtual_terminal(virtual_terminal&& rhs) = delete;
virtual_terminal& operator=(virtual_terminal&& rhs) = delete;
/*!
* \brief Print the given char to the terminal
* \param c The character to print
*/
void print(char c);
/*!
@ -76,13 +86,36 @@ struct virtual_terminal {
*/
size_t read_input_raw(size_t ms);
/*!
* \brief Set the canonical mode of the terminal
* \param can The canonical mode of the terminal
*/
void set_canonical(bool can);
/*!
* \brief Set the mouse mode of the terminal
* \param can The mouse mode of the terminal
*/
void set_mouse(bool m);
/*!
* \brief Returns true if the terminal is in canonical mode, false otherwise
*/
bool is_canonical() const;
/*!
* \brief Returns true if the terminal is in mouse mode, false otherwise
*/
bool is_mouse() const;
/*!
* \brief Set the active mode of the terminal
*/
void set_active(bool);
/*!
* \brief Returns the console linked to this terminal
*/
console& get_console();
size_t id;

View File

@ -10,12 +10,41 @@
#include <types.hpp>
/*!
* \brief A textual console
*/
struct text_console {
/*!
* \brief Initialize the console
*/
void init();
/*!
* \brief Returns the number of lines of the console
*/
size_t lines();
/*!
* \brief Returns the number of columns of the console
*/
size_t columns();
/*!
* \brief Clear the text console
*/
void clear();
/*!
* \brief Scroll up one line
*/
void scroll_up();
/*!
* \brief Print a char at the given line and column
* \param line The line at which to print the char
* \param column The column at which to print the char
* \param c The char to print
*/
void print_char(size_t line, size_t column, char c);
};

View File

@ -10,22 +10,75 @@
#include <types.hpp>
/*!
* \brief A VESA console
*/
struct vesa_console {
/*!
* \brief Initialize the console
*/
void init();
/*!
* \brief Returns the number of lines of the console
*/
size_t lines() const;
/*!
* \brief Returns the number of columns of the console
*/
size_t columns() const;
/*!
* \brief Clear the vesa console
*/
void clear();
/*!
* \brief Clear the given vesa console state
* \param buffer The VESA console state
*/
void clear(void* buffer);
/*!
* \brief Scroll up one line
*/
void scroll_up();
/*!
* \brief Scroll up one line on the given vesa console state
* \param buffer The VESA console state
*/
void scroll_up(void* buffer);
/*!
* \brief Print a char at the given line and column
* \param line The line at which to print the char
* \param column The column at which to print the char
* \param c The char to print
*/
void print_char(size_t line, size_t column, char c);
/*!
* \brief Print a char at the given line and column on the given vesa console state
* \param buffer The VESA console state
* \param line The line at which to print the char
* \param column The column at which to print the char
* \param c The char to print
*/
void print_char(void* buffer, size_t line, size_t column, char c);
/*!
* \brief Save the state of the console
* \param buffer The buffer to save to
* \return the buffer the state was saved to
*/
void* save(void* buffer);
/*!
* \brief Restore the state of the console
* \param buffer The buffer to restore from
*/
void restore(void* buffer);
};

View File

@ -115,7 +115,7 @@ void input_thread(void* data){
while (!terminal.mouse_buffer.empty()) {
auto key = terminal.mouse_buffer.pop();
if(!terminal.canonical && terminal.mouse){
if (!terminal.canonical && terminal.is_mouse()) {
terminal.raw_buffer.push(key);
terminal.input_queue.notify_one();

View File

@ -130,6 +130,10 @@ bool stdio::virtual_terminal::is_canonical() const {
return canonical;
}
bool stdio::virtual_terminal::is_mouse() const {
return mouse;
}
void stdio::virtual_terminal::set_active(bool active) {
if (this->active == active) {
return;