Skip to content

Commit

Permalink
Merge branch 'FarGroup:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Sep 21, 2024
2 parents 9701ccc + 00d400c commit 596a602
Show file tree
Hide file tree
Showing 38 changed files with 691 additions and 226 deletions.
535 changes: 453 additions & 82 deletions enc/enc_lua/luafar_manual.tsi

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
--------------------------------------------------------------------------------
drkns 2024-09-15 14:01:29+01:00 - build 6370

1. Refactoring.

--------------------------------------------------------------------------------
drkns 2024-09-11 17:11:09+01:00 - build 6369

1. Correction of 5839.

2. Refactoring.

--------------------------------------------------------------------------------
drkns 2024-09-10 19:37:57+01:00 - build 6368

1. Minor visual correction of 6348.

--------------------------------------------------------------------------------
drkns 2024-09-05 21:27:14+01:00 - build 6367

Expand Down
2 changes: 1 addition & 1 deletion far/color_picker_256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static FarColor Console256ColorToFarColor(index_color_256 const Color)
{
return
{
FCF_FG_INDEX | FCF_BG_INDEX,
FCF_INDEXMASK,
{ colors::opaque(colors::index_bits(Color.ForegroundIndex)) },
{ colors::opaque(colors::index_bits(Color.BackgroundIndex)) }
};
Expand Down
13 changes: 7 additions & 6 deletions far/colormix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ namespace colors
static WORD emulate_styles(index_color_16 Color, FARCOLORFLAGS const Flags)
{
if (Flags & FCF_FG_BOLD)
Color.ForegroundIndex |= FOREGROUND_INTENSITY;
Color.ForegroundIndex |= F_INTENSE;

if (Flags & FCF_FG_FAINT)
Color.ForegroundIndex &= ~FOREGROUND_INTENSITY;
Color.ForegroundIndex &= ~F_INTENSE;

// COMMON_LVB_REVERSE_VIDEO is a better way, but it only works on Windows 10.
// Manual swap works everywhere.
Expand Down Expand Up @@ -638,7 +638,7 @@ WORD FarColorToConsoleColor(const FarColor& Color)
{
// oops, unreadable
// since background is more pronounced we adjust the foreground only
flags::invert(Result.ForegroundIndex, FOREGROUND_INTENSITY);
flags::invert(Result.ForegroundIndex, C_INTENSE);
}

Last.emplace(Color, Result);
Expand Down Expand Up @@ -676,7 +676,7 @@ FarColor NtColorToFarColor(WORD Color)

return
{
FCF_FG_INDEX | FCF_BG_INDEX | FCF_INHERIT_STYLE | (Color & FCF_RAWATTR_MASK),
FCF_INDEXMASK | FCF_INHERIT_STYLE | (Color & FCF_RAWATTR_MASK),
{ opaque(Color16.ForegroundIndex) },
{ opaque(Color16.BackgroundIndex) }
};
Expand Down Expand Up @@ -842,8 +842,9 @@ unsigned long long ColorStringToFlags(string_view const Flags)
static FarColor s_ResolvedDefaultColor
{
FCF_INDEXMASK,
{ opaque(F_LIGHTGRAY) },
{ opaque(F_BLACK) },
{ opaque(C_LIGHTGRAY) },
{ opaque(C_BLACK) },
{ transparent(C_BLACK) }
};

COLORREF resolve_default(COLORREF Color, bool IsForeground)
Expand Down
30 changes: 30 additions & 0 deletions far/common.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ TEST_CASE("cpp.const_return")

#include "common/2d/matrix.hpp"

namespace detail
{
template<typename T>
constexpr bool is_const = std::is_const_v<std::remove_reference_t<T>>;
};

TEST_CASE("2d.matrix")
{
static const size_t Data[]
Expand All @@ -126,10 +132,34 @@ TEST_CASE("2d.matrix")
matrix Copy(Matrix);
Copy = Matrix;

matrix_view<const size_t> const ConstView(Copy);

REQUIRE(Matrix.width() == Width);
REQUIRE(Matrix.height() == Height);
REQUIRE(Matrix.size() == Height * Width);

REQUIRE(std::views::reverse(Matrix).front().front() == Data[Width * (Height - 1)]);

STATIC_REQUIRE(detail::is_const<decltype(*Matrix.data())>);
STATIC_REQUIRE(detail::is_const<decltype(*Matrix[0].data())>);
STATIC_REQUIRE(detail::is_const<decltype(*Matrix.front().data())>);
STATIC_REQUIRE(detail::is_const<decltype(Matrix.at(0, 0))>);

STATIC_REQUIRE(!detail::is_const<decltype(*Copy.data())>);
STATIC_REQUIRE(!detail::is_const<decltype(*Copy[0].data())>);
STATIC_REQUIRE(!detail::is_const<decltype(*Copy.front().data())>);
STATIC_REQUIRE(!detail::is_const<decltype(Copy.at(0, 0))>);

STATIC_REQUIRE(!detail::is_const<decltype(*std::as_const(Copy).data())>);
STATIC_REQUIRE(!detail::is_const<decltype(*std::as_const(Copy)[0].data())>);
STATIC_REQUIRE(!detail::is_const<decltype(*std::as_const(Copy).front().data())>);
STATIC_REQUIRE(!detail::is_const<decltype(std::as_const(Copy).at(0, 0))>);

STATIC_REQUIRE(detail::is_const<decltype(*ConstView.data())>);
STATIC_REQUIRE(detail::is_const<decltype(*ConstView[0].data())>);
STATIC_REQUIRE(detail::is_const<decltype(*ConstView.front().data())>);
STATIC_REQUIRE(detail::is_const<decltype(ConstView.at(0, 0))>);

size_t Counter = 0;
size_t RowNumber = 0;

Expand Down
55 changes: 25 additions & 30 deletions far/common/2d/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ namespace detail
public:
using iterator_category = std::random_access_iterator_tag;
using difference_type = std::ptrdiff_t;
using reference = T;
using value_type = T;
using pointer = T*;
using value_type = matrix_row<T>;
using reference = value_type;
using pointer = value_type*;

matrix_iterator() = default;

Expand Down Expand Up @@ -129,6 +129,8 @@ template<class T>
class matrix_view
{
public:
using iterator = detail::matrix_iterator<T>;

COPYABLE(matrix_view);
MOVABLE(matrix_view);

Expand All @@ -140,33 +142,25 @@ class matrix_view
{
}

[[nodiscard]] auto begin() { return detail::matrix_iterator(data(), m_Cols); }
[[nodiscard]] auto end() { return detail::matrix_iterator(data() + size(), m_Cols); }
[[nodiscard]] auto begin() const { return detail::matrix_iterator(data(), m_Cols); }
[[nodiscard]] auto end() const { return detail::matrix_iterator(data() + size(), m_Cols); }
[[nodiscard]] auto cbegin() const { return detail::matrix_iterator(data(), m_Cols); }
[[nodiscard]] auto cend() const { return detail::matrix_iterator(data() + size(), m_Cols); }

[[nodiscard]]
// BUGBUG assert for <= is due to the fact that &row[size] can be used as an 'end' iterator
// TODO: use iterators
auto operator[](size_t const Index) { assert(Index <= m_Rows); return detail::matrix_row(m_Data + m_Cols * Index, m_Cols); }
[[nodiscard]] auto begin() const { return iterator(m_Data, m_Cols); }
[[nodiscard]] auto end() const { return iterator(m_Data + size(), m_Cols); }
[[nodiscard]] auto cbegin() const { return begin(); }
[[nodiscard]] auto cend() const { return end(); }
[[nodiscard]] auto rbegin() const { return std::make_reverse_iterator(begin()); }
[[nodiscard]] auto rend() const { return std::make_reverse_iterator(end()); }
[[nodiscard]] auto crbegin() const { return rbegin(); }
[[nodiscard]] auto crend() const { return rend(); }

[[nodiscard]]
// BUGBUG assert for <= is due to the fact that &row[size] can be used as an 'end' iterator
// TODO: use iterators
auto operator[](size_t const Index) const { assert(Index <= m_Rows); return detail::matrix_row(m_Data + m_Cols * Index, m_Cols); }

const auto& at(size_t const Row, size_t const Col) const
auto& at(size_t const Row, size_t const Col) const
{
assert(Row < m_Rows);
assert(Col < m_Cols);
return m_Data[m_Cols * Row + Col];
}

auto& at(size_t const Row, size_t const Col)
{
return const_cast<T&>(std::as_const(*this).at(Row, Col));
return data()[m_Cols * Row + Col];
}

[[nodiscard]]
Expand All @@ -175,12 +169,6 @@ class matrix_view
[[nodiscard]]
auto width() const { return m_Cols; }

[[nodiscard]]
auto front() { assert(m_Rows != 0); return (*this)[0]; }

[[nodiscard]]
auto back() { assert(m_Rows != 0); return (*this)[m_Rows - 1]; }

[[nodiscard]]
auto front() const { assert(m_Rows != 0); return (*this)[0]; }

Expand All @@ -193,12 +181,19 @@ class matrix_view
[[nodiscard]]
auto size() const { return m_Rows * m_Cols; }

[[nodiscard]]
auto data() { return m_Data; }

[[nodiscard]]
auto data() const { return m_Data; }

auto row_number(detail::matrix_row<T> const& Row) const
{
return (Row.data() - m_Data) / m_Cols;
}

operator matrix_view<const T>() const
{
return matrix_view<const T>(m_Data, m_Rows, m_Cols);
}

private:
T* m_Data{};
size_t m_Rows{};
Expand Down
35 changes: 22 additions & 13 deletions far/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ namespace console_detail
if (colors::is_default(Color.Value))
append(Str, Mapping.Default);
else if (const auto Index = vt_color_index(colors::index_value(Color.Value)); Index < colors::index::nt_size && Mapping.PreferBasicIndex)
append(Str, Color.Value & FOREGROUND_INTENSITY? Mapping.Intense : Mapping.Normal, static_cast<wchar_t>(L'0' + (Index & 0b111)));
append(Str, Color.Value & C_INTENSE? Mapping.Intense : Mapping.Normal, static_cast<wchar_t>(L'0' + (Index & 0b111)));
else
far::format_to(Str, L"{1}{0}5{0}{2}"sv, Mapping.Separator, Mapping.ExtendedColour, Index);
}
Expand Down Expand Up @@ -1530,6 +1530,15 @@ namespace console_detail
UnderlineStyle(Color.GetUnderline()),
UnderlineColor(single_color::underline(Color))
{
if (Color.Flags & COMMON_LVB_GRID_HORIZONTAL)
Style |= FCF_FG_OVERLINE;

if (Color.Flags & COMMON_LVB_REVERSE_VIDEO)
Style |= FCF_FG_INVERSE;

if (Color.Flags & COMMON_LVB_UNDERSCORE && UnderlineStyle == UNDERLINE_STYLE::UNDERLINE_NONE)
UnderlineStyle = UNDERLINE_STYLE::UNDERLINE_SINGLE;

if (
// If there's no underline, no point in emitting its color
UnderlineStyle == UNDERLINE_NONE ||
Expand Down Expand Up @@ -3191,8 +3200,8 @@ TEST_CASE("console.vt_sequence")

{
FAR_CHAR_INFO Buffer[]{ def, def, def, def };
Buffer[1].Attributes.BackgroundColor = colors::opaque(F_MAGENTA);
Buffer[2].Attributes.ForegroundColor = colors::opaque(F_GREEN);
Buffer[1].Attributes.BackgroundColor = colors::opaque(C_MAGENTA);
Buffer[2].Attributes.ForegroundColor = colors::opaque(C_GREEN);
Buffer[3].Attributes.Flags |= FCF_FG_BOLD;
check(Buffer, VTSTR(
" "
Expand All @@ -3205,8 +3214,8 @@ TEST_CASE("console.vt_sequence")
{
FAR_CHAR_INFO Buffer[]{ def, def, def };
Buffer[0].Attributes.Flags |= FCF_FG_BOLD;
Buffer[0].Attributes.BackgroundColor = colors::opaque(F_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(F_LIGHTGREEN);
Buffer[0].Attributes.BackgroundColor = colors::opaque(C_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(C_LIGHTGREEN);

Buffer[1] = Buffer[0];

Expand All @@ -3221,22 +3230,22 @@ TEST_CASE("console.vt_sequence")

{
FAR_CHAR_INFO Buffer[]{ def, def, def, def, def };
Buffer[0].Attributes.BackgroundColor = colors::opaque(F_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(F_YELLOW);
Buffer[0].Attributes.BackgroundColor = colors::opaque(C_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(C_YELLOW);

Buffer[1] = Buffer[0];
Buffer[1].Attributes.SetUnderline(UNDERLINE_CURLY);
Buffer[1].Attributes.UnderlineColor = Buffer[1].Attributes.ForegroundColor;
Buffer[1].Attributes.SetUnderlineIndex(Buffer[1].Attributes.IsFgIndex());

Buffer[2] = Buffer[1];
Buffer[2].Attributes.UnderlineColor = colors::opaque(F_RED);
Buffer[2].Attributes.UnderlineColor = colors::opaque(C_RED);

Buffer[3] = Buffer[1];

Buffer[4] = Buffer[3];
Buffer[4].Attributes.ForegroundColor = colors::opaque(F_MAGENTA);
Buffer[4].Attributes.UnderlineColor = colors::opaque(F_MAGENTA);
Buffer[4].Attributes.ForegroundColor = colors::opaque(C_MAGENTA);
Buffer[4].Attributes.UnderlineColor = colors::opaque(C_MAGENTA);


check(Buffer, VTSTR(
Expand All @@ -3251,13 +3260,13 @@ TEST_CASE("console.vt_sequence")
{
FAR_CHAR_INFO Buffer[]{ def, def, def, def, def, def };

Buffer[0].Attributes.BackgroundColor = colors::opaque(F_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(F_LIGHTGREEN);
Buffer[0].Attributes.BackgroundColor = colors::opaque(C_BLUE);
Buffer[0].Attributes.ForegroundColor = colors::opaque(C_LIGHTGREEN);
Buffer[0].Attributes.SetUnderline(UNDERLINE_DOUBLE);

Buffer[1] = Buffer[0];
Buffer[1].Attributes.SetUnderline(UNDERLINE_CURLY);
Buffer[1].Attributes.UnderlineColor = colors::opaque(F_YELLOW);
Buffer[1].Attributes.UnderlineColor = colors::opaque(C_YELLOW);

Buffer[2] = Buffer[1];
Buffer[2].Attributes.SetUnderline(UNDERLINE_DOT);
Expand Down
8 changes: 6 additions & 2 deletions far/console_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ class context final: noncopyable, public i_context
m_Consolised = false;
}

if (Scroll && DoWeReallyHaveToScroll(Global->Opt->ShowKeyBar? 3 : 2))
if (Scroll)
{
std::wcout << std::endl;
const auto SpaceNeeded = Global->Opt->ShowKeyBar? 3uz : 2uz;

if (const auto SpaceAvailable = NumberOfEmptyLines(SpaceNeeded); SpaceAvailable < SpaceNeeded)
std::wcout << string_view(L"\n\n\n", SpaceNeeded - SpaceAvailable) << std::flush;

Global->ScrBuf->FillBuf();
}

Expand Down
4 changes: 2 additions & 2 deletions far/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class far_exception: public detail::far_std_exception
class far_known_exception final: public far_exception
{
public:
explicit far_known_exception(string_view const Message):
far_exception(Message, false, {})
explicit far_known_exception(string_view const Message, source_location const& Location = source_location::current()):
far_exception(Message, false, Location)
{
}
};
Expand Down
19 changes: 10 additions & 9 deletions far/hilight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

static const FarColor DefaultColor
{
FCF_FG_INDEX | FCF_BG_INDEX | FCF_INHERIT_STYLE,
{colors::transparent(F_BLACK)},
{colors::transparent(F_BLACK)}
FCF_INDEXMASK | FCF_INHERIT_STYLE,
{colors::transparent(C_BLACK)},
{colors::transparent(C_BLACK)},
{colors::transparent(C_BLACK)}
};

namespace names
Expand Down Expand Up @@ -167,12 +168,12 @@ static void SetHighlighting(bool DeleteOld, HierarchicalConfig& cfg)
}
DefaultHighlighting[]
{
{ {}, FILE_ATTRIBUTE_HIDDEN, MakeFarColor(F_CYAN), MakeFarColor(F_DARKGRAY) },
{ {}, FILE_ATTRIBUTE_SYSTEM, MakeFarColor(F_CYAN), MakeFarColor(F_DARKGRAY) },
{ {}, FILE_ATTRIBUTE_DIRECTORY, MakeFarColor(F_WHITE), MakeFarColor(F_WHITE) },
{ L"<exec>"sv, 0, MakeFarColor(F_LIGHTGREEN), MakeFarColor(F_LIGHTGREEN) },
{ L"<arc>"sv, 0, MakeFarColor(F_LIGHTMAGENTA), MakeFarColor(F_LIGHTMAGENTA) },
{ L"<temp>"sv, 0, MakeFarColor(F_BROWN), MakeFarColor(F_BROWN) },
{ {}, FILE_ATTRIBUTE_HIDDEN, MakeFarColor(C_CYAN), MakeFarColor(C_DARKGRAY) },
{ {}, FILE_ATTRIBUTE_SYSTEM, MakeFarColor(C_CYAN), MakeFarColor(C_DARKGRAY) },
{ {}, FILE_ATTRIBUTE_DIRECTORY, MakeFarColor(C_WHITE), MakeFarColor(C_WHITE) },
{ L"<exec>"sv, 0, MakeFarColor(C_LIGHTGREEN), MakeFarColor(C_LIGHTGREEN) },
{ L"<arc>"sv, 0, MakeFarColor(C_LIGHTMAGENTA), MakeFarColor(C_LIGHTMAGENTA) },
{ L"<temp>"sv, 0, MakeFarColor(C_BROWN), MakeFarColor(C_BROWN) },
};

const auto root = cfg.CreateKey(cfg.root_key, names::Highlight);
Expand Down
Loading

0 comments on commit 596a602

Please sign in to comment.