1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/***********************************************************************
* fvtermattribute.cpp - Manipulation of FChar colors and attributes *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2021-2023 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 *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* 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/>. *
***********************************************************************/
#include <functional>
#include <unordered_map>
#include "final/vterm/fcolorpair.h"
#include "final/vterm/fstyle.h"
#include "final/vterm/fvtermattribute.h"
namespace finalcut
{
// static class attributes
FChar FVTermAttribute::next_attribute{};
//----------------------------------------------------------------------
// class FVTermAttribute
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
// constructor
FVTermAttribute::FVTermAttribute() = default;
//----------------------------------------------------------------------
// destructor
FVTermAttribute::~FVTermAttribute() noexcept = default;
// public methods of FVTermAttribute
//----------------------------------------------------------------------
void FVTermAttribute::initAttribute()
{
// next_attribute contains the state of the next printed character
next_attribute.ch = {{ L'\0' }};
next_attribute.fg_color = FColor::Default;
next_attribute.bg_color = FColor::Default;
next_attribute.attr.byte[0] = 0;
next_attribute.attr.byte[1] = 0;
next_attribute.attr.byte[2] = 0;
next_attribute.attr.byte[3] = 0;
}
//----------------------------------------------------------------------
void FVTermAttribute::print (const FStyle& style)
{
static const std::unordered_map<Style, std::function<void(bool)>> attributeLookup
{
{ Style::Bold, &FVTermAttribute::setBold },
{ Style::Dim, &FVTermAttribute::setDim },
{ Style::Italic, &FVTermAttribute::setItalic },
{ Style::Underline, &FVTermAttribute::setUnderline },
{ Style::Blink, &FVTermAttribute::setBlink },
{ Style::Reverse, &FVTermAttribute::setReverse },
{ Style::Standout, &FVTermAttribute::setStandout },
{ Style::Invisible, &FVTermAttribute::setInvisible },
{ Style::Protected, &FVTermAttribute::setProtected },
{ Style::CrossedOut, &FVTermAttribute::setCrossedOut },
{ Style::DoubleUnderline, &FVTermAttribute::setDoubleUnderline },
{ Style::Transparent, &FVTermAttribute::setTransparent },
{ Style::ColorOverlay, &FVTermAttribute::setColorOverlay },
{ Style::InheritBackground, &FVTermAttribute::setInheritBackground }
};
Style attr = style.getStyle();
if ( attr == Style::None )
{
setNormal();
return;
}
while ( attr != Style::None )
{
const auto style_name = Style(attr & -attr); // Find rightmost set bit
const auto iter = attributeLookup.find(style_name);
if ( iter != attributeLookup.end() )
iter->second(true); // Sets the found style
attr ^= style_name; // Clear the rightmost set bit
}
}
//----------------------------------------------------------------------
void FVTermAttribute::print (const FColorPair& pair)
{
setColor (pair.getForegroundColor(), pair.getBackgroundColor());
}
} // namespace finalcut
|