Skip to content

Commit

Permalink
Merge pull request #1497 from contour-terminal/fix/status_line_bug
Browse files Browse the repository at this point in the history
Fix crush when status line is enabled
  • Loading branch information
christianparpart authored Jun 20, 2024
2 parents 8c39881 + 93fec67 commit ae4ebc4
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 653 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<li>Fixes `CSI 8 ; (COLS) ; (ROWS) t` to resize the terminal with respect to High-DPI</li>
<li>Fixes screen sampling with multiple monitors (#940)</li>
<li>Fixes bell sound in spawned window in same process (#1515)</li>
<li>Fixes status line crush (#1511)</li>
</ul>
</description>
</release>
Expand Down
3 changes: 1 addition & 2 deletions src/vtbackend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(vtbackend_HEADERS
Screen.h
Selector.h
Sequence.h
Sequencer.h
SequenceBuilder.h
SixelParser.h
StatusLineBuilder.h
Terminal.h
Expand Down Expand Up @@ -67,7 +67,6 @@ set(vtbackend_SOURCES
Screen.cpp
Selector.cpp
Sequence.cpp
Sequencer.cpp
SixelParser.cpp
StatusLineBuilder.cpp
Terminal.cpp
Expand Down
2 changes: 0 additions & 2 deletions src/vtbackend/Metrics.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <vtbackend/Sequencer.h> // Sequence

#include <algorithm>
#include <map>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions src/vtbackend/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vtbackend/VTType.h>
#include <vtbackend/VTWriter.h>
#include <vtbackend/logging.h>
#include <vtbackend/SixelParser.h>

#include <crispy/App.h>
#include <crispy/Comparison.h>
Expand Down
124 changes: 123 additions & 1 deletion src/vtbackend/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <vtbackend/Image.h>
#include <vtbackend/ScreenBase.h>
#include <vtbackend/ScreenEvents.h>
#include <vtbackend/Sequencer.h>
#include <vtbackend/VTType.h>
#include <vtbackend/cell/CellConcept.h>

Expand Down Expand Up @@ -39,9 +38,90 @@
namespace vtbackend
{

class SixelImageBuilder;
class Terminal;
struct Settings;

// {{{ TODO: move me somewhere more appropriate
// XTSMGRAPHICS (xterm extension)
// CSI ? Pi ; Pa ; Pv S
namespace XtSmGraphics
{
enum class Item
{
NumberOfColorRegisters = 1,
SixelGraphicsGeometry = 2,
ReGISGraphicsGeometry = 3,
};

enum class Action
{
Read = 1,
ResetToDefault = 2,
SetToValue = 3,
ReadLimit = 4
};

using Value = std::variant<std::monostate, unsigned, ImageSize>;
} // namespace XtSmGraphics

/// TBC - Tab Clear
///
/// This control function clears tab stops.
enum class HorizontalTabClear
{
/// Ps = 0 (default)
AllTabs,

/// Ps = 3
UnderCursor,
};

/// Input: CSI 16 t
///
/// Input: CSI 14 t (for text area size)
/// Input: CSI 14; 2 t (for full window size)
/// Output: CSI 14 ; width ; height ; t
enum class RequestPixelSize // TODO: rename RequestPixelSize to RequestArea?
{
CellArea,
TextArea,
WindowArea,
};

/// DECRQSS - Request Status String
enum class RequestStatusString
{
SGR,
DECSCL,
DECSCUSR,
DECSCA,
DECSTBM,
DECSLRM,
DECSLPP,
DECSCPP,
DECSNLS,
DECSASD,
DECSSDT,
};

inline std::string setDynamicColorValue(
RGBColor const& color) // TODO: yet another helper. maybe SemanticsUtils static class?
{
auto const r = static_cast<unsigned>(static_cast<float>(color.red) / 255.0f * 0xFFFF);
auto const g = static_cast<unsigned>(static_cast<float>(color.green) / 255.0f * 0xFFFF);
auto const b = static_cast<unsigned>(static_cast<float>(color.blue) / 255.0f * 0xFFFF);
return fmt::format("rgb:{:04X}/{:04X}/{:04X}", r, g, b);
}

enum class ApplyResult
{
Ok,
Invalid,
Unsupported,
};
// }}}

/**
* Terminal Screen.
*
Expand Down Expand Up @@ -594,3 +674,45 @@ inline bool Screen<Cell>::isContiguousToCurrentLine(std::string_view continuatio
}

} // namespace vtbackend

// {{{ fmt formatter
template <>
struct fmt::formatter<vtbackend::RequestStatusString>: formatter<std::string_view>
{
auto format(vtbackend::RequestStatusString value,
format_context& ctx) noexcept -> format_context::iterator
{
string_view name;
switch (value)
{
case vtbackend::RequestStatusString::SGR: name = "SGR"; break;
case vtbackend::RequestStatusString::DECSCL: name = "DECSCL"; break;
case vtbackend::RequestStatusString::DECSCUSR: name = "DECSCUSR"; break;
case vtbackend::RequestStatusString::DECSCA: name = "DECSCA"; break;
case vtbackend::RequestStatusString::DECSTBM: name = "DECSTBM"; break;
case vtbackend::RequestStatusString::DECSLRM: name = "DECSLRM"; break;
case vtbackend::RequestStatusString::DECSLPP: name = "DECSLPP"; break;
case vtbackend::RequestStatusString::DECSCPP: name = "DECSCPP"; break;
case vtbackend::RequestStatusString::DECSNLS: name = "DECSNLS"; break;
case vtbackend::RequestStatusString::DECSASD: name = "DECSASD"; break;
case vtbackend::RequestStatusString::DECSSDT: name = "DECSSDT"; break;
}
return formatter<string_view>::format(name, ctx);
}
};

template <>
struct fmt::formatter<vtbackend::Sequence>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
template <typename FormatContext>
auto format(vtbackend::Sequence const& seq, FormatContext& ctx)
{
return fmt::format_to(ctx.out(), "{}", seq.text());
}
};
// }}}
10 changes: 10 additions & 0 deletions src/vtbackend/Sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gsl/span>

#include <cassert>
#include <concepts>
#include <iterator>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -362,4 +363,13 @@ class SequenceHandler
virtual void writeTextEnd() = 0;
};

template <typename T>
concept SequenceHandlerConcept = requires(T t) {
{ t.executeControlCode('\x00') } -> std::same_as<void>;
{ t.processSequence(Sequence {}) } -> std::same_as<void>;
{ t.writeText(U'a') } -> std::same_as<void>;
{ t.writeText("a", size_t(1)) } -> std::same_as<void>;
{ t.writeTextEnd() } -> std::same_as<void>;
};

} // namespace vtbackend
Loading

0 comments on commit ae4ebc4

Please sign in to comment.