mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
terminal: add new terminal class
This commit is contained in:
parent
b9c95d99e8
commit
7e51194c86
2 changed files with 63 additions and 6 deletions
57
common/include/villas/terminal.hpp
Normal file
57
common/include/villas/terminal.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/** Terminal handling.
|
||||
*
|
||||
* @file
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2018, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @license GNU General Public License (version 3)
|
||||
*
|
||||
* VILLAScommon
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
namespace villas {
|
||||
|
||||
class Terminal {
|
||||
|
||||
protected:
|
||||
static struct winsize window; /**< Size of the terminal window. */
|
||||
|
||||
bool isTty;
|
||||
|
||||
public:
|
||||
Terminal();
|
||||
|
||||
/** Signal handler for TIOCGWINSZ */
|
||||
static void resize(int signal, siginfo_t *sinfo, void *ctx);
|
||||
|
||||
static int getCols()
|
||||
{
|
||||
return window.ws_col;
|
||||
}
|
||||
|
||||
static int getRows()
|
||||
{
|
||||
return window.ws_row;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace villas
|
|
@ -62,8 +62,8 @@ static int table_resize(struct table *t, int width)
|
|||
|
||||
void table_header(struct table *t)
|
||||
{
|
||||
if (t->width != global_log->width)
|
||||
table_resize(t, global_log->width);
|
||||
if (t->width != log_get_width())
|
||||
table_resize(t, log_get_width());
|
||||
|
||||
char *line0 = strf("\b");
|
||||
char *line1 = strf("\b\b" BOX_UD);
|
||||
|
@ -119,8 +119,8 @@ void table_header(struct table *t)
|
|||
|
||||
void table_row(struct table *t, ...)
|
||||
{
|
||||
if (t->width != global_log->width) {
|
||||
table_resize(t, global_log->width);
|
||||
if (t->width != log_get_width()) {
|
||||
table_resize(t, log_get_width());
|
||||
table_header(t);
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ void table_row(struct table *t, ...)
|
|||
|
||||
void table_footer(struct table *t)
|
||||
{
|
||||
if (t->width != global_log->width)
|
||||
table_resize(t, global_log->width);
|
||||
if (t->width != log_get_width())
|
||||
table_resize(t, log_get_width());
|
||||
|
||||
char *line = strf("\b");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue