Skip to content

Commit

Permalink
Escape sequences can now be used to repeat UTF-8 characters, which in…
Browse files Browse the repository at this point in the history
…creases the display speed
  • Loading branch information
gansm committed Feb 7, 2024
1 parent 130571a commit 687d640
Show file tree
Hide file tree
Showing 25 changed files with 248 additions and 96 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-02-07 Markus Gans <guru.mail@muenster.de>
* Escape sequences can now be used to repeat UTF-8 characters, which
increases the display speed

2023-12-30 Markus Gans <guru.mail@muenster.de>
* FColorPair can now be used as input for FVTermAttribute::setColor

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ AC_CHECK_HEADERS( \
cmath \
csignal \
cstdlib \
list \
list \
map \
queue \
vector )
Expand Down
18 changes: 16 additions & 2 deletions examples/hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2022 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand All @@ -30,7 +30,21 @@ auto main (int argc, char* argv[]) -> int

// Create a simple dialog box
finalcut::FMessageBox mbox{&app};
mbox.setText("Hello, World!");

// New line
const auto nl = finalcut::FString('\n');

// Border spacing
const auto spacing = finalcut::FString(5, ' ');

// Line with unicode character "─" (U+2500/Box drawings horizontal)
const auto line = finalcut::FString(13, L'\U00002500');

// Set the message box text
mbox.setText(nl + spacing + "Hello, World!" + spacing + nl + line);

// Center the text in the message box
mbox.setCenterText();

// Start the application
mbox.exec();
Expand Down
7 changes: 4 additions & 3 deletions examples/termcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2017-2023 Markus Gans *
* Copyright 2017-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -51,13 +51,13 @@ struct Data
const Termcap cap;
};

static std::array<TermcapString, 85> strings;
static std::array<TermcapString, 86> strings;
};

//----------------------------------------------------------------------
// struct data - string data array
//----------------------------------------------------------------------
std::array<Data::TermcapString, 85> Data::strings =
std::array<Data::TermcapString, 86> Data::strings =
{{
{ "t_bell", Termcap::t_bell },
{ "t_flash_screen", Termcap::t_flash_screen },
Expand All @@ -76,6 +76,7 @@ std::array<Data::TermcapString, 85> Data::strings =
{ "t_insert_character", Termcap::t_insert_character },
{ "t_parm_ich", Termcap::t_parm_ich },
{ "t_repeat_char", Termcap::t_repeat_char },
{ "t_repeat_last_char", Termcap::t_repeat_last_char },
{ "t_initialize_color", Termcap::t_initialize_color },
{ "t_initialize_pair", Termcap::t_initialize_pair },
{ "t_set_a_foreground", Termcap::t_set_a_foreground },
Expand Down
3 changes: 2 additions & 1 deletion final/fc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -1514,6 +1514,7 @@ enum class Termcap
t_insert_character,
t_parm_ich,
t_repeat_char,
t_repeat_last_char,
t_initialize_color,
t_initialize_pair,
t_set_a_foreground,
Expand Down
13 changes: 12 additions & 1 deletion final/ftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2017-2023 Markus Gans *
* Copyright 2017-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -32,6 +32,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <cwctype>

#include <array>
#include <chrono>
Expand Down Expand Up @@ -116,6 +117,16 @@ constexpr auto is7bit (CharT ch) noexcept -> bool
return static_cast<char_type>(ch) < 128;
}

// Printable character verification
constexpr auto isPrintable (char ch) noexcept -> bool
{
return std::isprint(ch);
}

constexpr auto isPrintable (wchar_t ch) noexcept -> bool
{
return std::iswprint(std::wint_t(ch));
}

// Typecast to c-string
template <typename StringT>
Expand Down
4 changes: 2 additions & 2 deletions final/menu/fmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -1200,7 +1200,7 @@ inline void FMenu::drawMenuText (MenuText& data)

for (std::size_t z{0}; z < data.text.getLength(); z++)
{
if ( ! std::iswprint(std::wint_t(data.text[z]))
if ( ! isPrintable(data.text[z])
&& ! FVTerm::getFOutput()->isNewFont()
&& ( data.text[z] < UniChar::NF_rev_left_arrow2
|| data.text[z] > UniChar::NF_check_mark )
Expand Down
2 changes: 1 addition & 1 deletion final/menu/fmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ inline void FMenuBar::drawMenuText (menuText& data)
if ( data.startpos > screenWidth - z )
break;

if ( ! std::iswprint(std::wint_t(data.text[z]))
if ( ! isPrintable(data.text[z])
&& ! FVTerm::getFOutput()->isNewFont()
&& ( data.text[z] < UniChar::NF_rev_left_arrow2
|| data.text[z] > UniChar::NF_check_mark ) )
Expand Down
23 changes: 21 additions & 2 deletions final/output/tty/foptimove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -110,6 +110,7 @@ void FOptiMove::setTermEnvironment (const TermEnv& term_env)
set_parm_right_cursor (term_env.param_cursor.t_parm_right_cursor);
set_erase_chars (term_env.edit.t_erase_chars);
set_repeat_char (term_env.edit.t_repeat_char);
set_repeat_last_char (term_env.edit.t_repeat_last_char);
set_clr_bol (term_env.edit.t_clr_bol);
set_clr_eol (term_env.edit.t_clr_eol);
setTabStop (term_env.tabstop);
Expand Down Expand Up @@ -419,7 +420,7 @@ void FOptiMove::set_repeat_char (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, ' ');
const auto& temp = FTermcap::encodeParameter(cap, ' ', 23);
edit.repeat_char.cap = cap;
edit.repeat_char.duration = capDuration (temp.data(), 1);
edit.repeat_char.length = capDurationToLength (edit.repeat_char.duration);
Expand All @@ -432,6 +433,24 @@ void FOptiMove::set_repeat_char (const char cap[])
}
}

//----------------------------------------------------------------------
void FOptiMove::set_repeat_last_char (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23);
edit.repeat_last_char.cap = cap;
edit.repeat_last_char.duration = capDuration (temp.data(), 1);
edit.repeat_last_char.length = capDurationToLength (edit.repeat_last_char.duration);
}
else
{
edit.repeat_last_char.cap = nullptr;
edit.repeat_last_char.duration = \
edit.repeat_last_char.length = LONG_DURATION;
}
}

//----------------------------------------------------------------------
void FOptiMove::set_clr_bol (const char cap[])
{
Expand Down
5 changes: 4 additions & 1 deletion final/output/tty/foptimove.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -86,6 +86,7 @@ class FOptiMove final
{
const char* t_erase_chars;
const char* t_repeat_char;
const char* t_repeat_last_char;
const char* t_clr_bol;
const char* t_clr_eol;
};
Expand Down Expand Up @@ -150,6 +151,7 @@ class FOptiMove final
void set_parm_right_cursor (const char[]);
void set_erase_chars (const char[]);
void set_repeat_char (const char[]);
void set_repeat_last_char (const char[]);
void set_clr_bol (const char[]);
void set_clr_eol (const char[]);
void set_auto_left_margin (bool = true) noexcept;
Expand Down Expand Up @@ -195,6 +197,7 @@ class FOptiMove final
{
Capability erase_chars{};
Capability repeat_char{};
Capability repeat_last_char{};
Capability clr_bol{};
Capability clr_eol{};
};
Expand Down
3 changes: 2 additions & 1 deletion final/output/tty/fterm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2012-2023 Markus Gans *
* Copyright 2012-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -1213,6 +1213,7 @@ void FTerm::init_optiMove()
{
TCAP(t_erase_chars),
TCAP(t_repeat_char),
TCAP(t_repeat_last_char),
TCAP(t_clr_bol),
TCAP(t_clr_eol)
},
Expand Down
7 changes: 4 additions & 3 deletions final/output/tty/ftermcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -595,8 +595,8 @@ inline void FTermcap::asteriskSlash ( string_iterator& iter
FTermcap::TCapMapType FTermcap::strings =
{{
// .------------- term string
// | .-------- Tcap-code
// | | // variable name -> description
// | .-------- Tcap-code
// | | // variable name -> description
//------------------------------------------------------------------------------
{ nullptr, {"bl"} }, // bell -> audible signal (bell) (P)
{ nullptr, {"vb"} }, // flash_screen -> visible bell (may not move cursor)
Expand All @@ -615,6 +615,7 @@ FTermcap::TCapMapType FTermcap::strings =
{ nullptr, {"ic"} }, // insert_character -> insert character (P)
{ nullptr, {"IC"} }, // parm_ich -> insert #1 characters (P*)
{ nullptr, {"rp"} }, // repeat_char -> repeat char #1 #2 times (P*)
{ nullptr, {"lr"} }, // repeat_last_char -> repeat last char #1 times (P*)
{ nullptr, {"Ic"} }, // initialize_color -> initialize color #1 to (#2,#3,#4)
{ nullptr, {"Ip"} }, // initialize_pair -> Initialize color pair #1 to
// fg=(#2,#3,#4), bg=(#5,#6,#7)
Expand Down
4 changes: 2 additions & 2 deletions final/output/tty/ftermcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2016-2023 Markus Gans *
* Copyright 2016-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -76,7 +76,7 @@ class FTermcap final
};

// Using-declaration
using TCapMapType = std::array<TCapMap, 85>;
using TCapMapType = std::array<TCapMap, 86>;
using PutCharFunc = std::decay_t<int(int)>;
using PutStringFunc = std::decay_t<int(const std::string&)>;

Expand Down
17 changes: 16 additions & 1 deletion final/output/tty/ftermcapquirks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2023 Markus Gans *
* Copyright 2018-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -129,6 +129,8 @@ void FTermcapQuirks::terminalFixup()

// Fixes general quirks
general();
// Repeat utf-8 character
repeatLastChar();
// ECMA-48 (ANSI X3.64) compatible terminal
ecma48();
}
Expand Down Expand Up @@ -481,6 +483,19 @@ inline void FTermcapQuirks::caModeExtension()
}
}

//----------------------------------------------------------------------
void FTermcapQuirks::repeatLastChar()
{
// UTF-8 characters can be repeated with repeat_last_char, unlike
// repeat_char which can only repeat 7-bit ASCII characters

if ( ! TCAP(t_repeat_char)
|| std::memcmp(TCAP(t_repeat_char), "%p1%c\033[%p2%{1}%-%db", 19) != 0 )
return;

setTCapString (TCAP(t_repeat_last_char), "\033[%p1%{1}%-%db");
}

//----------------------------------------------------------------------
void FTermcapQuirks::ecma48()
{
Expand Down
3 changes: 2 additions & 1 deletion final/output/tty/ftermcapquirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2022 Markus Gans *
* Copyright 2018-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -76,6 +76,7 @@ class FTermcapQuirks final
static void screen();
static void general();
static void caModeExtension();
static void repeatLastChar();
static void ecma48();
};

Expand Down
Loading

0 comments on commit 687d640

Please sign in to comment.