diff --git a/common/include/villas/terminal.hpp b/common/include/villas/terminal.hpp new file mode 100644 index 000000000..3cf753a08 --- /dev/null +++ b/common/include/villas/terminal.hpp @@ -0,0 +1,57 @@ +/** Terminal handling. + * + * @file + * @author Steffen Vogel + * @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 . + *********************************************************************************/ + +#pragma once + +#include + +#include +#include + +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 diff --git a/common/lib/table.c b/common/lib/table.c index 88a55b6f3..ad0bf6cc0 100644 --- a/common/lib/table.c +++ b/common/lib/table.c @@ -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");