Compare commits

...

3 Commits

Author SHA1 Message Date
Mike Griese
7d4765b45a the logic is definitely wack here, but this feels closer 2023-09-14 17:00:27 -05:00
Mike Griese
11dfb74e8d turns out tab visibility is Hard 2023-09-14 16:41:38 -05:00
Mike Griese
38386bb8a7 a proof of concept for #3991 2023-09-14 15:30:50 -05:00
6 changed files with 167 additions and 2 deletions

View File

@@ -211,6 +211,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
core->_ScrollPositionChangedHandlers(*core, update);
}
});
shared->updateAutoProgress = std::make_unique<ThrottledFuncTrailing<>>(
_dispatcher,
SearchAfterChangeDelay,
[weakThis = get_weak()]() {
// if (const auto t = weakTerminal.lock())
if (auto core{ weakThis.get() }; !core->_IsClosing())
{
core->_autodetectProgressState();
// auto lock = core->_terminal->LockForWriting();
// if (core->_terminal->HasContentAfter(core->_restartedAt))
// {
// core->_gotFirstByte = true;
// core->_automaticProgressState = DispatchTypes::TaskbarState::Clear;
// core->_TaskbarProgressChangedHandlers(*core, nullptr);
// }
}
});
}
ControlCore::~ControlCore()
@@ -276,6 +294,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
// Subscribe to the connection's disconnected event and call our connection closed handlers.
_connectionStateChangedRevoker = newConnection.StateChanged(winrt::auto_revoke, [this](auto&& /*s*/, auto&& /*v*/) {
// if (_connection.State() > TerminalConnection::ConnectionState::Connecting &&
// _automaticProgressState == DispatchTypes::TaskbarState::Indeterminate)
// {
// _automaticProgressState = DispatchTypes::TaskbarState::Clear;
// _TaskbarProgressChangedHandlers(*this, nullptr);
// }
_ConnectionStateChangedHandlers(*this, nullptr);
});
@@ -296,6 +320,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// This event is explicitly revoked in the destructor: does not need weak_ref
_connectionOutputEventRevoker = _connection.TerminalOutput(winrt::auto_revoke, { this, &ControlCore::_connectionOutputHandler });
if (_connection.State() < TerminalConnection::ConnectionState::Connected)
{
_gotFirstByte = false;
_automaticProgressState = DispatchTypes::TaskbarState::Indeterminate;
_restartedAt = _initializedTerminal.load(std::memory_order_relaxed) ? _terminal->GetTextBuffer().GetLastNonSpaceCharacter() : _restartedAt;
_TaskbarProgressChangedHandlers(*this, nullptr);
}
}
// Fire off a connection state changed notification, to let our hosting
@@ -1382,7 +1414,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - The taskbar state of this control
const size_t ControlCore::TaskbarState() const noexcept
{
return _terminal->GetTaskbarState();
// The CLI's progress always takes precedence.
if (const auto progressStateFromApp{ _terminal->GetTaskbarState() };
static_cast<DispatchTypes::TaskbarState>(progressStateFromApp) != DispatchTypes::TaskbarState::Clear)
{
return progressStateFromApp;
}
else if (!_gotFirstByte)
{
return static_cast<size_t>(DispatchTypes::TaskbarState::Indeterminate);
}
return static_cast<size_t>(_automaticProgressState); // _terminal->GetTaskbarState();
}
// Method Description:
@@ -1391,7 +1433,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - The taskbar progress of this control
const size_t ControlCore::TaskbarProgress() const noexcept
{
return _terminal->GetTaskbarProgress();
// The CLI's progress always takes precedence.
if (const auto progressStateFromApp{ _terminal->GetTaskbarState() };
static_cast<DispatchTypes::TaskbarState>(progressStateFromApp) != DispatchTypes::TaskbarState::Clear)
{
return _terminal->GetTaskbarProgress();
}
return _automaticProgress; // _terminal->GetTaskbarState();
}
int ControlCore::ScrollOffset()
@@ -1916,6 +1964,46 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
void ControlCore::_connectionOutputHandler(const hstring& hstr)
{
{
const auto shared = _shared.lock_shared();
// if (!_gotFirstByte)
// {
if (shared->updateAutoProgress)
{
shared->updateAutoProgress->Run();
}
// // ConPTY is known to send
// // * L"\x1b[?9001h\x1b[?1004h"
// // * L"\x1b[6n"
// //
// // on startup. It might be changed in the future. You might think a
// // useful heuristic would be wait till we get a sequence that
// // doesn't start with an esc char. You'd be wrong - for something
// // like bash, it's going to write a lot of frames that start with an
// // ESC. Even just typing - turns the cursor on and off, moves it,
// // clears the input line, etc.
// // if (!hstr.empty() && hstr != L'\x1b')
// if (hstr != L"\x1b[?9001h\x1b[?1004h" && hstr != L"\x1b[6n")
// {
// _gotFirstByte = true;
// _automaticProgressState = DispatchTypes::TaskbarState::Clear;
// // TODO! not on the output thread dingus
// // Though i guess the first one does too so that's okay
// _TaskbarProgressChangedHandlers(*this, nullptr);
// }
// }
// else
// {
// TODO! throttle
// if (!_visible && _terminal->InOutputState())
// {
// _automaticProgressState = DispatchTypes::TaskbarState::Indeterminate;
// _TaskbarProgressChangedHandlers(*this, nullptr);
// }
// }
}
try
{
_terminal->Write(hstr);
@@ -2622,4 +2710,41 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _clickedOnMark(_contextMenuBufferPosition,
[](const ::ScrollMark& m) -> bool { return !m.HasOutput(); });
}
void ControlCore::Visible(bool visible)
{
_visible = visible;
// if (visible && _automaticProgressState == DispatchTypes::TaskbarState::Indeterminate)
// {
// _automaticProgressState = DispatchTypes::TaskbarState::Clear;
// _TaskbarProgressChangedHandlers(*this, nullptr);
// }
}
void ControlCore::_autodetectProgressState()
{
auto lock = _terminal->LockForWriting();
if (!_gotFirstByte)
{
if (_terminal->HasContentAfter(_restartedAt))
{
_gotFirstByte = true;
_automaticProgressState = DispatchTypes::TaskbarState::Clear;
_TaskbarProgressChangedHandlers(*this, nullptr);
}
}
else
{
if (_terminal->InOutputState())
{
_automaticProgressState = DispatchTypes::TaskbarState::Indeterminate;
_TaskbarProgressChangedHandlers(*this, nullptr);
}
else if (_automaticProgressState == DispatchTypes::TaskbarState::Indeterminate)
{
_automaticProgressState = DispatchTypes::TaskbarState::Clear;
_TaskbarProgressChangedHandlers(*this, nullptr);
}
}
}
}

View File

@@ -139,6 +139,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ColorSelection(const Control::SelectionColor& fg, const Control::SelectionColor& bg, Core::MatchMode matchMode);
void Visible(bool visible);
void Close();
#pragma region ICoreState
@@ -286,6 +288,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
std::shared_ptr<ThrottledFuncTrailing<>> tsfTryRedrawCanvas;
std::unique_ptr<til::throttled_func_trailing<>> updatePatternLocations;
std::shared_ptr<ThrottledFuncTrailing<Control::ScrollPositionChangedArgs>> updateScrollBar;
std::shared_ptr<ThrottledFuncTrailing<>> updateAutoProgress;
};
std::atomic<bool> _initializedTerminal{ false };
@@ -341,6 +344,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
til::point _contextMenuBufferPosition{ 0, 0 };
::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState _automaticProgressState = ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState::Clear;
size_t _automaticProgress = 0;
bool _gotFirstByte{ false };
til::point _restartedAt{ 0, 0 };
bool _visible{ true };
Windows::Foundation::Collections::IVector<int32_t> _cachedSearchResultRows{ nullptr };
void _setupDispatcherAndCallbacks();
@@ -400,6 +409,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool _clickedOnMark(const til::point& pos, bool (*filter)(const ::ScrollMark&));
void _autodetectProgressState();
inline bool _IsClosing() const noexcept
{
#ifndef NDEBUG

View File

@@ -159,6 +159,8 @@ namespace Microsoft.Terminal.Control
Boolean ShouldShowSelectCommand();
Boolean ShouldShowSelectOutput();
void Visible(Boolean visible);
// These events are called from some background thread
event Windows.Foundation.TypedEventHandler<Object, CopyToClipboardEventArgs> CopyToClipboard;
event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged;

View File

@@ -219,6 +219,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}
});
// TODO! almost certainly need a revoker
// RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [weakThis = get_weak()](auto&&, auto&&) {
// if (auto control{ weakThis.get() }; !control->_IsClosing())
// {
// control->_core.Visible(control->Visibility() == Visibility::Visible);
// }
// });
//
// LayoutUpdated([weakThis = get_weak()](auto&&, auto&&) {
// if (auto control{ weakThis.get() }; !control->_IsClosing())
// {
// control->_core.Visible(control->Parent() != nullptr);
// }
// });
}
// Function Description:

View File

@@ -1626,3 +1626,12 @@ extern "C" SHORT OneCoreSafeGetKeyState(_In_ int nVirtKey)
{
return GetKeyState(nVirtKey);
}
bool Terminal::HasContentAfter(const til::point p)
{
return p < _activeBuffer().GetLastNonSpaceCharacter();
}
bool Terminal::InOutputState() const
{
return _currentPromptState == PromptState::Output;
}

View File

@@ -239,6 +239,9 @@ public:
void UpdatePatternsUnderLock();
void ClearPatternTree();
bool HasContentAfter(const til::point at);
bool InOutputState() const;
const std::optional<til::color> GetTabColor() const;
winrt::Microsoft::Terminal::Core::Scheme GetColorScheme() const;