Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crush when status line is enabled #1497

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

Check warning on line 111 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: variable name 'r' is too short, expected at least 3 characters [readability-identifier-length] ```cpp auto const r = static_cast<unsigned>(static_cast<float>(color.red) / 255.0f * 0xFFFF); ^ ```

Check warning on line 111 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: floating point literal has suffix 'f', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion 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);

Check warning on line 112 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: variable name 'g' is too short, expected at least 3 characters [readability-identifier-length] ```cpp auto const g = static_cast<unsigned>(static_cast<float>(color.green) / 255.0f * 0xFFFF); ^ ```

Check warning on line 112 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: floating point literal has suffix 'f', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion 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);

Check warning on line 113 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: variable name 'b' is too short, expected at least 3 characters [readability-identifier-length] ```cpp auto const b = static_cast<unsigned>(static_cast<float>(color.blue) / 255.0f * 0xFFFF); ^ ```

Check warning on line 113 in src/vtbackend/Screen.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: floating point literal has suffix 'f', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion 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 @@
}

} // 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
Loading