Skip to content

Border styles (C API)

Seleznev Anton edited this page Nov 3, 2018 · 10 revisions

libfort has a number of builtin border styles. To change border style of libfort tables one can use ft_set_default_border_style, ft_set_border_style functions:

/* Change border style of all libfort tables that will be created */
int ft_set_default_border_style(const struct ft_border_style *style);
/* Change border style of a particular table */
int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style);

Here is a simple example of creating table and setting border style:

ft_table_t *table = ft_create_table();   
/* Set border style */
ft_set_border_style(table, FT_BASIC_STYLE);
                                       
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);  
                                                                                
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);   
ft_write_ln(table, "Rank", "Title", "Year", "Rating");                          
                                                                                
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");             
ft_write_ln(table, "2", "12 Angry Men", "1957", "8.8");                         
ft_write_ln(table, "3", "It's a Wonderful Life", "1946", "8.6");                
ft_add_separator(table);                                                        
ft_write_ln(table, "4", "2001: A Space Odyssey", "1968", "8.5");                
ft_write_ln(table, "5", "Blade Runner", "1982", "8.1");   

printf("%s\n", ft_to_string(table));
ft_destroy_table(table);                   

Output:

+------+--------------------------+------+--------+
| Rank | Title                    | Year | Rating |
+------+--------------------------+------+--------+
|  1   | The Shawshank Redemption | 1994 | 9.5    |
|  2   | 12 Angry Men             | 1957 | 8.8    |
|  3   | It's a Wonderful Life    | 1946 | 8.6    |
+------+--------------------------+------+--------+
|  4   | 2001: A Space Odyssey    | 1968 | 8.5    |
|  5   | Blade Runner             | 1982 | 8.1    |
+------+--------------------------+------+--------+

FT_BASIC_STYLE

+------+--------------------------+------+--------+
| Rank | Title                    | Year | Rating |
+------+--------------------------+------+--------+
|  1   | The Shawshank Redemption | 1994 | 9.5    |
|  2   | 12 Angry Men             | 1957 | 8.8    |
|  3   | It's a Wonderful Life    | 1946 | 8.6    |
+------+--------------------------+------+--------+
|  4   | 2001: A Space Odyssey    | 1968 | 8.5    |
|  5   | Blade Runner             | 1982 | 8.1    |
+------+--------------------------+------+--------+

FT_BASIC2_STYLE

+------+--------------------------+------+--------+
| Rank | Title                    | Year | Rating |
+------+--------------------------+------+--------+
|  1   | The Shawshank Redemption | 1994 | 9.5    |
+------+--------------------------+------+--------+
|  2   | 12 Angry Men             | 1957 | 8.8    |
+------+--------------------------+------+--------+
|  3   | It's a Wonderful Life    | 1946 | 8.6    |
+------+--------------------------+------+--------+
|  4   | 2001: A Space Odyssey    | 1968 | 8.5    |
+------+--------------------------+------+--------+
|  5   | Blade Runner             | 1982 | 8.1    |
+------+--------------------------+------+--------+

FT_SIMPLE_STYLE

                                                   
  Rank   Title                      Year   Rating  
 ------ -------------------------- ------ -------- 
   1     The Shawshank Redemption   1994   9.5     
   2     12 Angry Men               1957   8.8     
   3     It's a Wonderful Life      1946   8.6     
 ------ -------------------------- ------ -------- 
   4     2001: A Space Odyssey      1968   8.5     
   5     Blade Runner               1982   8.1     
                                                   

FT_PLAIN_STYLE

 ------------------------------------------------- 
  Rank   Title                      Year   Rating  
 ------------------------------------------------- 
   1     The Shawshank Redemption   1994   9.5     
   2     12 Angry Men               1957   8.8     
   3     It's a Wonderful Life      1946   8.6     
 ------------------------------------------------- 
   4     2001: A Space Odyssey      1968   8.5     
   5     Blade Runner               1982   8.1      

FT_DOT_STYLE

...................................................
: Rank : Title                    : Year : Rating :
:......:..........................:......:........:
:  1   : The Shawshank Redemption : 1994 : 9.5    :
:  2   : 12 Angry Men             : 1957 : 8.8    :
:  3   : It's a Wonderful Life    : 1946 : 8.6    :
:......:..........................:......:........:
:  4   : 2001: A Space Odyssey    : 1968 : 8.5    :
:  5   : Blade Runner             : 1982 : 8.1    :
:......:..........................:......:........:

FT_EMPTY_STYLE

  Rank   Title                      Year   Rating  
   1     The Shawshank Redemption   1994   9.5     
   2     12 Angry Men               1957   8.8     
   3     It's a Wonderful Life      1946   8.6     
                                                   
   4     2001: A Space Odyssey      1968   8.5     
   5     Blade Runner               1982   8.1     
                                                  

FT_SOLID_STYLE

┌──────┬──────────────────────────┬──────┬────────┐
│ Rank │ Title                    │ Year │ Rating │
├──────┼──────────────────────────┼──────┼────────┤
│  1   │ The Shawshank Redemption │ 1994 │ 9.5    │
│  2   │ 12 Angry Men             │ 1957 │ 8.8    │
│  3   │ It's a Wonderful Life    │ 1946 │ 8.6    │
├──────┼──────────────────────────┼──────┼────────┤
│  4   │ 2001: A Space Odyssey    │ 1968 │ 8.5    │
│  5   │ Blade Runner             │ 1982 │ 8.1    │
└──────┴──────────────────────────┴──────┴────────╯ 

FT_SOLID_ROUND_STYLE

╭──────┬──────────────────────────┬──────┬────────╮
│ Rank │ Title                    │ Year │ Rating │
├──────┼──────────────────────────┼──────┼────────┤
│  1   │ The Shawshank Redemption │ 1994 │ 9.5    │
│  2   │ 12 Angry Men             │ 1957 │ 8.8    │
│  3   │ It's a Wonderful Life    │ 1946 │ 8.6    │
├──────┼──────────────────────────┼──────┼────────┤
│  4   │ 2001: A Space Odyssey    │ 1968 │ 8.5    │
│  5   │ Blade Runner             │ 1982 │ 8.1    │
╰──────┴──────────────────────────┴──────┴────────╯

FT_DOUBLE_STYLE

╔══════╦══════════════════════════╦══════╦════════╗
║ Rank ║ Title                    ║ Year ║ Rating ║
╠══════╬══════════════════════════╬══════╬════════╣
║  1   ║ The Shawshank Redemption ║ 1994 ║ 9.5    ║
║  2   ║ 12 Angry Men             ║ 1957 ║ 8.8    ║
║  3   ║ It's a Wonderful Life    ║ 1946 ║ 8.6    ║
╠══════╬══════════════════════════╬══════╬════════╣
║  4   ║ 2001: A Space Odyssey    ║ 1968 ║ 8.5    ║
║  5   ║ Blade Runner             ║ 1982 ║ 8.1    ║
╚══════╩══════════════════════════╩══════╩════════╝

FT_DOUBLE2_STYLE

╔══════╤══════════════════════════╤══════╤════════╗
║ Rank │ Title                    │ Year │ Rating ║
╠══════╪══════════════════════════╪══════╪════════╣
║  1   │ The Shawshank Redemption │ 1994 │ 9.5    ║
╟──────┼──────────────────────────┼──────┼────────╢
║  2   │ 12 Angry Men             │ 1957 │ 8.8    ║
╟──────┼──────────────────────────┼──────┼────────╢
║  3   │ It's a Wonderful Life    │ 1946 │ 8.6    ║
╠══════╪══════════════════════════╪══════╪════════╣
║  4   │ 2001: A Space Odyssey    │ 1968 │ 8.5    ║
╟──────┼──────────────────────────┼──────┼────────╢
║  5   │ Blade Runner             │ 1982 │ 8.1    ║
╚══════╧══════════════════════════╧══════╧════════╝

FT_BOLD_STYLE

┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━┓
┃ Rank ┃ Title                    ┃ Year ┃ Rating ┃
┣━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━╋━━━━━━━━┫
┃  1   ┃ The Shawshank Redemption ┃ 1994 ┃ 9.5    ┃
┃  2   ┃ 12 Angry Men             ┃ 1957 ┃ 8.8    ┃
┃  3   ┃ It's a Wonderful Life    ┃ 1946 ┃ 8.6    ┃
┣━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━╋━━━━━━━━┫
┃  4   ┃ 2001: A Space Odyssey    ┃ 1968 ┃ 8.5    ┃
┃  5   ┃ Blade Runner             ┃ 1982 ┃ 8.1    ┃
┗━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━┻━━━━━━━━┛

FT_BOLD2_STYLE

┏━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━┯━━━━━━━━┓
┃ Rank │ Title                    │ Year │ Rating ┃
┣━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━┿━━━━━━━━┫
┃  1   │ The Shawshank Redemption │ 1994 │ 9.5    ┃
┠──────┼──────────────────────────┼──────┼────────┨
┃  2   │ 12 Angry Men             │ 1957 │ 8.8    ┃
┠──────┼──────────────────────────┼──────┼────────┨
┃  3   │ It's a Wonderful Life    │ 1946 │ 8.6    ┃
┣━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━┿━━━━━━━━┫
┃  4   │ 2001: A Space Odyssey    │ 1968 │ 8.5    ┃
┠──────┼──────────────────────────┼──────┼────────┨
┃  5   │ Blade Runner             │ 1982 │ 8.1    ┃
┗━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┷━━━━━━━━┛

FT_FRAME_STYLE

▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
▌ Rank ┃ Title                    ┃ Year ┃ Rating ▐
▌━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━╋━━━━━━━━▐
▌  1   ┃ The Shawshank Redemption ┃ 1994 ┃ 9.5    ▐
▌  2   ┃ 12 Angry Men             ┃ 1957 ┃ 8.8    ▐
▌  3   ┃ It's a Wonderful Life    ┃ 1946 ┃ 8.6    ▐
▌━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━╋━━━━━━━━▐
▌  4   ┃ 2001: A Space Odyssey    ┃ 1968 ┃ 8.5    ▐
▌  5   ┃ Blade Runner             ┃ 1982 ┃ 8.1    ▐
▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟