Skip to content

Commit

Permalink
[vtpty] ImageSize: add min()/max() functions
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <christian@parpart.family>
  • Loading branch information
christianparpart committed Mar 15, 2024
1 parent 0102d17 commit 1c66ef4
Show file tree
Hide file tree
Showing 17 changed files with 920 additions and 583 deletions.
22 changes: 11 additions & 11 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void TerminalSession::executeShowHostWritableStatusLine(bool allow, bool remembe
_terminal.setStatusDisplay(vtbackend::StatusDisplayType::HostWritable);
displayLog()("requestCaptureBuffer: Finished. Waking up I/O thread.");
flushInput();
_terminal.state().syncWindowTitleWithHostWritableStatusDisplay = false;
_terminal.setSyncWindowTitleWithHostWritableStatusDisplay(false);
}

vtbackend::FontDef TerminalSession::getFontDef()
Expand Down Expand Up @@ -1017,16 +1017,16 @@ bool TerminalSession::operator()(actions::DecreaseOpacity)

bool TerminalSession::operator()(actions::FocusNextSearchMatch)
{
if (_terminal.state().viCommands.jumpToNextMatch(1))
_terminal.viewport().makeVisibleWithinSafeArea(_terminal.state().viCommands.cursorPosition.line);
if (_terminal.viCommands().jumpToNextMatch(1))
_terminal.viewport().makeVisibleWithinSafeArea(_terminal.viCommands().cursorPosition.line);
// TODO why didn't the makeVisibleWithinSafeArea() call from inside jumpToNextMatch not work?
return true;
}

bool TerminalSession::operator()(actions::FocusPreviousSearchMatch)
{
if (_terminal.state().viCommands.jumpToPreviousMatch(1))
_terminal.viewport().makeVisibleWithinSafeArea(_terminal.state().viCommands.cursorPosition.line);
if (_terminal.viCommands().jumpToPreviousMatch(1))
_terminal.viewport().makeVisibleWithinSafeArea(_terminal.viCommands().cursorPosition.line);
// TODO why didn't the makeVisibleWithinSafeArea() call from inside jumpToPreviousMatch not work?
return true;
}
Expand Down Expand Up @@ -1265,16 +1265,16 @@ bool TerminalSession::operator()(actions::ToggleInputProtection)
bool TerminalSession::operator()(actions::ToggleStatusLine)
{
auto const l = scoped_lock { _terminal };
if (terminal().state().statusDisplayType != StatusDisplayType::Indicator)
if (terminal().statusDisplayType() != StatusDisplayType::Indicator)
terminal().setStatusDisplay(StatusDisplayType::Indicator);
else
terminal().setStatusDisplay(StatusDisplayType::None);

// `savedStatusDisplayType` holds only a value if the application has been overriding
// the status display type. But the user now actively requests a given type,
// so make sure restoring will not destroy the user's desire.
if (terminal().state().savedStatusDisplayType)
terminal().state().savedStatusDisplayType = terminal().state().statusDisplayType;
if (terminal().savedStatusDisplayType())
terminal().setSavedStatusDisplayType(terminal().statusDisplayType());

return true;
}
Expand Down Expand Up @@ -1334,7 +1334,7 @@ void TerminalSession::setDefaultCursor()
return;

using Type = vtbackend::ScreenType;
switch (terminal().screenType())
switch (_terminal.screenType())
{
case Type::Primary: _display->setMouseCursorShape(MouseCursorShape::IBeam); break;
case Type::Alternate: _display->setMouseCursorShape(MouseCursorShape::Arrow); break;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void TerminalSession::configureTerminal()

sessionLog()("Setting terminal ID to {}.", _profile.terminalId.value());
_terminal.setTerminalId(_profile.terminalId.value());
_terminal.setMaxImageColorRegisters(_config.maxImageColorRegisters.value());
_terminal.setMaxSixelColorRegisters(_config.maxImageColorRegisters.value());
_terminal.setMaxImageSize(_config.maxImageSize.value());
_terminal.setMode(vtbackend::DECMode::NoSixelScrolling, !_config.sixelScrolling.value());
_terminal.setStatusDisplay(_profile.initialStatusDisplayType.value());
Expand Down Expand Up @@ -1532,7 +1532,7 @@ uint8_t TerminalSession::matchModeFlags() const
if (_terminal.inputHandler().mode() == ViMode::Insert)
flags |= static_cast<uint8_t>(MatchModes::Flag::Insert);

if (!_terminal.state().searchMode.pattern.empty())
if (!_terminal.search().pattern.empty())
flags |= static_cast<uint8_t>(MatchModes::Flag::Search);

if (_terminal.executionMode() != ExecutionMode::Normal)
Expand Down
1 change: 0 additions & 1 deletion src/vtbackend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ set(vtbackend_SOURCES
SixelParser.cpp
StatusLineBuilder.cpp
Terminal.cpp
TerminalState.cpp
VTType.cpp
VTWriter.cpp
Viewport.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/vtbackend/Hyperlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ using HyperlinkCache = crispy::lru_cache<HyperlinkId, std::shared_ptr<HyperlinkI

struct HyperlinkStorage
{
HyperlinkCache cache { 1024 };
mutable HyperlinkCache cache { 1024 };
HyperlinkId nextHyperlinkId = HyperlinkId(1);

std::shared_ptr<HyperlinkInfo> hyperlinkById(HyperlinkId id) noexcept
Expand All @@ -93,7 +93,7 @@ struct HyperlinkStorage
return {};
}

HyperlinkId hyperlinkIdByUserId(std::string const& id) noexcept
HyperlinkId hyperlinkIdByUserId(std::string const& id) const noexcept
{
for (auto& href: cache)
{
Expand Down
2 changes: 0 additions & 2 deletions src/vtbackend/MockTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class MockTerm: public Terminal::NullEvents
}

decltype(auto) pageSize() const noexcept { return terminal.pageSize(); }
decltype(auto) state() noexcept { return terminal.state(); }
decltype(auto) state() const noexcept { return terminal.state(); }

PtyDevice& mockPty() noexcept { return static_cast<PtyDevice&>(terminal.device()); }
PtyDevice const& mockPty() const noexcept { return static_cast<PtyDevice const&>(terminal.device()); }
Expand Down
26 changes: 13 additions & 13 deletions src/vtbackend/RenderBufferBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ optional<RenderCursor> RenderBufferBuilder<Cell>::renderCursor() const
// TODO: check if CursorStyle has changed, and update render context accordingly.

auto constexpr InactiveCursorShape = CursorShape::Rectangle; // TODO configurable
auto const shape = _terminal->state().focused ? _terminal->cursorShape() : InactiveCursorShape;
auto const shape = _terminal->focused() ? _terminal->cursorShape() : InactiveCursorShape;

auto const cursorScreenPosition =
CellLocation { _baseLine + _cursorPosition->line
Expand Down Expand Up @@ -311,7 +311,7 @@ bool RenderBufferBuilder<Cell>::gridLineContainsCursor(LineOffset lineOffset) co
if (_terminal->currentScreen().cursor().position.line == lineOffset)
return true;

if (_cursorPosition && _terminal->state().inputHandler.mode() != ViMode::Insert)
if (_cursorPosition && _terminal->inputHandler().mode() != ViMode::Insert)
{
auto const viCursor = _terminal->viewport().translateGridToScreenCoordinate(_cursorPosition->line);
if (viCursor == lineOffset)
Expand Down Expand Up @@ -399,21 +399,21 @@ void RenderBufferBuilder<Cell>::matchSearchPattern(T const& cellText)
if (_highlightSearchMatches == HighlightSearchMatches::No)
return;

auto const& searchMode = _terminal->state().searchMode;
if (searchMode.pattern.empty())
auto const& search = _terminal->search();
if (search.pattern.empty())
return;

auto const isFullMatch = [&]() -> bool {
if constexpr (std::is_same_v<Cell, T>)
{
return !CellUtil::beginsWith(u32string_view(searchMode.pattern.data() + _searchPatternOffset,
searchMode.pattern.size() - _searchPatternOffset),
return !CellUtil::beginsWith(u32string_view(search.pattern.data() + _searchPatternOffset,
search.pattern.size() - _searchPatternOffset),
cellText);
}
else
{
return crispy::beginsWith(u32string_view(searchMode.pattern.data() + _searchPatternOffset,
searchMode.pattern.size() - _searchPatternOffset),
return crispy::beginsWith(u32string_view(search.pattern.data() + _searchPatternOffset,
search.pattern.size() - _searchPatternOffset),
cellText);
}
}();
Expand All @@ -430,7 +430,7 @@ void RenderBufferBuilder<Cell>::matchSearchPattern(T const& cellText)
else
_searchPatternOffset += cellText.size();

if (_searchPatternOffset < searchMode.pattern.size())
if (_searchPatternOffset < search.pattern.size())
return; // match incomplete

// match complete
Expand All @@ -443,20 +443,20 @@ void RenderBufferBuilder<Cell>::matchSearchPattern(T const& cellText)
_output->cells.back().position,
}
.contains(_terminal->viewport().translateGridToScreenCoordinate(
_terminal->state().viCommands.cursorPosition));
_terminal->viCommands().cursorPosition));

auto highlightColors = [&]() -> CellRGBColorAndAlphaPair {
// Oh yeah, this can be optimized :)
if (isFocusedMatch)
{
if (_terminal->state().searchMode.initiatedByDoubleClick)
if (_terminal->search().initiatedByDoubleClick)
return _terminal->colorPalette().wordHighlightCurrent;
else
return _terminal->colorPalette().searchHighlightFocused;
}
else
{
if (_terminal->state().searchMode.initiatedByDoubleClick)
if (_terminal->search().initiatedByDoubleClick)
return _terminal->colorPalette().wordHighlight;
else
return _terminal->colorPalette().searchHighlight;
Expand Down Expand Up @@ -617,7 +617,7 @@ void RenderBufferBuilder<Cell>::renderCell(Cell const& screenCell, LineOffset li
_prevHasCursor = _cursorPosition && gridPosition == *_cursorPosition;

_output->cells.emplace_back(makeRenderCell(_terminal->colorPalette(),
_terminal->state().hyperlinks,
_terminal->hyperlinks(),
screenCell,
fg,
bg,
Expand Down
Loading

0 comments on commit 1c66ef4

Please sign in to comment.