1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/common/include/villas/terminal.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
841 B
C++
Raw Permalink Normal View History

/* Terminal handling.
2018-10-19 16:32:10 +02:00
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
2018-10-19 16:32:10 +02:00
#pragma once
#include <cstdio>
#include <signal.h>
#include <sys/ioctl.h>
namespace villas {
class Terminal {
protected:
struct winsize window; // Size of the terminal window.
2018-10-19 16:32:10 +02:00
bool isTty;
2018-10-19 16:32:10 +02:00
static class Terminal *current;
2019-01-22 16:02:27 +01:00
2018-10-19 16:32:10 +02:00
public:
Terminal();
2018-10-19 16:32:10 +02:00
// Signal handler for TIOCGWINSZ
static void resize(int signal, siginfo_t *sinfo, void *ctx);
2018-10-19 16:32:10 +02:00
static int getCols() {
if (!current)
current = new Terminal();
2019-01-22 16:02:27 +01:00
return current->window.ws_col;
}
2018-10-19 16:32:10 +02:00
static int getRows() {
if (!current)
current = new Terminal();
2019-01-22 16:02:27 +01:00
return current->window.ws_row;
}
2018-10-19 16:32:10 +02:00
};
} // namespace villas