"Fossies" - the Fresh Open Source Software Archive

Member "monit-5.28.0/src/terminal/TextBox.h" (28 Mar 2021, 2837 Bytes) of package /linux/privat/monit-5.28.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "TextBox.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Tildeslash Ltd. All rights reserved.
    3  *
    4  * This program is free software: you can redistribute it and/or modify
    5  * it under the terms of the GNU Affero General Public License version 3.
    6  *
    7  * This program is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  * GNU Affero General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Affero General Public License
   13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   14  *
   15  * In addition, as a special exception, the copyright holders give
   16  * permission to link the code of portions of this program with the
   17  * OpenSSL library under certain conditions as described in each
   18  * individual source file, and distribute linked combinations
   19  * including the two.
   20  *
   21  * You must obey the GNU Affero General Public License in all respects
   22  * for all of the code used other than OpenSSL.  
   23  */
   24 
   25 
   26 #ifndef BOX_INCLUDED
   27 #define BOX_INCLUDED
   28 
   29 
   30 /**
   31  * Class for terminal table output.
   32  *
   33  * @author http://www.tildeslash.com/
   34  * @see http://www.mmonit.com/
   35  * @file
   36  */
   37 
   38 
   39 typedef enum {
   40         TextBoxAlign_Left = 0,
   41         TextBoxAlign_Right
   42 } __attribute__((__packed__)) TextBoxAlign_T;
   43 
   44 
   45 typedef struct TexBoxColumn_T {
   46         const char *name;
   47         char *value;
   48         // Options
   49         int width;
   50         bool wrap;
   51         TextBoxAlign_T align;
   52         // Internal
   53         int _colorLength;
   54         unsigned long _valueLength;
   55         unsigned long _cursor;
   56         char _color[8];
   57 } TextBoxColumn_T;
   58 
   59 
   60 #define T TextBox_T
   61 typedef struct T *T;
   62 
   63 
   64 /**
   65  * Constructs a terminal table object.
   66  * @param b The output stringbuffer
   67  * @param columnsCount Count of table columns
   68  * @param columns Array of BoxColumn_T columns specification
   69  * @param printHeader true if the header should be printed otherwise false
   70  * @return A new terminal table object
   71  */
   72 T TextBox_new(StringBuffer_T b, int columnsCount, TextBoxColumn_T *columns, bool printHeader); //FIXME: when OutputStream is added, use it instead of StringBuffer
   73 
   74 
   75 /**
   76  * Close and destroy a Box object and free allocated resources
   77  * @param t a Box object reference
   78  */
   79 void TextBox_free(T *t);
   80 
   81 
   82 /**
   83  * Set a table column value
   84  * @param t The terminal table object
   85  * @param index Column index
   86  * @param format A format string with optional var args
   87  */
   88 void TextBox_setColumn(T t, unsigned int index, const char *format, ...) __attribute__((format (printf, 3, 4)));
   89 
   90 
   91 /**
   92  * Print a table row
   93  * @param t The terminal table object
   94  */
   95 void TextBox_printRow(T t);
   96 
   97 
   98 /**
   99  * Strip the UTF-8 table control characters in the string.
  100  * @param s The string to strip
  101  * @return A pointer to s
  102  */
  103 char *TextBox_strip(char *s);
  104 
  105 
  106 #undef T
  107 #endif
  108