| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/system/terminals.hpp" | ||
| 30 | #include "gate/exceptions.hpp" | ||
| 31 | |||
| 32 | namespace gate | ||
| 33 | { | ||
| 34 | namespace sys | ||
| 35 | { | ||
| 36 | |||
| 37 | 2 | Terminal::Terminal(gate_terminal_t* ptr_terminal) | |
| 38 | : Stream((gate_stream_t*)ptr_terminal), | ||
| 39 | 2 | terminal(ptr_terminal) | |
| 40 | { | ||
| 41 | 2 | } | |
| 42 | ✗ | Terminal::Terminal(Terminal const& src) | |
| 43 | : Stream(src), | ||
| 44 | ✗ | terminal(src.terminal) | |
| 45 | { | ||
| 46 | ✗ | } | |
| 47 | ✗ | Terminal& Terminal::operator=(Terminal const& src) | |
| 48 | { | ||
| 49 | ✗ | if (this != &src) | |
| 50 | { | ||
| 51 | ✗ | Stream::operator=(src); | |
| 52 | ✗ | this->terminal = src.terminal; | |
| 53 | } | ||
| 54 | ✗ | return *this; | |
| 55 | } | ||
| 56 | 2 | Terminal::~Terminal() | |
| 57 | { | ||
| 58 | 2 | } | |
| 59 | |||
| 60 | ✗ | void Terminal::getSize(uint16_t& width, uint16_t& height) | |
| 61 | { | ||
| 62 | ✗ | result_t result = gate_terminal_get_size(this->terminal, &width, &height); | |
| 63 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 64 | ✗ | } | |
| 65 | |||
| 66 | ✗ | void Terminal::getCursorPos(uint16_t& x, uint16_t& y) | |
| 67 | { | ||
| 68 | ✗ | result_t result = gate_terminal_get_cursor_pos(this->terminal, &x, &y); | |
| 69 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 70 | ✗ | } | |
| 71 | ✗ | void Terminal::setCursorPos(uint16_t x, uint16_t y) | |
| 72 | { | ||
| 73 | ✗ | result_t result = gate_terminal_set_cursor_pos(this->terminal, x, y); | |
| 74 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 75 | ✗ | } | |
| 76 | |||
| 77 | 2 | void Terminal::setTextColor(ColorEnum color) | |
| 78 | { | ||
| 79 | 2 | gate_uint8_t color_value = (gate_uint8_t)color; | |
| 80 | 2 | result_t result = gate_terminal_set_text_color(this->terminal, color_value); | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 82 | 2 | } | |
| 83 | 2 | Terminal::ColorEnum Terminal::getTextColor() | |
| 84 | { | ||
| 85 | 2 | gate_uint8_t color_value = 0; | |
| 86 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_terminal_get_text_color(this->terminal, &color_value); |
| 87 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 88 | 2 | return (Terminal::ColorEnum)color_value; | |
| 89 | } | ||
| 90 | |||
| 91 | 2 | void Terminal::setBackColor(ColorEnum color) | |
| 92 | { | ||
| 93 | 2 | gate_uint8_t color_value = (gate_uint8_t)color; | |
| 94 | 2 | result_t result = gate_terminal_set_back_color(this->terminal, color_value); | |
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 96 | 2 | } | |
| 97 | 2 | Terminal::ColorEnum Terminal::getBackColor() | |
| 98 | { | ||
| 99 | 2 | gate_uint8_t color_value = 0; | |
| 100 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_terminal_get_back_color(this->terminal, &color_value); |
| 101 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 102 | 2 | return (Terminal::ColorEnum)color_value; | |
| 103 | } | ||
| 104 | |||
| 105 | 1 | Terminal Terminal::getConsole() | |
| 106 | { | ||
| 107 | 1 | gate_terminal_t* term = gate_terminal_console_get_current(); | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (term == NULL) |
| 109 | { | ||
| 110 | ✗ | GATEXX_RAISE_EXCEPTION(results::NotAvailable, "Cannot access current console as terminal", 0); | |
| 111 | } | ||
| 112 | 1 | return Terminal(term); | |
| 113 | } | ||
| 114 | |||
| 115 | 1 | Terminal Terminal::openConsole(enumint_t flags) | |
| 116 | { | ||
| 117 | 1 | gate_terminal_t* term = gate_terminal_console_open(flags); | |
| 118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (term == NULL) |
| 119 | { | ||
| 120 | ✗ | GATEXX_RAISE_EXCEPTION(results::Failed, "Cannot open a new console terminal", 0); | |
| 121 | } | ||
| 122 | 1 | return Terminal(term); | |
| 123 | } | ||
| 124 | |||
| 125 | ✗ | Terminal Terminal::createVirtual(uint16_t cols, uint16_t rows, enumint_t flags, | |
| 126 | gate_terminal_read_char_t read_callback, void* read_param, | ||
| 127 | gate_terminal_write_char_t write_callback, void* write_param) | ||
| 128 | { | ||
| 129 | ✗ | gate_terminal_t* term = gate_terminal_virtual_create(cols, rows, flags, | |
| 130 | read_callback, read_param, write_callback, write_param); | ||
| 131 | |||
| 132 | ✗ | if (term == NULL) | |
| 133 | { | ||
| 134 | ✗ | GATEXX_RAISE_EXCEPTION(results::Failed, "Cannot open a new console terminal", 0); | |
| 135 | } | ||
| 136 | ✗ | return Terminal(term); | |
| 137 | } | ||
| 138 | |||
| 139 | } // end of namespace sys | ||
| 140 | } // end of namespace gate | ||
| 141 |