2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* termcap.cpp - Show the used termcap variables *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-03-26 20:40:04 +02:00
|
|
|
|
|
|
|
#include <iomanip>
|
2017-04-02 13:30:23 +02:00
|
|
|
#include <iostream>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2019-04-26 21:06:04 +02:00
|
|
|
namespace fc = finalcut::fc;
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2018-01-17 21:11:26 +01:00
|
|
|
// Function prototype
|
2018-02-19 01:36:38 +01:00
|
|
|
void tcapBoolean (const std::string&, bool);
|
2017-04-08 02:40:22 +02:00
|
|
|
void tcapNumeric (const std::string&, int);
|
2017-12-25 21:17:08 +01:00
|
|
|
void tcapString (const std::string&, const char[]);
|
2018-09-20 23:59:01 +02:00
|
|
|
void debug (finalcut::FApplication&);
|
2017-12-21 00:25:58 +01:00
|
|
|
void booleans();
|
|
|
|
void numeric();
|
2019-05-27 00:50:11 +02:00
|
|
|
void string();
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// struct data
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct data
|
2018-01-17 21:11:26 +01:00
|
|
|
{
|
2019-09-04 23:57:31 +02:00
|
|
|
struct alignas(alignof(std::string)) termcap_string
|
2018-10-03 22:23:55 +02:00
|
|
|
{
|
|
|
|
const std::string name;
|
2019-04-26 21:06:04 +02:00
|
|
|
const fc::termcaps cap;
|
2018-10-03 22:23:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static termcap_string strings[];
|
2018-01-17 21:11:26 +01:00
|
|
|
};
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// struct data - string data array
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
data::termcap_string data::strings[] =
|
2018-01-17 21:11:26 +01:00
|
|
|
{
|
2019-04-26 21:06:04 +02:00
|
|
|
{ "t_bell", fc::t_bell },
|
|
|
|
{ "t_erase_chars", fc::t_erase_chars },
|
|
|
|
{ "t_clear_screen", fc::t_clear_screen },
|
|
|
|
{ "t_clr_eos", fc::t_clr_eos },
|
|
|
|
{ "t_clr_eol", fc::t_clr_eol },
|
|
|
|
{ "t_clr_bol", fc::t_clr_bol },
|
|
|
|
{ "t_cursor_home", fc::t_cursor_home },
|
|
|
|
{ "t_cursor_to_ll", fc::t_cursor_to_ll },
|
|
|
|
{ "t_carriage_return", fc::t_carriage_return },
|
|
|
|
{ "t_tab", fc::t_tab },
|
|
|
|
{ "t_back_tab", fc::t_back_tab },
|
|
|
|
{ "t_insert_padding", fc::t_insert_padding },
|
|
|
|
{ "t_insert_character", fc::t_insert_character },
|
|
|
|
{ "t_parm_ich", fc::t_parm_ich },
|
|
|
|
{ "t_repeat_char", fc::t_repeat_char },
|
|
|
|
{ "t_initialize_color", fc::t_initialize_color },
|
|
|
|
{ "t_initialize_pair", fc::t_initialize_pair },
|
|
|
|
{ "t_set_a_foreground", fc::t_set_a_foreground },
|
|
|
|
{ "t_set_a_background", fc::t_set_a_background },
|
|
|
|
{ "t_set_foreground", fc::t_set_foreground },
|
|
|
|
{ "t_set_background", fc::t_set_background },
|
|
|
|
{ "t_set_color_pair", fc::t_set_color_pair },
|
|
|
|
{ "t_orig_pair", fc::t_orig_pair },
|
|
|
|
{ "t_orig_colors", fc::t_orig_colors },
|
|
|
|
{ "t_no_color_video", fc::t_no_color_video },
|
|
|
|
{ "t_cursor_address", fc::t_cursor_address },
|
|
|
|
{ "t_column_address", fc::t_column_address },
|
|
|
|
{ "t_row_address", fc::t_row_address },
|
|
|
|
{ "t_cursor_visible", fc::t_cursor_visible },
|
|
|
|
{ "t_cursor_invisible", fc::t_cursor_invisible },
|
|
|
|
{ "t_cursor_normal", fc::t_cursor_normal },
|
|
|
|
{ "t_cursor_up", fc::t_cursor_up },
|
|
|
|
{ "t_cursor_down", fc::t_cursor_down },
|
|
|
|
{ "t_cursor_left", fc::t_cursor_left },
|
|
|
|
{ "t_cursor_right", fc::t_cursor_right },
|
|
|
|
{ "t_parm_up_cursor", fc::t_parm_up_cursor },
|
|
|
|
{ "t_parm_down_cursor", fc::t_parm_down_cursor },
|
|
|
|
{ "t_parm_left_cursor", fc::t_parm_left_cursor },
|
|
|
|
{ "t_parm_right_cursor", fc::t_parm_right_cursor },
|
|
|
|
{ "t_save_cursor", fc::t_save_cursor },
|
|
|
|
{ "t_restore_cursor", fc::t_restore_cursor },
|
|
|
|
{ "t_scroll_forward", fc::t_scroll_forward },
|
|
|
|
{ "t_scroll_reverse", fc::t_scroll_reverse },
|
|
|
|
{ "t_enter_ca_mode", fc::t_enter_ca_mode },
|
|
|
|
{ "t_exit_ca_mode", fc::t_exit_ca_mode },
|
|
|
|
{ "t_enable_acs", fc::t_enable_acs },
|
|
|
|
{ "t_enter_bold_mode", fc::t_enter_bold_mode },
|
|
|
|
{ "t_exit_bold_mode", fc::t_exit_bold_mode },
|
|
|
|
{ "t_enter_dim_mode", fc::t_enter_dim_mode },
|
|
|
|
{ "t_exit_dim_mode", fc::t_exit_dim_mode },
|
|
|
|
{ "t_enter_italics_mode", fc::t_enter_italics_mode },
|
|
|
|
{ "t_exit_italics_mode", fc::t_exit_italics_mode },
|
|
|
|
{ "t_enter_underline_mode", fc::t_enter_underline_mode },
|
|
|
|
{ "t_exit_underline_mode", fc::t_exit_underline_mode },
|
|
|
|
{ "t_enter_blink_mode", fc::t_enter_blink_mode },
|
|
|
|
{ "t_exit_blink_mode", fc::t_exit_blink_mode },
|
|
|
|
{ "t_enter_reverse_mode", fc::t_enter_reverse_mode },
|
|
|
|
{ "t_exit_reverse_mode", fc::t_exit_reverse_mode },
|
|
|
|
{ "t_enter_standout_mode", fc::t_enter_standout_mode },
|
|
|
|
{ "t_exit_standout_mode", fc::t_exit_standout_mode },
|
|
|
|
{ "t_enter_secure_mode", fc::t_enter_secure_mode },
|
|
|
|
{ "t_exit_secure_mode", fc::t_exit_secure_mode },
|
|
|
|
{ "t_enter_protected_mode", fc::t_enter_protected_mode },
|
|
|
|
{ "t_exit_protected_mode", fc::t_exit_protected_mode },
|
|
|
|
{ "t_enter_crossed_out_mode", fc::t_enter_crossed_out_mode },
|
|
|
|
{ "t_exit_crossed_out_mode", fc::t_exit_crossed_out_mode },
|
|
|
|
{ "t_enter_dbl_underline_mode", fc::t_enter_dbl_underline_mode },
|
|
|
|
{ "t_exit_dbl_underline_mode", fc::t_exit_dbl_underline_mode },
|
|
|
|
{ "t_set_attributes", fc::t_set_attributes },
|
|
|
|
{ "t_exit_attribute_mode", fc::t_exit_attribute_mode },
|
|
|
|
{ "t_enter_alt_charset_mode", fc::t_enter_alt_charset_mode },
|
|
|
|
{ "t_exit_alt_charset_mode", fc::t_exit_alt_charset_mode },
|
|
|
|
{ "t_enter_pc_charset_mode", fc::t_enter_pc_charset_mode },
|
|
|
|
{ "t_exit_pc_charset_mode", fc::t_exit_pc_charset_mode },
|
|
|
|
{ "t_enter_insert_mode", fc::t_enter_insert_mode },
|
|
|
|
{ "t_exit_insert_mode", fc::t_exit_insert_mode },
|
|
|
|
{ "t_enter_am_mode", fc::t_enter_am_mode },
|
|
|
|
{ "t_exit_am_mode", fc::t_exit_am_mode },
|
|
|
|
{ "t_acs_chars", fc::t_acs_chars },
|
|
|
|
{ "t_keypad_xmit", fc::t_keypad_xmit },
|
|
|
|
{ "t_keypad_local", fc::t_keypad_local },
|
|
|
|
{ "t_key_mouse", fc::t_key_mouse }
|
2018-01-17 21:11:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-03-26 20:40:04 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-01-17 21:11:26 +01:00
|
|
|
// Functions
|
2017-03-26 20:40:04 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-02-19 01:36:38 +01:00
|
|
|
void tcapBoolean (const std::string& name, bool cap_bool)
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
|
|
|
std::cout << "FTermcap::" << name << ": ";
|
|
|
|
|
|
|
|
if ( cap_bool )
|
|
|
|
std::cout << "true\r\n";
|
|
|
|
else
|
|
|
|
std::cout << "false\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-04-08 02:40:22 +02:00
|
|
|
void tcapNumeric (const std::string& name, int cap_num)
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
|
|
|
std::cout << "FTermcap::" << name << ": " << cap_num << "\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-25 21:17:08 +01:00
|
|
|
void tcapString (const std::string& name, const char cap_str[])
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
std::string sequence{};
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << name << ": ";
|
|
|
|
|
|
|
|
if ( cap_str == 0 )
|
|
|
|
{
|
|
|
|
std::cout << "\r\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const uInt len = uInt(std::strlen(cap_str));
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (uInt i{0}; i < len; i++)
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const uChar c = uChar(cap_str[i]);
|
2017-04-02 13:30:23 +02:00
|
|
|
|
2017-11-04 07:03:53 +01:00
|
|
|
if ( c > 127 )
|
2017-04-08 02:40:22 +02:00
|
|
|
{
|
|
|
|
std::ostringstream o;
|
2017-12-21 00:25:58 +01:00
|
|
|
o << std::oct << int(c);
|
2017-04-08 02:40:22 +02:00
|
|
|
sequence += "\\";
|
|
|
|
sequence += o.str();
|
|
|
|
}
|
|
|
|
else if ( c < 32 )
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
2017-04-02 13:30:23 +02:00
|
|
|
if ( c == 27 )
|
2017-03-26 20:40:04 +02:00
|
|
|
sequence += "\\E";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sequence += '^';
|
2017-12-21 00:25:58 +01:00
|
|
|
sequence += char(c + 64);
|
2017-03-26 20:40:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-12-21 00:25:58 +01:00
|
|
|
sequence += char(c);
|
2017-03-26 20:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << sequence << " ";
|
|
|
|
std::cout << "\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-02 00:43:27 +02:00
|
|
|
#if DEBUG
|
2018-09-20 23:59:01 +02:00
|
|
|
void debug (finalcut::FApplication& TermApp)
|
2017-03-26 20:40:04 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& fterm = TermApp.getFTerm();
|
2019-08-18 02:04:44 +02:00
|
|
|
auto& debug_data = fterm.getFTermDebugData();
|
2018-11-01 21:29:54 +01:00
|
|
|
const finalcut::FString& ab_s = debug_data.getAnswerbackString();
|
|
|
|
const finalcut::FString& sec_da = debug_data.getSecDAString();
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "\n.------------------- debug -------------------\r\n";
|
2018-11-01 21:29:54 +01:00
|
|
|
|
2017-11-24 00:28:25 +01:00
|
|
|
#if defined(__linux__)
|
|
|
|
std::cout << "| Framebuffer bpp: "
|
2018-11-01 21:29:54 +01:00
|
|
|
<< debug_data.getFramebufferBpp() << "\r\n";
|
2017-11-24 00:28:25 +01:00
|
|
|
#endif
|
2018-03-21 00:02:43 +01:00
|
|
|
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "| after init_256colorTerminal(): "
|
2018-11-01 21:29:54 +01:00
|
|
|
<< debug_data.getTermType_256color() << "\r\n";
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "| after parseAnswerbackMsg(): "
|
2018-11-01 21:29:54 +01:00
|
|
|
<< debug_data.getTermType_Answerback() << "\r\n";
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "| after parseSecDA(): "
|
2018-11-01 21:29:54 +01:00
|
|
|
<< debug_data.getTermType_SecDA() << "\r\n";
|
2017-03-28 08:50:37 +02:00
|
|
|
|
2018-05-02 12:31:21 +02:00
|
|
|
if ( ! ab_s.isEmpty() )
|
2018-03-21 00:02:43 +01:00
|
|
|
tcapString ("| The answerback String", ab_s);
|
2017-04-08 02:40:22 +02:00
|
|
|
|
2018-05-02 12:31:21 +02:00
|
|
|
if ( ! sec_da.isEmpty() )
|
2018-03-21 00:02:43 +01:00
|
|
|
tcapString ("| The SecDA String", sec_da);
|
2017-03-28 08:50:37 +02:00
|
|
|
|
2017-04-05 22:25:20 +02:00
|
|
|
std::cout << "`------------------- debug -------------------\r\n";
|
2017-11-24 00:28:25 +01:00
|
|
|
}
|
2018-09-02 00:43:27 +02:00
|
|
|
#else
|
2018-09-20 23:59:01 +02:00
|
|
|
void debug (finalcut::FApplication&)
|
2018-09-02 00:43:27 +02:00
|
|
|
{ }
|
|
|
|
#endif
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2017-11-24 00:28:25 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void booleans()
|
|
|
|
{
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "\r\n[Booleans]\r\n";
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "background_color_erase"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::background_color_erase );
|
2018-10-29 21:12:03 +01:00
|
|
|
tcapBoolean ( "can_change_color_palette"
|
|
|
|
, finalcut::FTermcap::can_change_color_palette );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "automatic_left_margin"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::automatic_left_margin );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "automatic_right_margin"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::automatic_right_margin );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "eat_nl_glitch"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::eat_nl_glitch );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "ansi_default_color"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::ansi_default_color );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "osc_support"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::osc_support );
|
2018-02-19 01:36:38 +01:00
|
|
|
tcapBoolean ( "no_utf8_acs_chars"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::no_utf8_acs_chars );
|
2017-11-24 00:28:25 +01:00
|
|
|
}
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2017-11-24 00:28:25 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void numeric()
|
|
|
|
{
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "\r\n[Numeric]\r\n";
|
2017-04-08 02:40:22 +02:00
|
|
|
tcapNumeric ("max_color"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::max_color);
|
2017-04-08 02:40:22 +02:00
|
|
|
tcapNumeric ("tabstop"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::tabstop);
|
2017-04-08 02:40:22 +02:00
|
|
|
tcapNumeric ("attr_without_color"
|
2018-09-20 23:59:01 +02:00
|
|
|
, finalcut::FTermcap::attr_without_color);
|
2017-11-24 00:28:25 +01:00
|
|
|
}
|
2017-03-26 20:40:04 +02:00
|
|
|
|
2017-11-24 00:28:25 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-05-27 00:50:11 +02:00
|
|
|
void string()
|
2017-11-24 00:28:25 +01:00
|
|
|
{
|
2017-03-26 20:40:04 +02:00
|
|
|
std::cout << "\r\n[String]\r\n";
|
2020-02-02 22:34:27 +01:00
|
|
|
const finalcut::FTermcap::tcap_map (&tcap_strings)[] \
|
2019-05-27 00:50:11 +02:00
|
|
|
= finalcut::FTermcap::strings;
|
2018-01-17 21:11:26 +01:00
|
|
|
|
2019-10-14 01:44:24 +02:00
|
|
|
for (const auto& entry : data::strings)
|
2018-01-17 21:11:26 +01:00
|
|
|
{
|
2019-10-14 01:44:24 +02:00
|
|
|
const std::string name = entry.name;
|
|
|
|
const fc::termcaps cap = entry.cap;
|
2019-05-27 00:50:11 +02:00
|
|
|
tcapString (name, tcap_strings[cap].string);
|
2018-01-17 21:11:26 +01:00
|
|
|
}
|
2017-03-26 20:40:04 +02:00
|
|
|
}
|
2017-11-24 00:28:25 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const bool disable_alt_screen{true};
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication TermApp (argc, argv, disable_alt_screen);
|
2017-11-24 00:28:25 +01:00
|
|
|
|
|
|
|
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
|
2018-10-30 01:13:32 +01:00
|
|
|
std::cout << "Terminal: " << TermApp.getTermType() << "\r\n";
|
2017-11-24 00:28:25 +01:00
|
|
|
|
|
|
|
debug (TermApp);
|
|
|
|
|
|
|
|
booleans();
|
|
|
|
numeric();
|
2019-05-27 00:50:11 +02:00
|
|
|
string();
|
2017-11-24 00:28:25 +01:00
|
|
|
}
|