Skip to content
Snippets Groups Projects
Commit f792307b authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

use color in terminal

parent f753aeff
No related branches found
No related tags found
No related merge requests found
...@@ -155,6 +155,42 @@ void Msg::Exit(int level) ...@@ -155,6 +155,42 @@ void Msg::Exit(int level)
exit(_errorCount); exit(_errorCount);
} }
static int streamIsFile(FILE* stream)
{
// the given stream is definately not interactive if it is a regular file
struct stat stream_stat;
if(fstat(fileno(stream), &stream_stat) == 0){
if(stream_stat.st_mode & S_IFREG) return 1;
}
return 0;
}
static int streamIsVT100(FILE* stream)
{
// if running inside emacs the terminal is not VT100
const char* emacs = getenv("EMACS");
if(emacs && *emacs == 't') return 0;
// list of known terminal names (from cmake)
static const char* names[] =
{"Eterm", "ansi", "color-xterm", "con132x25", "con132x30", "con132x43",
"con132x60", "con80x25", "con80x28", "con80x30", "con80x43", "con80x50",
"con80x60", "cons25", "console", "cygwin", "dtterm", "eterm-color", "gnome",
"gnome-256color", "konsole", "konsole-256color", "kterm", "linux", "msys",
"linux-c", "mach-color", "mlterm", "putty", "rxvt", "rxvt-256color",
"rxvt-cygwin", "rxvt-cygwin-native", "rxvt-unicode", "rxvt-unicode-256color",
"screen", "screen-256color", "screen-256color-bce", "screen-bce", "screen-w",
"screen.linux", "vt100", "xterm", "xterm-16color", "xterm-256color",
"xterm-88color", "xterm-color", "xterm-debian", 0};
const char** t = 0;
const char* term = getenv("TERM");
if(term){
for(t = names; *t && strcmp(term, *t) != 0; ++t) {}
}
if(!(t && *t)) return 0;
return 1;
}
void Msg::Fatal(const char *fmt, ...) void Msg::Fatal(const char *fmt, ...)
{ {
_errorCount++; _errorCount++;
...@@ -183,10 +219,14 @@ void Msg::Fatal(const char *fmt, ...) ...@@ -183,10 +219,14 @@ void Msg::Fatal(const char *fmt, ...)
#endif #endif
if(CTX::instance()->terminal){ if(CTX::instance()->terminal){
const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){
c0 = "\33[31m"; c1 = "\33[0m"; // red
}
if(_commSize > 1) if(_commSize > 1)
fprintf(stderr, "Fatal : [On processor %d] %s\n", _commRank, str); fprintf(stderr, "%sFatal : [On processor %d] %s%s\n", c0, _commRank, str, c1);
else else
fprintf(stderr, "Fatal : %s\n", str); fprintf(stderr, "%sFatal : %s%s\n", c0, str, c1);
fflush(stderr); fflush(stderr);
} }
...@@ -219,10 +259,14 @@ void Msg::Error(const char *fmt, ...) ...@@ -219,10 +259,14 @@ void Msg::Error(const char *fmt, ...)
#endif #endif
if(CTX::instance()->terminal){ if(CTX::instance()->terminal){
const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){
c0 = "\33[31m"; c1 = "\33[0m"; // red
}
if(_commSize > 1) if(_commSize > 1)
fprintf(stderr, "Error : [On processor %d] %s\n", _commRank, str); fprintf(stderr, "%sError : [On processor %d] %s%s\n", c0, _commRank, str, c1);
else else
fprintf(stderr, "Error : %s\n", str); fprintf(stderr, "%sError : %s%s\n", c0, str, c1);
fflush(stderr); fflush(stderr);
} }
} }
...@@ -251,7 +295,11 @@ void Msg::Warning(const char *fmt, ...) ...@@ -251,7 +295,11 @@ void Msg::Warning(const char *fmt, ...)
#endif #endif
if(CTX::instance()->terminal){ if(CTX::instance()->terminal){
fprintf(stderr, "Warning : %s\n", str); const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){
c0 = "\33[35m"; c1 = "\33[0m"; // magenta
}
fprintf(stderr, "%sWarning : %s%s\n", c0, str, c1);
fflush(stderr); fflush(stderr);
} }
} }
...@@ -326,7 +374,11 @@ void Msg::Direct(int level, const char *fmt, ...) ...@@ -326,7 +374,11 @@ void Msg::Direct(int level, const char *fmt, ...)
#endif #endif
if(CTX::instance()->terminal){ if(CTX::instance()->terminal){
fprintf(stdout, "%s\n", str); const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){
c0 = "\33[34m"; c1 = "\33[0m"; // blue
}
fprintf(stdout, "%s%s%s\n", c0, str, c1);
fflush(stdout); fflush(stdout);
} }
} }
......
This is Gmsh, an automatic three-dimensional finite element mesh This is Gmsh, an automatic three-dimensional finite element mesh generator with
generator with built-in pre- and post-processing facilities. built-in pre- and post-processing facilities.
Gmsh is distributed under the terms of the GNU General Public License, Gmsh is distributed under the terms of the GNU General Public License, Version 2
Version 2 or later, with an exception to allow for easier linking with or later, with an exception to allow for easier linking with external
external libraries. See doc/LICENSE.txt and doc/CREDITS.txt for more libraries. See doc/LICENSE.txt and doc/CREDITS.txt for more information.
information.
See the doc/ and tutorial/ directories for documentation. The See the doc/ and tutorial/ directories for documentation. The reference manual
reference manual is located in doc/texinfo/. See the demos/ directory is located in doc/texinfo/. See the demos/ directory and the web site
and the web site http://geuz.org/gmsh for additional examples. http://geuz.org/gmsh for additional examples.
Building Gmsh from its source code requires a C++ compiler and CMake Building Gmsh from its source code requires a C++ compiler and CMake
(http://cmake.org). Building the graphical user interface requires (http://cmake.org). Building the graphical user interface requires FLTK 1.1.7
FLTK 1.1.7 or above (http://fltk.org), configured with OpenGL or above (http://fltk.org), configured with OpenGL support. Building the 64 bit
support. Building the 64 bit graphical version on MacOS X requires graphical version on MacOS X requires FLTK 1.3.
FLTK 1.3.
Build Gmsh using CMake's graphical user interface Build Gmsh using CMake's graphical user interface
------------------------------------------------- -------------------------------------------------
* Launch CMake and fill-in the two top input fields (telling where the * Launch CMake and fill-in the two top input fields (telling where the Gmsh
Gmsh source directory is located and where you want the Gmsh binary source directory is located and where you want the Gmsh binary to be created).
to be created).
* Click on "Add entry" and define the variable CMAKE_PREFIX_PATH, of * Click on "Add entry" and define the variable CMAKE_PREFIX_PATH, of type
type "PATH", pointing to the location(s) of any external package(s) "PATH", pointing to the location(s) of any external package(s) (FLTK,
(FLTK, BLAS/LAPACK, etc.) installed in non-standard directories. BLAS/LAPACK, etc.) installed in non-standard directories.
(If you are using our pre-compiled "gmsh dependencies" package (If you are using our pre-compiled "gmsh dependencies" package
(http://geuz.org/gmsh/bin/Windows/gmsh-dep-msvc2008-release.zip) (http://geuz.org/gmsh/bin/Windows/gmsh-dep-msvc2008-release.zip) with Visual
with Visual Studio on Windows simply point CMAKE_PREFIX_PATH to the Studio on Windows simply point CMAKE_PREFIX_PATH to the "gmsh-dep" directory.)
"gmsh-dep" directory.)
* Click on "Configure" and choose your compiler (e.g. Visual Studio). * Click on "Configure" and choose your compiler (e.g. Visual Studio).
* Optionally change some configuration options (re-run "Configure" * Optionally change some configuration options (re-run "Configure" every time
every time you change some options). you change some options).
* Once you are happy with all the configuration options, click on * Once you are happy with all the configuration options, click on "Generate".
"Generate".
* Go to the build directory and build Gmsh using your chosen compiler. * Go to the build directory and build Gmsh using your chosen compiler.
(With Visual Studio double-click on "gmsh.sln". If you are using our (With Visual Studio double-click on "gmsh.sln". If you are using our
pre-compiled "gmsh dependencies" package you must use the "Release" pre-compiled "gmsh dependencies" package you must use the "Release" or
or "RelWithDebInfo" build type.) "RelWithDebInfo" build type.)
Build Gmsh from the command line Build Gmsh from the command line
-------------------------------- --------------------------------
* Create a build directory, for example as a subdirectory of Gmsh's * Create a build directory, for example as a subdirectory of Gmsh's source
source directory: directory:
mkdir build mkdir build
* Run cmake from within the build directory, pointing to Gmsh's * Run cmake from within the build directory, pointing to Gmsh's source
source directory: directory:
cd build cd build
cmake .. cmake ..
...@@ -67,18 +62,17 @@ Build Gmsh from the command line ...@@ -67,18 +62,17 @@ Build Gmsh from the command line
make make
make install make install
* To change build options you can use "ccmake" instead of "cmake", * To change build options you can use "ccmake" instead of "cmake", e.g.:
e.g.:
ccmake .. ccmake ..
or you can specify options directly on the command line. For or you can specify options directly on the command line. For example, you can
example, you can use use
cmake -DCMAKE_PREFIX_PATH=/opt/local .. cmake -DCMAKE_PREFIX_PATH=/opt/local ..
to specify the location of external packages installed in to specify the location of external packages installed in non-standard
non-standard directories. You can use directories. You can use
cmake -DCMAKE_INSTALL_PREFIX=/opt cmake -DCMAKE_INSTALL_PREFIX=/opt
...@@ -88,17 +82,17 @@ Build Gmsh from the command line ...@@ -88,17 +82,17 @@ Build Gmsh from the command line
to build a version of Gmsh without the FLTK graphical interface. to build a version of Gmsh without the FLTK graphical interface.
* You can keep multiple builds with different build options at the * You can keep multiple builds with different build options at the same
same time. For example, you could configure a debug graphical build time. For example, you could configure a debug graphical build in a "bin"
in a "bin" subdirectory with subdirectory with
cd bin cd bin
cmake -DCMAKE_BUILD_TYPE=Debug .. cmake -DCMAKE_BUILD_TYPE=Debug ..
make make
make install make install
and static and dynamic non-graphical release libraries in a "lib" and static and dynamic non-graphical release libraries in a "lib" subdirectory
subdirectory with with
cd lib cd lib
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_FLTK=0 -DENABLE_OCC=0 .. cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_FLTK=0 -DENABLE_OCC=0 ..
......
This is Gmsh, an automatic three-dimensional finite element mesh This is Gmsh, an automatic three-dimensional finite element mesh generator with
generator with built-in pre- and post-processing facilities. built-in pre- and post-processing facilities.
Gmsh is distributed under the terms of the GNU General Public Gmsh is distributed under the terms of the GNU General Public License. See the
License. See the LICENSE.txt and CREDITS.txt files for more LICENSE.txt and CREDITS.txt files for more information.
information.
The tutorial/ directory contains the examples from the tutorial The tutorial/ directory contains the examples from the tutorial chapter in the
chapter in the reference manual (http://geuz.org/gmsh/doc/texinfo/). reference manual (http://geuz.org/gmsh/doc/texinfo/). The demos/ directory
The demos/ directory contains additional examples. contains additional examples.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment