Adding a tty check for stdin
This commit is contained in:
parent
07a29910b7
commit
dd625e0822
|
@ -1,4 +1,5 @@
|
||||||
2020-02-08 Markus Gans <guru.mail@muenster.de>
|
2020-02-09 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Adding a tty check for stdin
|
||||||
* An application structure diagram was added to the document
|
* An application structure diagram was added to the document
|
||||||
of the first steps
|
of the first steps
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
width="101.5mm"
|
width="101.5mm"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="svg61"
|
id="svg61"
|
||||||
sodipodi:docname="application-structure.svg"
|
sodipodi:docname="final-cut-application-structure.svg"
|
||||||
inkscape:version="0.92.1 r15371">
|
inkscape:version="0.92.1 r15371">
|
||||||
<sodipodi:namedview
|
<sodipodi:namedview
|
||||||
pagecolor="#ffffff"
|
pagecolor="#ffffff"
|
||||||
|
@ -27,13 +27,13 @@
|
||||||
inkscape:window-height="1984"
|
inkscape:window-height="1984"
|
||||||
id="namedview35"
|
id="namedview35"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
inkscape:zoom="4.0861905"
|
inkscape:zoom="2.8893731"
|
||||||
inkscape:cx="81.193565"
|
inkscape:cx="331.13905"
|
||||||
inkscape:cy="171.2161"
|
inkscape:cy="54.29145"
|
||||||
inkscape:window-x="0"
|
inkscape:window-x="0"
|
||||||
inkscape:window-y="55"
|
inkscape:window-y="55"
|
||||||
inkscape:window-maximized="1"
|
inkscape:window-maximized="1"
|
||||||
inkscape:current-layer="g59" />
|
inkscape:current-layer="g23" />
|
||||||
<metadata
|
<metadata
|
||||||
id="metadata67">
|
id="metadata67">
|
||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:type
|
<dc:type
|
||||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
id="g59">
|
id="g59">
|
||||||
<g
|
<g
|
||||||
id="g23"
|
id="g23"
|
||||||
style="stroke:#000000"
|
style="stroke:#000000;fill:none"
|
||||||
transform="translate(-0.00447221)">
|
transform="translate(-0.00447221)">
|
||||||
<rect
|
<rect
|
||||||
height="74.20752"
|
height="74.20752"
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
x="0.2115"
|
x="0.2115"
|
||||||
y="222.58098"
|
y="222.58098"
|
||||||
id="rect7"
|
id="rect7"
|
||||||
style="fill:#f0f0f0;fill-opacity:1;stroke-width:0.42300001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5" />
|
style="fill:#f6f8fa;fill-opacity:1;stroke-width:0.42300001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5" />
|
||||||
<path
|
<path
|
||||||
d="M 7.8726193,233.11525 H 66.187848"
|
d="M 7.8726193,233.11525 H 66.187848"
|
||||||
id="path9"
|
id="path9"
|
||||||
|
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
@ -29,9 +29,22 @@ Table of Contents
|
||||||
Basic functions
|
Basic functions
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
FINAL CUT is a library for creating text-based terminal applications. It runs on several Unix-like platforms. The release of FINAL CUT is licensed under the terms of the GNU Lesser General Public License v3.0 ([GNU LGPL v3](https://www.gnu.org/licenses/lgpl-3.0-standalone.html)), which allows flexible licensing of applications. FINAL CUT has a [C++](https://en.wikipedia.org/wiki/C%2B%2B)-based object-oriented architecture for creating fast and lean programs.
|
FINAL CUT is a library for creating text-based terminal applications.
|
||||||
|
It runs on several Unix-like platforms. The release of FINAL CUT is
|
||||||
|
licensed under the terms of the GNU Lesser General Public License v3.0
|
||||||
|
([GNU LGPL v3](https://www.gnu.org/licenses/lgpl-3.0-standalone.html)),
|
||||||
|
which allows flexible licensing of applications. FINAL CUT was written
|
||||||
|
in the programming language [C++](https://en.wikipedia.org/wiki/C%2B%2B).
|
||||||
|
The object-oriented design allows the creation of fast and lean programs.
|
||||||
|
|
||||||
FINAL CUT is a [widget toolkit](http://en.wikipedia.org/wiki/Widget_toolkit). A user interface created consists of several widgets. FINAL CUT draws widgets on virtual windows and then mapped them on a virtual terminal. It uses the terminal capabilities from the [Termcap library](https://en.wikipedia.org/wiki/Termcap) to display the character matrix of the virtual terminal on the screen or a terminal emulator. It uses various optimization methods to improve the speed of the display.
|
FINAL CUT is a [widget toolkit](http://en.wikipedia.org/wiki/Widget_toolkit).
|
||||||
|
A user interface usually consists of several
|
||||||
|
[widgets](https://en.wikipedia.org/wiki/Software_widget). FINAL CUT
|
||||||
|
draws widgets on virtual windows and then mapped them on a virtual
|
||||||
|
terminal. It uses the terminal capabilities from the
|
||||||
|
[Termcap library](https://en.wikipedia.org/wiki/Termcap) to display
|
||||||
|
the character matrix of the virtual terminal on the screen or a terminal
|
||||||
|
emulator. It uses various optimization methods to improve the drawing speed.
|
||||||
|
|
||||||
<figure class="image">
|
<figure class="image">
|
||||||
<img src="final-cut-application-structure.svg" alt="application structure">
|
<img src="final-cut-application-structure.svg" alt="application structure">
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "final/fapplication.h"
|
||||||
#include "final/fc.h"
|
#include "final/fc.h"
|
||||||
#include "final/fcharmap.h"
|
#include "final/fcharmap.h"
|
||||||
#include "final/fcolorpalette.h"
|
#include "final/fcolorpalette.h"
|
||||||
|
@ -2211,24 +2212,9 @@ void FTerm::init (bool disable_alt_screen)
|
||||||
allocationValues();
|
allocationValues();
|
||||||
init_global_values(disable_alt_screen);
|
init_global_values(disable_alt_screen);
|
||||||
|
|
||||||
// Initialize termios
|
// Initialize the terminal
|
||||||
FTermios::init();
|
if ( ! init_terminal() )
|
||||||
|
return;
|
||||||
// Get pathname of the terminal device
|
|
||||||
init_terminal_device_path();
|
|
||||||
|
|
||||||
// Initialize Linux or *BSD console
|
|
||||||
initOSspecifics();
|
|
||||||
|
|
||||||
// Save termios settings
|
|
||||||
FTermios::storeTTYsettings();
|
|
||||||
|
|
||||||
// Get output baud rate
|
|
||||||
initBaudRate();
|
|
||||||
|
|
||||||
// Terminal detection
|
|
||||||
term_detection->detect();
|
|
||||||
setTermType (term_detection->getTermType());
|
|
||||||
|
|
||||||
// Set maximum number of colors for detected terminals
|
// Set maximum number of colors for detected terminals
|
||||||
init_fixed_max_color();
|
init_fixed_max_color();
|
||||||
|
@ -2312,6 +2298,49 @@ void FTerm::init (bool disable_alt_screen)
|
||||||
term_initialized = true;
|
term_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
bool FTerm::init_terminal()
|
||||||
|
{
|
||||||
|
// Initialize termios
|
||||||
|
FTermios::init();
|
||||||
|
|
||||||
|
// Check if stdin is a tty
|
||||||
|
if ( ! fsys->isTTY(FTermios::getStdIn()) )
|
||||||
|
{
|
||||||
|
data->setExitMessage("FTerm: Standard input is not a TTY.");
|
||||||
|
FApplication::exit(EXIT_FAILURE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get pathname of the terminal device
|
||||||
|
init_terminal_device_path();
|
||||||
|
|
||||||
|
// Initialize Linux or *BSD console
|
||||||
|
initOSspecifics();
|
||||||
|
|
||||||
|
// Save termios settings
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FTermios::storeTTYsettings();
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& ex)
|
||||||
|
{
|
||||||
|
FString msg = "FTerm: " + FString(ex.what());
|
||||||
|
data->setExitMessage(msg);
|
||||||
|
FApplication::exit(EXIT_FAILURE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get output baud rate
|
||||||
|
initBaudRate();
|
||||||
|
|
||||||
|
// Terminal detection
|
||||||
|
term_detection->detect();
|
||||||
|
setTermType (term_detection->getTermType());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FTerm::initOSspecifics()
|
void FTerm::initOSspecifics()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* *
|
* *
|
||||||
* This file is part of the Final Cut widget toolkit *
|
* This file is part of the Final Cut widget toolkit *
|
||||||
* *
|
* *
|
||||||
* Copyright 2018-2019 Markus Gans *
|
* Copyright 2018-2020 Markus Gans *
|
||||||
* *
|
* *
|
||||||
* The Final Cut is free software; you can redistribute it and/or *
|
* The Final Cut is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU Lesser General Public License *
|
* modify it under the terms of the GNU Lesser General Public License *
|
||||||
|
@ -72,7 +72,10 @@ void FTermios::init()
|
||||||
termios FTermios::getTTY()
|
termios FTermios::getTTY()
|
||||||
{
|
{
|
||||||
struct termios t{};
|
struct termios t{};
|
||||||
tcgetattr (stdin_no, &t);
|
|
||||||
|
if ( tcgetattr(stdin_no, &t) == -1 )
|
||||||
|
std::runtime_error("Cannot find tty");
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +89,14 @@ void FTermios::setTTY (const termios& t)
|
||||||
void FTermios::storeTTYsettings()
|
void FTermios::storeTTYsettings()
|
||||||
{
|
{
|
||||||
// Store termios settings
|
// Store termios settings
|
||||||
|
try
|
||||||
|
{
|
||||||
term_init = getTTY();
|
term_init = getTTY();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
throw std::current_exception();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -343,6 +343,7 @@ class FTerm final
|
||||||
void allocationValues();
|
void allocationValues();
|
||||||
void deallocationValues();
|
void deallocationValues();
|
||||||
void init (bool);
|
void init (bool);
|
||||||
|
bool init_terminal();
|
||||||
void initOSspecifics();
|
void initOSspecifics();
|
||||||
void initTermspecifics();
|
void initTermspecifics();
|
||||||
void initBaudRate();
|
void initBaudRate();
|
||||||
|
|
Loading…
Reference in New Issue