diff --git a/ChangeLog b/ChangeLog index eb67b3a2..1dc98661 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ -2020-02-08 Markus Gans +2020-02-09 Markus Gans + * Adding a tty check for stdin * An application structure diagram was added to the document of the first steps diff --git a/doc/final-cut-application-structure.svg b/doc/final-cut-application-structure.svg index e1cec8b7..e992dacd 100644 --- a/doc/final-cut-application-structure.svg +++ b/doc/final-cut-application-structure.svg @@ -12,7 +12,7 @@ width="101.5mm" version="1.1" id="svg61" - sodipodi:docname="application-structure.svg" + sodipodi:docname="final-cut-application-structure.svg" inkscape:version="0.92.1 r15371"> + inkscape:current-layer="g23" /> @@ -42,7 +42,7 @@ image/svg+xml - + @@ -70,7 +70,7 @@ id="g59"> + style="fill:#f6f8fa;fill-opacity:1;stroke-width:0.42300001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5" /> application structure diff --git a/src/fterm.cpp b/src/fterm.cpp index ad796b69..9bc8a4b3 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -25,6 +25,7 @@ #include #include +#include "final/fapplication.h" #include "final/fc.h" #include "final/fcharmap.h" #include "final/fcolorpalette.h" @@ -2211,24 +2212,9 @@ void FTerm::init (bool disable_alt_screen) allocationValues(); init_global_values(disable_alt_screen); - // Initialize termios - FTermios::init(); - - // 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()); + // Initialize the terminal + if ( ! init_terminal() ) + return; // Set maximum number of colors for detected terminals init_fixed_max_color(); @@ -2312,6 +2298,49 @@ void FTerm::init (bool disable_alt_screen) 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() { diff --git a/src/ftermios.cpp b/src/ftermios.cpp index 011bc157..fc28cda2 100644 --- a/src/ftermios.cpp +++ b/src/ftermios.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -72,7 +72,10 @@ void FTermios::init() termios FTermios::getTTY() { struct termios t{}; - tcgetattr (stdin_no, &t); + + if ( tcgetattr(stdin_no, &t) == -1 ) + std::runtime_error("Cannot find tty"); + return t; } @@ -86,7 +89,14 @@ void FTermios::setTTY (const termios& t) void FTermios::storeTTYsettings() { // Store termios settings - term_init = getTTY(); + try + { + term_init = getTTY(); + } + catch (...) + { + throw std::current_exception(); + } } //---------------------------------------------------------------------- diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 0285a224..47b42bd8 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -343,6 +343,7 @@ class FTerm final void allocationValues(); void deallocationValues(); void init (bool); + bool init_terminal(); void initOSspecifics(); void initTermspecifics(); void initBaudRate();