diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index fe245e5caef..8df2b28457f 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -2988,6 +2988,85 @@ "description": "Sets the sound played when the application emits a BEL. When set to an array, the terminal will pick one of those sounds at random.", "$ref": "#/$defs/BellSound" }, + "notifyOnActivity": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "taskbar", + "audible", + "tab", + "notification" + ] + } + }, + { + "type": "string", + "enum": [ + "taskbar", + "audible", + "tab", + "notification", + "all", + "none" + ] + } + ], + "description": "Controls how you are notified when an inactive tab produces new output." + }, + "notifyOnNextPrompt": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "taskbar", + "audible", + "tab", + "notification" + ] + } + }, + { + "type": "string", + "enum": [ + "taskbar", + "audible", + "tab", + "notification", + "all", + "none" + ] + } + ], + "description": "Controls how you are notified when a new shell prompt is detected. Requires shell integration." + }, + "notifyOnActivityThreshold": { + "type": "integer", + "minimum": 0, + "default": 5, + "description": "Minimum number of seconds between consecutive activity notifications for this profile. Use this to suppress repeated notifications from chatty processes. The first notification after the pane has been silent always fires; subsequent notifications within this window are suppressed. Use 0 to always notify." + }, + "notifyOnNextPromptThreshold": { + "type": "integer", + "minimum": 0, + "default": 5, + "description": "Suppress the next-prompt notification unless the just-finished command ran for at least this many seconds. Requires shell integration. Use 0 to always notify." + }, + "autoDetectRunningCommand": { + "default": false, + "description": "Automatically detect when a command is running and show a progress indicator in the tab and taskbar.", + "type": "boolean" + }, "closeOnExit": { "default": "automatic", "description": "Sets how the profile reacts to termination or failure to launch. Possible values:\n -\"graceful\" (close when exit is typed or the process exits normally)\n -\"always\" (always close)\n -\"automatic\" (behave as \"graceful\" only for processes launched by terminal, behave as \"always\" otherwise)\n -\"never\" (never close).\ntrue and false are accepted as synonyms for \"graceful\" and \"never\" respectively.", diff --git a/src/cascadia/TerminalApp/CommandPalette.xaml b/src/cascadia/TerminalApp/CommandPalette.xaml index b933173c771..adc38087d8e 100644 --- a/src/cascadia/TerminalApp/CommandPalette.xaml +++ b/src/cascadia/TerminalApp/CommandPalette.xaml @@ -231,6 +231,12 @@ Glyph="" Visibility="{x:Bind Item.(local:TabPaletteItem.TabStatus).BellIndicator, Mode=OneWay}" /> + + Title() : notifArgs.Title(); - tab->TabToastNotificationRequested.raise(title, notifArgs.Body(), sender); + const auto activeContent = tab->GetActiveContent(); + const auto isActivePaneContent = activeContent && activeContent == sender; + + if (!notifArgs.AlwaysNotify() && + (!Feature_NotifyOnActivity::IsEnabled() || + (isActivePaneContent && tab->_focusState != WUX::FocusState::Unfocused))) + { + co_return; + } + + const auto style = notifArgs.Style(); + + if (WI_IsFlagSet(style, OutputNotificationStyle::Taskbar)) + { + tab->TabRaiseVisualBell.raise(); + } + + if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Audible)) + { + if (const auto termContent{ sender.try_as() }) + { + termContent.PlayNotificationSound(); + } + } + + if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Tab)) + { + tab->ShowActivityIndicator(true); + + if (tab->_focusState != WUX::FocusState::Unfocused) + { + tab->ActivateActivityIndicatorTimer(); + } + } + + if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Notification)) + { + const auto title = notifArgs.Title().empty() ? tab->Title() : notifArgs.Title(); + tab->TabToastNotificationRequested.raise(title, notifArgs.Body(), sender); + } } }); @@ -1282,11 +1350,10 @@ namespace winrt::TerminalApp::implementation const auto taskbarState = state.State(); // The progress of the control changed, but not necessarily the progress of the tab. // Set the tab's progress ring to the active pane's progress - if (taskbarState > 0) + if (taskbarState != winrt::Microsoft::Terminal::Control::TaskbarState::Clear) { - if (taskbarState == 3) + if (taskbarState == winrt::Microsoft::Terminal::Control::TaskbarState::Indeterminate) { - // 3 is the indeterminate state, set the progress ring as such _tabStatus.IsProgressRingIndeterminate(true); } else @@ -1462,6 +1529,10 @@ namespace winrt::TerminalApp::implementation { tab->ShowBellIndicator(false); } + if (tab->_tabStatus.ActivityIndicator()) + { + tab->ShowActivityIndicator(false); + } } }); diff --git a/src/cascadia/TerminalApp/Tab.h b/src/cascadia/TerminalApp/Tab.h index 3675ca5b1e5..f21d37c1132 100644 --- a/src/cascadia/TerminalApp/Tab.h +++ b/src/cascadia/TerminalApp/Tab.h @@ -48,6 +48,9 @@ namespace winrt::TerminalApp::implementation void ShowBellIndicator(const bool show); void ActivateBellIndicatorTimer(); + void ShowActivityIndicator(const bool show); + void ActivateActivityIndicatorTimer(); + float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const; std::optional PreCalculateCanSplit(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType, const float splitSize, @@ -216,6 +219,9 @@ namespace winrt::TerminalApp::implementation SafeDispatcherTimer _bellIndicatorTimer; void _BellIndicatorTimerTick(const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e); + SafeDispatcherTimer _activityIndicatorTimer; + void _ActivityIndicatorTimerTick(const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e); + void _UpdateHeaderControlMaxWidth(const winrt::Microsoft::Terminal::Settings::Model::WindowSettings& windowSettings); void _CreateContextMenu(); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index d44d7a0c7d9..83fc04f7b86 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -32,6 +32,12 @@ FontSize="12" Glyph="" Visibility="{x:Bind TabStatus.BellIndicator, Mode=OneWay}" /> + Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [weakPage{ page->get_weak() }, weakTab, weakContent]() { - if (const auto p{ weakPage.get() }) + page->Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [weakThis, weakTab, weakContent]() { + if (const auto p{ weakThis.get() }) { if (const auto t{ weakTab.get() }) { diff --git a/src/cascadia/TerminalApp/TaskbarState.cpp b/src/cascadia/TerminalApp/TaskbarState.cpp index ef9c34a75d1..e996fcba4dd 100644 --- a/src/cascadia/TerminalApp/TaskbarState.cpp +++ b/src/cascadia/TerminalApp/TaskbarState.cpp @@ -9,27 +9,28 @@ namespace winrt::TerminalApp::implementation { // Default to unset, 0%. TaskbarState::TaskbarState() : - TaskbarState(0, 0) {}; + TaskbarState(winrt::Microsoft::Terminal::Control::TaskbarState::Clear, 0) {}; - TaskbarState::TaskbarState(const uint64_t dispatchTypesState, const uint64_t progressParam) : - _State{ dispatchTypesState }, + TaskbarState::TaskbarState(const winrt::Microsoft::Terminal::Control::TaskbarState state, const uint64_t progressParam) : + _State{ state }, _Progress{ progressParam } {} uint64_t TaskbarState::Priority() const { // This seemingly nonsensical ordering is from // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate#how-the-taskbar-button-chooses-the-progress-indicator-for-a-group + using TbState = winrt::Microsoft::Terminal::Control::TaskbarState; switch (_State) { - case 0: // Clear = 0, + case TbState::Clear: return 5; - case 1: // Set = 1, + case TbState::Set: return 3; - case 2: // Error = 2, + case TbState::Error: return 1; - case 3: // Indeterminate = 3, + case TbState::Indeterminate: return 4; - case 4: // Paused = 4 + case TbState::Paused: return 2; } // Here, return 6, to definitely be greater than all the other valid values. diff --git a/src/cascadia/TerminalApp/TaskbarState.h b/src/cascadia/TerminalApp/TaskbarState.h index 36100eeec79..84b22793e83 100644 --- a/src/cascadia/TerminalApp/TaskbarState.h +++ b/src/cascadia/TerminalApp/TaskbarState.h @@ -16,13 +16,13 @@ namespace winrt::TerminalApp::implementation { public: TaskbarState(); - TaskbarState(const uint64_t dispatchTypesState, const uint64_t progress); + TaskbarState(const winrt::Microsoft::Terminal::Control::TaskbarState state, const uint64_t progress); static int ComparePriority(const winrt::TerminalApp::TaskbarState& lhs, const winrt::TerminalApp::TaskbarState& rhs); uint64_t Priority() const; - WINRT_PROPERTY(uint64_t, State, 0); + WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::TaskbarState, State, winrt::Microsoft::Terminal::Control::TaskbarState::Clear); WINRT_PROPERTY(uint64_t, Progress, 0); }; } diff --git a/src/cascadia/TerminalApp/TaskbarState.idl b/src/cascadia/TerminalApp/TaskbarState.idl index 159242a17b2..9734e5b609a 100644 --- a/src/cascadia/TerminalApp/TaskbarState.idl +++ b/src/cascadia/TerminalApp/TaskbarState.idl @@ -6,9 +6,9 @@ namespace TerminalApp [default_interface] runtimeclass TaskbarState { TaskbarState(); - TaskbarState(UInt64 dispatchTypesState, UInt64 progress); + TaskbarState(Microsoft.Terminal.Control.TaskbarState state, UInt64 progress); - UInt64 State{ get; }; + Microsoft.Terminal.Control.TaskbarState State{ get; }; UInt64 Progress{ get; }; UInt64 Priority { get; }; } diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp index bdb72c941d9..6bebe5e344d 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp +++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp @@ -10,6 +10,7 @@ #include "../../types/inc/utils.hpp" #include "BellEventArgs.g.cpp" +#include "NotificationEventArgs.g.cpp" #include "TerminalPaneContent.g.cpp" using namespace winrt::Windows::Foundation; @@ -34,6 +35,7 @@ namespace winrt::TerminalApp::implementation { _controlEvents._ConnectionStateChanged = _control.ConnectionStateChanged(winrt::auto_revoke, { this, &TerminalPaneContent::_controlConnectionStateChangedHandler }); _controlEvents._WarningBell = _control.WarningBell(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlWarningBellHandler }); + _controlEvents._PromptStarted = _control.PromptStarted(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlPromptStartedHandler }); _controlEvents._CloseTerminalRequested = _control.CloseTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_closeTerminalRequestedHandler }); _controlEvents._RestartTerminalRequested = _control.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_restartTerminalRequestedHandler }); @@ -42,6 +44,8 @@ namespace winrt::TerminalApp::implementation _controlEvents._SetTaskbarProgress = _control.SetTaskbarProgress(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlSetTaskbarProgress }); _controlEvents._ReadOnlyChanged = _control.ReadOnlyChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlReadOnlyChanged }); _controlEvents._FocusFollowMouseRequested = _control.FocusFollowMouseRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlFocusFollowMouseRequested }); + _controlEvents._OutputStarted = _control.OutputStarted(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlOutputStartedHandler }); + _controlEvents._OutputBurstEnded = _control.OutputIdle(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlOutputBurstEndedHandler }); _controlEvents._ShowNotification = _control.ShowNotification(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlShowNotification }); } void TerminalPaneContent::_removeControlEvents() @@ -162,6 +166,16 @@ namespace winrt::TerminalApp::implementation { TaskbarProgressChanged.raise(*this, nullptr); } + + winrt::Microsoft::Terminal::Control::TaskbarState TerminalPaneContent::TaskbarState() + { + return _control.TaskbarState(); + } + + uint64_t TerminalPaneContent::TaskbarProgress() + { + return _control.TaskbarProgress(); + } void TerminalPaneContent::_controlReadOnlyChanged(const IInspectable&, const IInspectable&) { ReadOnlyChanged.raise(*this, nullptr); @@ -173,7 +187,7 @@ namespace winrt::TerminalApp::implementation void TerminalPaneContent::_controlShowNotification(const IInspectable& /*sender*/, const ShowNotificationEventArgs& args) { - NotificationRequested.raise(*this, winrt::make(args.Title(), args.Body())); + NotificationRequested.raise(*this, winrt::make(OutputNotificationStyle::Notification, true /*alwaysNotify*/, args.Title(), args.Body())); } // Method Description: @@ -255,6 +269,26 @@ namespace winrt::TerminalApp::implementation // has the 'visual' flag set // Arguments: // - + void TerminalPaneContent::PlayNotificationSound() + { + if (_profile) + { + auto sounds{ _profile.BellSound() }; + if (sounds && sounds.Size() > 0) + { + // Sound paths are resolved and validated by CascadiaSettings + // before we reach this point. + auto soundPath{ sounds.GetAt(rand() % sounds.Size()).Resolved() }; + PlaySoundW(soundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC | SND_SENTRY | SND_NODEFAULT); + } + else + { + const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND); + PlaySoundW(soundAlias, nullptr, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); + } + } + } + void TerminalPaneContent::_controlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::Windows::Foundation::IInspectable& /*eventArgs*/) { @@ -266,19 +300,7 @@ namespace winrt::TerminalApp::implementation if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible)) { // Audible is set, play the sound - auto sounds{ _profile.BellSound() }; - if (sounds && sounds.Size() > 0) - { - // Sound paths are resolved and validated by CascadiaSettings - // before we reach this point. - auto soundPath{ sounds.GetAt(rand() % sounds.Size()).Resolved() }; - PlaySoundW(soundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC | SND_SENTRY | SND_NODEFAULT); - } - else - { - const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND); - PlaySoundW(soundAlias, nullptr, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); - } + PlayNotificationSound(); } if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window)) @@ -295,6 +317,67 @@ namespace winrt::TerminalApp::implementation } } + void TerminalPaneContent::_controlPromptStartedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, + const winrt::Windows::Foundation::IInspectable& /*eventArgs*/) + { + if (_profile) + { + const auto notifyStyle = _profile.NotifyOnNextPrompt(); + if (notifyStyle != OutputNotificationStyle::None) + { + if (const auto thresholdInSeconds = _profile.NotifyOnNextPromptThreshold(); thresholdInSeconds > 0) + { + if (_lastOutputStartedAt == 0) + { + return; + } + if (const auto elapsedMs = GetTickCount64() - _lastOutputStartedAt; elapsedMs < (static_cast(thresholdInSeconds) * 1000)) + { + _lastOutputStartedAt = 0; + return; + } + } + _lastOutputStartedAt = 0; + + NotificationRequested.raise(*this, + *winrt::make_self(notifyStyle, false)); + } + } + } + + void TerminalPaneContent::_controlOutputStartedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, + const winrt::Windows::Foundation::IInspectable& /*eventArgs*/) + { + _lastOutputStartedAt = GetTickCount64(); + } + + // The underlying TermControl::OutputIdle event is fired on the trailing + // edge of a 100ms-debounced output burst (see ControlCore::Initialize). + // When "notifyOnActivity" is enabled, we get one event per burst of + // output, which naturally coalesces a stream of output into a single notification. + void TerminalPaneContent::_controlOutputBurstEndedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, + const winrt::Windows::Foundation::IInspectable& /*eventArgs*/) + { + if (_profile) + { + const auto notifyStyle = _profile.NotifyOnActivity(); + if (notifyStyle != OutputNotificationStyle::None) + { + const auto now = GetTickCount64(); + const auto thresholdSeconds = _profile.NotifyOnActivityThreshold(); + if (thresholdSeconds > 0 && + _lastActivityNotificationAt != 0 && + (now - _lastActivityNotificationAt) < (static_cast(thresholdSeconds) * 1000)) + { + return; + } + _lastActivityNotificationAt = now; + + NotificationRequested.raise(*this, + *winrt::make_self(notifyStyle, false)); + } + } + } void TerminalPaneContent::_closeTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::Windows::Foundation::IInspectable& /*args*/) { diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index b04d4de9955..71f02b9580d 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -24,9 +24,11 @@ namespace winrt::TerminalApp::implementation struct NotificationEventArgs : public NotificationEventArgsT { public: - NotificationEventArgs(const winrt::hstring& title = {}, const winrt::hstring& body = {}) : - Title(title), Body(body) {} + NotificationEventArgs(winrt::Microsoft::Terminal::Control::OutputNotificationStyle style, bool alwaysNotify = true, const winrt::hstring& title = {}, const winrt::hstring& body = {}) : + Style(style), AlwaysNotify(alwaysNotify), Title(title), Body(body) {} + til::property Style; + til::property AlwaysNotify; til::property Title; til::property Body; }; @@ -49,6 +51,7 @@ namespace winrt::TerminalApp::implementation const winrt::Microsoft::Terminal::Settings::Model::WindowSettings& windowSettings); void MarkAsDefterm(); + void PlayNotificationSound(); winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const { @@ -56,8 +59,8 @@ namespace winrt::TerminalApp::implementation } winrt::hstring Title() { return _control.Title(); } - uint64_t TaskbarState() { return _control.TaskbarState(); } - uint64_t TaskbarProgress() { return _control.TaskbarProgress(); } + winrt::Microsoft::Terminal::Control::TaskbarState TaskbarState(); + uint64_t TaskbarProgress(); bool ReadOnly() { return _control.ReadOnly(); } winrt::hstring Icon() const; Windows::Foundation::IReference TabColor() const noexcept; @@ -77,10 +80,18 @@ namespace winrt::TerminalApp::implementation std::shared_ptr _cache{}; bool _isDefTermSession{ false }; + // Tracks the GetTickCount64() for NotifyOnActivityThreshold + // and NotifyOnNextPromptThreshold respectively. + uint64_t _lastActivityNotificationAt{ 0 }; + uint64_t _lastOutputStartedAt{ 0 }; + struct ControlEventTokens { winrt::Microsoft::Terminal::Control::TermControl::ConnectionStateChanged_revoker _ConnectionStateChanged; winrt::Microsoft::Terminal::Control::TermControl::WarningBell_revoker _WarningBell; + winrt::Microsoft::Terminal::Control::TermControl::PromptStarted_revoker _PromptStarted; + winrt::Microsoft::Terminal::Control::TermControl::OutputStarted_revoker _OutputStarted; + winrt::Microsoft::Terminal::Control::TermControl::OutputIdle_revoker _OutputBurstEnded; winrt::Microsoft::Terminal::Control::TermControl::CloseTerminalRequested_revoker _CloseTerminalRequested; winrt::Microsoft::Terminal::Control::TermControl::RestartTerminalRequested_revoker _RestartTerminalRequested; @@ -98,6 +109,9 @@ namespace winrt::TerminalApp::implementation safe_void_coroutine _controlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/); void _controlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& e); + void _controlPromptStartedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs); + void _controlOutputStartedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs); + void _controlOutputBurstEndedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs); void _controlReadOnlyChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& e); void _controlTitleChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args); diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.idl b/src/cascadia/TerminalApp/TerminalPaneContent.idl index 53dcf4c3379..36a1612c181 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.idl +++ b/src/cascadia/TerminalApp/TerminalPaneContent.idl @@ -11,6 +11,7 @@ namespace TerminalApp Microsoft.Terminal.Control.TermControl GetTermControl(); void MarkAsDefterm(); + void PlayNotificationSound(); Microsoft.Terminal.Settings.Model.Profile GetProfile(); diff --git a/src/cascadia/TerminalApp/TerminalTabStatus.h b/src/cascadia/TerminalApp/TerminalTabStatus.h index 8d1d015193b..81166b89ae5 100644 --- a/src/cascadia/TerminalApp/TerminalTabStatus.h +++ b/src/cascadia/TerminalApp/TerminalTabStatus.h @@ -17,6 +17,7 @@ namespace winrt::TerminalApp::implementation WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingActive, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingIndeterminate, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(bool, BellIndicator, PropertyChanged.raise); + WINRT_OBSERVABLE_PROPERTY(bool, ActivityIndicator, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(bool, IsReadOnlyActive, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(uint32_t, ProgressValue, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(bool, IsInputBroadcastActive, PropertyChanged.raise); diff --git a/src/cascadia/TerminalApp/TerminalTabStatus.idl b/src/cascadia/TerminalApp/TerminalTabStatus.idl index d5664c76c6c..f91199a632b 100644 --- a/src/cascadia/TerminalApp/TerminalTabStatus.idl +++ b/src/cascadia/TerminalApp/TerminalTabStatus.idl @@ -12,6 +12,7 @@ namespace TerminalApp Boolean IsProgressRingActive { get; set; }; Boolean IsProgressRingIndeterminate { get; set; }; Boolean BellIndicator { get; set; }; + Boolean ActivityIndicator { get; set; }; UInt32 ProgressValue { get; set; }; Boolean IsReadOnlyActive { get; set; }; Boolean IsInputBroadcastActive { get; set; }; diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index d9c1561f5ac..a93822430f9 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -138,6 +138,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation auto pfnSearchMissingCommand = [this](auto&& PH1, auto&& PH2) { _terminalSearchMissingCommand(std::forward(PH1), std::forward(PH2)); }; _terminal->SetSearchMissingCommandCallback(pfnSearchMissingCommand); + auto pfnPromptStarted = [this] { _terminalPromptStarted(); }; + _terminal->SetPromptStartedCallback(pfnPromptStarted); + + auto pfnOutputStarted = [this] { _terminalOutputStarted(); }; + _terminal->SetOutputStartedCallback(pfnOutputStarted); + auto pfnShowNotification = [this](auto&& PH1, auto&& PH2) { _terminalShowNotification(std::forward(PH1), std::forward(PH2)); }; _terminal->SetShowNotificationCallback(pfnShowNotification); @@ -974,6 +980,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation _hasUnfocusedAppearance = static_cast(newAppearance); _unfocusedAppearance = _hasUnfocusedAppearance ? newAppearance : settings; + // Cache the auto-detect setting in an atomic so the off-thread output/prompt + // callbacks can read it without synchronizing with _settings. If the effective + // taskbar state changes (because a command is currently active and the setting + // toggled), notify listeners. + const auto nowEnabled = Feature_NotifyOnActivity::IsEnabled() && _settings.AutoDetectRunningCommand(); + const auto wasEnabled = _autoDetectCommandActivity.exchange(nowEnabled, std::memory_order_relaxed); + if (wasEnabled != nowEnabled && _commandActive.load(std::memory_order_relaxed)) + { + TaskbarProgressChanged.raise(*this, nullptr); + } + { const auto lock = _terminal->LockForWriting(); @@ -1638,10 +1655,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - Gets the internal taskbar state value // Return Value: // - The taskbar state of this control - const size_t ControlCore::TaskbarState() const noexcept + const Control::TaskbarState ControlCore::TaskbarState() const noexcept { const auto lock = _terminal->LockForReading(); - return _terminal->GetTaskbarState(); + const auto vtState = static_cast(_terminal->GetTaskbarState()); + if (vtState == Control::TaskbarState::Clear && + _autoDetectCommandActivity.load(std::memory_order_relaxed) && + _commandActive.load(std::memory_order_relaxed)) + { + return Control::TaskbarState::Indeterminate; + } + return vtState; } // Method Description: @@ -1686,6 +1710,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation WarningBell.raise(*this, nullptr); } + void ControlCore::_terminalPromptStarted() + { + if (_commandActive.exchange(false, std::memory_order_relaxed) && + _autoDetectCommandActivity.load(std::memory_order_relaxed)) + { + TaskbarProgressChanged.raise(*this, nullptr); + } + PromptStarted.raise(*this, nullptr); + } + + void ControlCore::_terminalOutputStarted() + { + if (!_commandActive.exchange(true, std::memory_order_relaxed) && + _autoDetectCommandActivity.load(std::memory_order_relaxed)) + { + TaskbarProgressChanged.raise(*this, nullptr); + } + OutputStarted.raise(*this, nullptr); + } + // Method Description: // - Called for the Terminal's TitleChanged callback. This will re-raise // a new winrt TypedEvent that can be listened to. diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index b860f52d829..f7145ca45c6 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -166,7 +166,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void OpenCWD(); #pragma region ICoreState - const size_t TaskbarState() const noexcept; + const Control::TaskbarState TaskbarState() const noexcept; const size_t TaskbarProgress() const noexcept; hstring Title(); @@ -289,6 +289,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation til::typed_event TitleChanged; til::typed_event WriteToClipboard; til::typed_event<> WarningBell; + til::typed_event<> PromptStarted; + til::typed_event<> OutputStarted; til::typed_event<> TabColorChanged; til::typed_event<> BackgroundColorChanged; til::typed_event ScrollPositionChanged; @@ -338,6 +340,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation #pragma region TerminalCoreCallbacks void _terminalWarningBell(); + void _terminalPromptStarted(); + void _terminalOutputStarted(); void _terminalTitleChanged(std::wstring_view wstr); void _terminalScrollPositionChanged(const int viewTop, const int viewHeight, @@ -436,6 +440,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation std::optional _lastHoveredCell; ::Microsoft::Terminal::Core::Terminal::HyperlinkInfo _lastHoveredLink; std::atomic _initializedTerminal{ false }; + std::atomic _autoDetectCommandActivity{ false }; + std::atomic _commandActive{ false }; bool _isReadOnly{ false }; bool _closing{ false }; diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index 97c75f1ab07..99f829ca90c 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -29,6 +29,30 @@ namespace Microsoft.Terminal.Control MinGW, }; + [flags] + enum OutputNotificationStyle + { + None = 0, + Taskbar = 0x1, + Audible = 0x2, + Tab = 0x4, + Notification = 0x8, + All = 0xffffffff + }; + + // Mirrors Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState + // (which is shared with conhost and lives outside the WinRT projection). + // Values must remain numerically identical so the conversion at the + // ControlCore boundary is a 1:1 cast. + enum TaskbarState + { + Clear = 0, + Set = 1, + Error = 2, + Indeterminate = 3, + Paused = 4, + }; + // Class Description: // TerminalSettings encapsulates all settings that control the // TermControl's behavior. In these settings there is both the entirety @@ -79,6 +103,12 @@ namespace Microsoft.Terminal.Control PathTranslationStyle PathTranslationStyle { get; }; String DragDropDelimiter { get; }; + OutputNotificationStyle NotifyOnActivity { get; }; + OutputNotificationStyle NotifyOnNextPrompt { get; }; + Int32 NotifyOnActivityThreshold { get; }; + Int32 NotifyOnNextPromptThreshold { get; }; + Boolean AutoDetectRunningCommand { get; }; + // NOTE! When adding something here, make sure to update ControlProperties.h too! }; } diff --git a/src/cascadia/TerminalControl/ICoreState.idl b/src/cascadia/TerminalControl/ICoreState.idl index 48a8e4a43c8..bc0a88e9347 100644 --- a/src/cascadia/TerminalControl/ICoreState.idl +++ b/src/cascadia/TerminalControl/ICoreState.idl @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import "IControlSettings.idl"; + namespace Microsoft.Terminal.Control { enum MarkCategory @@ -31,7 +33,7 @@ namespace Microsoft.Terminal.Control interface ICoreState { String Title { get; }; - UInt64 TaskbarState { get; }; + Microsoft.Terminal.Control.TaskbarState TaskbarState { get; }; UInt64 TaskbarProgress { get; }; String WorkingDirectory { get; }; diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 0f3ba0e705e..75890a438e4 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -413,6 +413,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation // attached content before we set up the throttled func, and that'll A/V _revokers.coreScrollPositionChanged = _core->ScrollPositionChanged(winrt::auto_revoke, { get_weak(), &TermControl::_ScrollPositionChanged }); _revokers.WarningBell = _core->WarningBell(winrt::auto_revoke, { get_weak(), &TermControl::_coreWarningBell }); + _revokers.PromptStarted = _core->PromptStarted(winrt::auto_revoke, { get_weak(), &TermControl::_corePromptStarted }); + _revokers.OutputStarted = _core->OutputStarted(winrt::auto_revoke, { get_weak(), &TermControl::_coreOutputStarted }); _ApplyUISettings(); @@ -3257,7 +3259,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - Gets the internal taskbar state value // Return Value: // - The taskbar state of this control - const uint64_t TermControl::TaskbarState() const noexcept + const Control::TaskbarState TermControl::TaskbarState() const noexcept { return _core->TaskbarState(); } @@ -3627,6 +3629,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation _playWarningBell->Run(); } + void TermControl::_corePromptStarted(const IInspectable& /*sender*/, const IInspectable& /*args*/) + { + PromptStarted.raise(*this, nullptr); + } + + void TermControl::_coreOutputStarted(const IInspectable& /*sender*/, const IInspectable& /*args*/) + { + OutputStarted.raise(*this, nullptr); + } + hstring TermControl::ReadEntireBuffer() const { return _core->ReadEntireBuffer(); @@ -3744,6 +3756,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void TermControl::_coreOutputIdle(const IInspectable& /*sender*/, const IInspectable& /*args*/) { _refreshSearch(); + OutputIdle.raise(*this, nullptr); } void TermControl::OwningHwnd(uint64_t owner) diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 71af8d691a1..d0fccd1fd5c 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -92,7 +92,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void ColorSelection(Control::SelectionColor fg, Control::SelectionColor bg, Core::MatchMode matchMode); #pragma region ICoreState - const uint64_t TaskbarState() const noexcept; + const Control::TaskbarState TaskbarState() const noexcept; const uint64_t TaskbarProgress() const noexcept; hstring Title(); @@ -218,6 +218,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation til::typed_event FocusFollowMouseRequested; til::typed_event Initialized; til::typed_event<> WarningBell; + til::typed_event<> PromptStarted; + til::typed_event<> OutputStarted; + til::typed_event<> OutputIdle; til::typed_event KeySent; til::typed_event CharSent; til::typed_event StringSent; @@ -421,6 +424,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation void _coreTransparencyChanged(IInspectable sender, Control::TransparencyChangedEventArgs args); void _coreRaisedNotice(const IInspectable& s, const Control::NoticeEventArgs& args); void _coreWarningBell(const IInspectable& sender, const IInspectable& args); + void _corePromptStarted(const IInspectable& sender, const IInspectable& args); + void _coreOutputStarted(const IInspectable& sender, const IInspectable& args); void _coreOutputIdle(const IInspectable& sender, const IInspectable& args); winrt::Windows::Foundation::Point _toPosInDips(const Core::Point terminalCellPos); @@ -444,6 +449,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation { til::event_revoker coreScrollPositionChanged; til::event_revoker WarningBell; + til::event_revoker PromptStarted; + til::event_revoker OutputStarted; til::event_revoker RendererEnteredErrorState; til::event_revoker BackgroundColorChanged; til::event_revoker FontSizeChanged; diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index 4c51342c3a1..d6dabae34c9 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -88,6 +88,9 @@ namespace Microsoft.Terminal.Control event Windows.Foundation.TypedEventHandler SetTaskbarProgress; event Windows.Foundation.TypedEventHandler RaiseNotice; event Windows.Foundation.TypedEventHandler WarningBell; + event Windows.Foundation.TypedEventHandler PromptStarted; + event Windows.Foundation.TypedEventHandler OutputStarted; + event Windows.Foundation.TypedEventHandler OutputIdle; event Windows.Foundation.TypedEventHandler HidePointerCursor; event Windows.Foundation.TypedEventHandler RestorePointerCursor; event Windows.Foundation.TypedEventHandler TabColorChanged; diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 7948a9878fb..f4641066e45 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -793,6 +793,11 @@ TerminalInput::OutputType Terminal::SendCharEvent(const wchar_t ch, const WORD s // This changed the scrollbar marks - raise a notification to update them _NotifyScrollEvent(); } + // regardless, notify that we started command output + if (_pfnOutputStarted) + { + _pfnOutputStarted(); + } } } @@ -1278,7 +1283,7 @@ const std::optional Terminal::GetTabColor() const // - Gets the internal taskbar state value // Return Value: // - The taskbar state -const size_t Microsoft::Terminal::Core::Terminal::GetTaskbarState() const noexcept +const Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState Microsoft::Terminal::Core::Terminal::GetTaskbarState() const noexcept { return _taskbarState; } @@ -1312,6 +1317,16 @@ void Microsoft::Terminal::Core::Terminal::SetClearQuickFixCallback(std::function _pfnClearQuickFix.swap(pfn); } +void Terminal::SetPromptStartedCallback(std::function pfn) noexcept +{ + _pfnPromptStarted.swap(pfn); +} + +void Terminal::SetOutputStartedCallback(std::function pfn) noexcept +{ + _pfnOutputStarted.swap(pfn); +} + // Method Description: // - Stores the search highlighted regions in the terminal void Terminal::SetSearchHighlights(const std::vector& highlights) noexcept diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 7df5480a0a7..0aceb963fd9 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -170,7 +170,7 @@ class Microsoft::Terminal::Core::Terminal final : bool IsVtInputEnabled() const noexcept override; void NotifyBufferRotation(const int delta) override; - void NotifyShellIntegrationMark() override; + void NotifyShellIntegrationMark(ShellIntegrationMark mark) override; void InvokeCompletions(std::wstring_view menuJson, unsigned int replaceLength) override; @@ -248,6 +248,8 @@ class Microsoft::Terminal::Core::Terminal final : void SetShowNotificationCallback(std::function pfn) noexcept; void SetClearQuickFixCallback(std::function pfn) noexcept; void SetWindowSizeChangedCallback(std::function pfn) noexcept; + void SetPromptStartedCallback(std::function pfn) noexcept; + void SetOutputStartedCallback(std::function pfn) noexcept; void SetSearchHighlights(const std::vector& highlights) noexcept; void SetSearchHighlightFocused(size_t focusedIdx) noexcept; void ScrollToSearchHighlight(til::CoordType searchScrollOffset); @@ -256,7 +258,7 @@ class Microsoft::Terminal::Core::Terminal final : const std::optional GetTabColor() const; - const size_t GetTaskbarState() const noexcept; + const ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState GetTaskbarState() const noexcept; const size_t GetTaskbarProgress() const noexcept; void ColorSelection(const TextAttribute& attr, winrt::Microsoft::Terminal::Core::MatchMode matchMode); @@ -357,6 +359,8 @@ class Microsoft::Terminal::Core::Terminal final : std::function _pfnShowNotification; std::function _pfnClearQuickFix; std::function _pfnWindowSizeChanged; + std::function _pfnPromptStarted; + std::function _pfnOutputStarted; RenderSettings _renderSettings; std::unique_ptr<::Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine; @@ -378,6 +382,9 @@ class Microsoft::Terminal::Core::Terminal final : til::enumset _systemMode{ Mode::AutoWrap }; + ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState _taskbarState{ ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState::Clear }; + size_t _taskbarProgress = 0; + bool _focused = false; bool _snapOnInput = true; bool _altGrAliasing = true; @@ -386,9 +393,6 @@ class Microsoft::Terminal::Core::Terminal final : bool _autoMarkPrompts = false; bool _rainbowSuggestions = false; - size_t _taskbarState = 0; - size_t _taskbarProgress = 0; - size_t _hyperlinkPatternId = 0; std::wstring _answerbackMessage; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 627a5d68650..c7c80b2d388 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -173,7 +173,7 @@ void Terminal::SetTaskbarProgress(const ::Microsoft::Console::VirtualTerminal::D { _assertLocked(); - _taskbarState = static_cast(state); + _taskbarState = state; switch (state) { @@ -428,8 +428,26 @@ void Terminal::NotifyBufferRotation(const int delta) } } -void Terminal::NotifyShellIntegrationMark() +void Terminal::NotifyShellIntegrationMark(ShellIntegrationMark mark) { // Notify the scrollbar that marks have been added so it can refresh the mark indicators _NotifyScrollEvent(); + + switch (mark) + { + case ShellIntegrationMark::Prompt: + if (_pfnPromptStarted) + { + _pfnPromptStarted(); + } + break; + case ShellIntegrationMark::Output: + if (_pfnOutputStarted) + { + _pfnOutputStarted(); + } + break; + default: + break; + } } diff --git a/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp b/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp index 44b363f3c68..067f7f34af4 100644 --- a/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp @@ -374,6 +374,11 @@ namespace winrt::Microsoft::Terminal::Settings _AllowOscNotifications = profile.AllowOscNotifications(); _PathTranslationStyle = profile.PathTranslationStyle(); _DragDropDelimiter = profile.DragDropDelimiter(); + _NotifyOnActivity = profile.NotifyOnActivity(); + _NotifyOnNextPrompt = profile.NotifyOnNextPrompt(); + _NotifyOnActivityThreshold = profile.NotifyOnActivityThreshold(); + _NotifyOnNextPromptThreshold = profile.NotifyOnNextPromptThreshold(); + _AutoDetectRunningCommand = profile.AutoDetectRunningCommand(); } // Method Description: diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp index e44c2d834b3..8a8bf5f9aec 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp @@ -116,6 +116,22 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _NotifyChanges(L"CurrentPathTranslationStyle"); } + else if (viewModelProperty == L"NotifyOnActivity") + { + _NotifyChanges(L"IsNotifyOnActivityFlagSet", L"NotifyOnActivityPreview"); + } + else if (viewModelProperty == L"NotifyOnActivityPreview") + { + _NotifyChanges(L"NotifyOnActivityAccessibleName"); + } + else if (viewModelProperty == L"NotifyOnNextPrompt") + { + _NotifyChanges(L"IsNotifyOnNextPromptFlagSet", L"NotifyOnNextPromptPreview"); + } + else if (viewModelProperty == L"NotifyOnNextPromptPreview") + { + _NotifyChanges(L"NotifyOnNextPromptAccessibleName"); + } else if (viewModelProperty == L"Padding") { _parsedPadding = StringToXamlThickness(_profile.Padding()); @@ -439,7 +455,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } #define PROFILE_COUNT(target, name) +1 - static_assert(0 PROFILE_INHERITABLE_SETTINGS(PROFILE_COUNT) == 36, + static_assert(0 PROFILE_INHERITABLE_SETTINGS(PROFILE_COUNT) == 41, "The set of inheritable profile settings changed. Update this count, then make " "sure the new/removed setting is also reflected in ProfileViewModel.idl and in the " "XAML reset buttons."); @@ -682,6 +698,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation return iconPath.empty() || iconPath == IconPicker::HideIconValue; } +#pragma region BellStyle hstring ProfileViewModel::BellStylePreview() const { const auto bellStyle = BellStyle(); @@ -766,6 +783,157 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WI_UpdateFlag(currentStyle, Model::BellStyle::Notification, winrt::unbox_value(on)); BellStyle(currentStyle); } +#pragma endregion + +#pragma region NotifyOnActivity + hstring ProfileViewModel::NotifyOnActivityPreview() const + { + using Ons = Control::OutputNotificationStyle; + const auto style = NotifyOnActivity(); + if (WI_AreAllFlagsSet(style, Ons::Taskbar | Ons::Audible | Ons::Tab | Ons::Notification)) + { + return RS_(L"Profile_OutputNotificationStyleAll/Content"); + } + else if (style == Ons::None) + { + return RS_(L"Profile_OutputNotificationStyleNone/Content"); + } + + std::wstring result; + const auto appendIfFlagSet = [&](Ons flag, std::wstring_view resource) { + // WI_IsFlagSet requires a compile-time constant flag; `flag` is a runtime parameter here. + if ((WI_EnumValue(style) & WI_EnumValue(flag)) != 0) + { + if (!result.empty()) + { + result.append(L", "); + } + result.append(resource); + } + }; + + appendIfFlagSet(Ons::Taskbar, RS_(L"Profile_OutputNotificationStyleTaskbar/Content")); + appendIfFlagSet(Ons::Audible, RS_(L"Profile_OutputNotificationStyleAudible/Content")); + appendIfFlagSet(Ons::Tab, RS_(L"Profile_OutputNotificationStyleTab/Content")); + appendIfFlagSet(Ons::Notification, RS_(L"Profile_OutputNotificationStyleNotification/Content")); + + return hstring{ result }; + } + + hstring ProfileViewModel::NotifyOnActivityAccessibleName() const + { + return FormatAccessibleName(USES_RESOURCE(L"Profile_NotifyOnActivity/Header"), NotifyOnActivityPreview()); + } + + bool ProfileViewModel::IsNotifyOnActivityFlagSet(const uint32_t flag) + { + return (WI_EnumValue(NotifyOnActivity()) & flag) == flag; + } + + void ProfileViewModel::SetNotifyOnActivityTaskbar(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnActivity(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Taskbar, winrt::unbox_value(on)); + NotifyOnActivity(currentStyle); + } + + void ProfileViewModel::SetNotifyOnActivityAudible(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnActivity(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Audible, winrt::unbox_value(on)); + NotifyOnActivity(currentStyle); + } + + void ProfileViewModel::SetNotifyOnActivityTab(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnActivity(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Tab, winrt::unbox_value(on)); + NotifyOnActivity(currentStyle); + } + + void ProfileViewModel::SetNotifyOnActivityNotification(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnActivity(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Notification, winrt::unbox_value(on)); + NotifyOnActivity(currentStyle); + } +#pragma endregion + +#pragma region NotifyOnNextPrompt + hstring ProfileViewModel::NotifyOnNextPromptPreview() const + { + using Ons = Control::OutputNotificationStyle; + const auto style = NotifyOnNextPrompt(); + if (WI_AreAllFlagsSet(style, Ons::Taskbar | Ons::Audible | Ons::Tab | Ons::Notification)) + { + return RS_(L"Profile_OutputNotificationStyleAll/Content"); + } + else if (style == Ons::None) + { + return RS_(L"Profile_OutputNotificationStyleNone/Content"); + } + + std::wstring result; + const auto appendIfFlagSet = [&](Ons flag, std::wstring_view resource) { + // WI_IsFlagSet requires a compile-time constant flag; `flag` is a runtime parameter here. + if ((WI_EnumValue(style) & WI_EnumValue(flag)) != 0) + { + if (!result.empty()) + { + result.append(L", "); + } + result.append(resource); + } + }; + + appendIfFlagSet(Ons::Taskbar, RS_(L"Profile_OutputNotificationStyleTaskbar/Content")); + appendIfFlagSet(Ons::Audible, RS_(L"Profile_OutputNotificationStyleAudible/Content")); + appendIfFlagSet(Ons::Tab, RS_(L"Profile_OutputNotificationStyleTab/Content")); + appendIfFlagSet(Ons::Notification, RS_(L"Profile_OutputNotificationStyleNotification/Content")); + + return hstring{ result }; + } + + hstring ProfileViewModel::NotifyOnNextPromptAccessibleName() const + { + return FormatAccessibleName(USES_RESOURCE(L"Profile_NotifyOnNextPrompt/Header"), NotifyOnNextPromptPreview()); + } + + bool ProfileViewModel::IsNotifyOnNextPromptFlagSet(const uint32_t flag) + { + return (WI_EnumValue(NotifyOnNextPrompt()) & flag) == flag; + } + + void ProfileViewModel::SetNotifyOnNextPromptTaskbar(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnNextPrompt(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Taskbar, winrt::unbox_value(on)); + NotifyOnNextPrompt(currentStyle); + } + + void ProfileViewModel::SetNotifyOnNextPromptAudible(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnNextPrompt(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Audible, winrt::unbox_value(on)); + NotifyOnNextPrompt(currentStyle); + } + + void ProfileViewModel::SetNotifyOnNextPromptTab(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnNextPrompt(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Tab, winrt::unbox_value(on)); + NotifyOnNextPrompt(currentStyle); + } + + void ProfileViewModel::SetNotifyOnNextPromptNotification(winrt::Windows::Foundation::IReference on) + { + auto currentStyle = NotifyOnNextPrompt(); + WI_UpdateFlag(currentStyle, Control::OutputNotificationStyle::Notification, winrt::unbox_value(on)); + NotifyOnNextPrompt(currentStyle); + } +#pragma endregion + +#pragma region BellSound // Method Description: // - Construct _CurrentBellSounds by importing the _inherited_ value from the model @@ -909,6 +1077,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _NotifyChanges(L"CurrentBellSounds"); } } +#pragma endregion void ProfileViewModel::DeleteProfile() { diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h index 6d92f4ad0e3..e52252c91f8 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h @@ -50,6 +50,24 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void SetBellStyleTaskbar(winrt::Windows::Foundation::IReference on); void SetBellStyleNotification(winrt::Windows::Foundation::IReference on); + // notify on activity bits + hstring NotifyOnActivityPreview() const; + hstring NotifyOnActivityAccessibleName() const; + bool IsNotifyOnActivityFlagSet(const uint32_t flag); + void SetNotifyOnActivityTaskbar(winrt::Windows::Foundation::IReference on); + void SetNotifyOnActivityAudible(winrt::Windows::Foundation::IReference on); + void SetNotifyOnActivityTab(winrt::Windows::Foundation::IReference on); + void SetNotifyOnActivityNotification(winrt::Windows::Foundation::IReference on); + + // notify on next prompt bits + hstring NotifyOnNextPromptPreview() const; + hstring NotifyOnNextPromptAccessibleName() const; + bool IsNotifyOnNextPromptFlagSet(const uint32_t flag); + void SetNotifyOnNextPromptTaskbar(winrt::Windows::Foundation::IReference on); + void SetNotifyOnNextPromptAudible(winrt::Windows::Foundation::IReference on); + void SetNotifyOnNextPromptTab(winrt::Windows::Foundation::IReference on); + void SetNotifyOnNextPromptNotification(winrt::Windows::Foundation::IReference on); + hstring BellSoundPreview(); hstring BellSoundAccessibleName(); void RequestAddBellSound(hstring path); @@ -166,7 +184,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation X(_profile, AnswerbackMessage) \ X(_profile, RainbowSuggestions) \ X(_profile, PathTranslationStyle) \ - X(_profile, DragDropDelimiter) + X(_profile, DragDropDelimiter) \ + X(_profile, NotifyOnActivity) \ + X(_profile, NotifyOnNextPrompt) \ + X(_profile, NotifyOnActivityThreshold) \ + X(_profile, NotifyOnNextPromptThreshold) \ + X(_profile, AutoDetectRunningCommand) + // Generate the projected property accessors from the list above. #define PROFILE_GEN_PROJECTED(target, name) OBSERVABLE_PROJECTED_SETTING(target, name); diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl index e3ace53c77c..ed848bec2cb 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl @@ -53,6 +53,22 @@ namespace Microsoft.Terminal.Settings.Editor void SetBellStyleTaskbar(Windows.Foundation.IReference on); void SetBellStyleNotification(Windows.Foundation.IReference on); + String NotifyOnActivityPreview { get; }; + String NotifyOnActivityAccessibleName { get; }; + Boolean IsNotifyOnActivityFlagSet(UInt32 flag); + void SetNotifyOnActivityTaskbar(Windows.Foundation.IReference on); + void SetNotifyOnActivityAudible(Windows.Foundation.IReference on); + void SetNotifyOnActivityTab(Windows.Foundation.IReference on); + void SetNotifyOnActivityNotification(Windows.Foundation.IReference on); + + String NotifyOnNextPromptPreview { get; }; + String NotifyOnNextPromptAccessibleName { get; }; + Boolean IsNotifyOnNextPromptFlagSet(UInt32 flag); + void SetNotifyOnNextPromptTaskbar(Windows.Foundation.IReference on); + void SetNotifyOnNextPromptAudible(Windows.Foundation.IReference on); + void SetNotifyOnNextPromptTab(Windows.Foundation.IReference on); + void SetNotifyOnNextPromptNotification(Windows.Foundation.IReference on); + String BellSoundPreview { get; }; String BellSoundAccessibleName { get; }; Windows.Foundation.Collections.IObservableVector CurrentBellSounds { get; }; @@ -152,5 +168,10 @@ namespace Microsoft.Terminal.Settings.Editor OBSERVABLE_PROJECTED_PROFILE_SETTING(String, DragDropDelimiter); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtClipboardWrite); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowOscNotifications); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Control.OutputNotificationStyle, NotifyOnActivity); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Control.OutputNotificationStyle, NotifyOnNextPrompt); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Int32, NotifyOnActivityThreshold); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Int32, NotifyOnNextPromptThreshold); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AutoDetectRunningCommand); } } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.cpp b/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.cpp index a6a6ee1f921..3533b7ff0a7 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.cpp +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.cpp @@ -20,6 +20,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { InitializeComponent(); + if (!Feature_NotifyOnActivity::IsEnabled()) + { + NotifyOnActivity().Visibility(Visibility::Collapsed); + NotifyOnActivityThreshold().Visibility(Visibility::Collapsed); + NotifyOnNextPrompt().Visibility(Visibility::Collapsed); + NotifyOnNextPromptThreshold().Visibility(Visibility::Collapsed); + AutoDetectRunningCommand().Visibility(Visibility::Collapsed); + } + Automation::AutomationProperties::SetName(AddBellSoundButton(), RS_(L"Profile_AddBellSound/Text")); // The XAML -> C++ converter seems to use floats instead of doubles, which means it diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml b/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml index a0bcbf24ba7..5cff8dfb0fa 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml @@ -229,6 +229,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Flash window An option to choose from for the "bell style" setting. When selected, a visual notification is used to notify the user. In this case, the window is flashed. + + None + An option to choose from for the notification style setting. When selected, no notification is sent. + + + All + An option to choose from for the notification style setting. When selected, all notification methods are used. + + + Flash taskbar + An option to choose from for the notification style setting. Flashes the taskbar icon. + + + Play sound + An option to choose from for the notification style setting. Plays an audible notification sound. + + + Show tab indicator + An option to choose from for the notification style setting. Shows an activity indicator on the tab. + + + Desktop notification + An option to choose from for the notification style setting. Sends a Windows desktop notification (toast). + + + Notify on activity + Header for a control to set the notification style when a background tab has new activity (output). + + + Choose how to be notified when a background tab produces new output. + Help text for the notify on activity setting. + + + Minimum seconds between activity notifications + Header for a numeric control that sets the minimum number of seconds between consecutive "notify on activity" notifications. Useful for chatty programs. + + + Suppress repeated activity notifications within this many seconds of the previous one. Set to 0 to always notify. + Help text for the minimum duration threshold applied to "notify on activity" notifications. + + + Notify on next prompt + Header for a control to set the notification style when a new shell prompt is detected (requires shell integration). + + + Choose how to be notified when a command finishes and a new prompt appears. Requires shell integration. + Help text for the notify on next prompt setting. + + + Minimum duration for the next prompt notification + Header for a numeric control that sets the minimum number of seconds a command must run before its completion triggers a "notify on next prompt" notification. + + + Only notify when the command ran for at least this many seconds. Requires shell integration. Set to 0 to always notify. + Help text for the minimum duration threshold applied to "notify on next prompt" notifications. + + + Auto-detect running command + Header for a control to configure automatic detection of a running command's progress state. + + + Automatically show a progress indicator when a command is running. Requires shell integration. + Help text for the auto-detect running command setting. + Desktop notification An option to choose from for the "bell style" setting. When selected, a Windows desktop notification (toast) is sent to notify the user. diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index 6757c757574..fe454b7f195 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -91,40 +91,45 @@ Author(s): // * TerminalSettings.cpp: TerminalSettings::_ApplyProfileSettings // * IControlSettings.idl or ICoreSettings.idl // * ControlProperties.h -#define MTSM_PROFILE_SETTINGS(X) \ - X(bool, CursorBlinking, "cursorBlinking", true) \ - X(int32_t, HistorySize, "historySize", DEFAULT_HISTORY_SIZE) \ - X(bool, SnapOnInput, "snapOnInput", true) \ - X(bool, AltGrAliasing, "altGrAliasing", true) \ - X(hstring, AnswerbackMessage, "answerbackMessage") \ - X(hstring, Commandline, "commandline", L"%SystemRoot%\\System32\\cmd.exe") \ - X(Microsoft::Terminal::Control::ScrollbarState, ScrollState, "scrollbarState", Microsoft::Terminal::Control::ScrollbarState::Visible) \ - X(Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, "antialiasingMode", Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale) \ - X(hstring, StartingDirectory, "startingDirectory") \ - X(IMediaResource, Icon, "icon", implementation::MediaResource::FromString(L"\uE756")) \ - X(bool, SuppressApplicationTitle, "suppressApplicationTitle", false) \ - X(guid, ConnectionType, "connectionType") \ - X(CloseOnExitMode, CloseOnExit, "closeOnExit", CloseOnExitMode::Automatic) \ - X(hstring, TabTitle, "tabTitle") \ - X(Model::BellStyle, BellStyle, "bellStyle", BellStyle::Audible) \ - X(IEnvironmentVariableMap, EnvironmentVariables, "environment", nullptr) \ - X(bool, RightClickContextMenu, "rightClickContextMenu", false) \ - X(Windows::Foundation::Collections::IVector, BellSound, "bellSound", nullptr) \ - X(bool, Elevate, "elevate", false) \ - X(bool, AutoMarkPrompts, "autoMarkPrompts", true) \ - X(bool, ShowMarks, "showMarksOnScrollbar", false) \ - X(bool, RepositionCursorWithMouse, "experimental.repositionCursorWithMouse", false) \ - X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \ - X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \ - X(bool, ForceVTInput, "compatibility.input.forceVT", false) \ - X(bool, AllowKittyKeyboardMode, "compatibility.kittyKeyboardMode", true) \ - X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \ - X(bool, AllowVtCursorBlinking, "compatibility.allowCursorBlinking", true) \ - X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \ - X(bool, AllowOscNotifications, "compatibility.allowOSC777", false) \ - X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \ - X(hstring, DragDropDelimiter, "dragDropDelimiter", L" ") \ - X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None) +#define MTSM_PROFILE_SETTINGS(X) \ + X(bool, CursorBlinking, "cursorBlinking", true) \ + X(int32_t, HistorySize, "historySize", DEFAULT_HISTORY_SIZE) \ + X(bool, SnapOnInput, "snapOnInput", true) \ + X(bool, AltGrAliasing, "altGrAliasing", true) \ + X(hstring, AnswerbackMessage, "answerbackMessage") \ + X(hstring, Commandline, "commandline", L"%SystemRoot%\\System32\\cmd.exe") \ + X(Microsoft::Terminal::Control::ScrollbarState, ScrollState, "scrollbarState", Microsoft::Terminal::Control::ScrollbarState::Visible) \ + X(Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, "antialiasingMode", Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale) \ + X(hstring, StartingDirectory, "startingDirectory") \ + X(IMediaResource, Icon, "icon", implementation::MediaResource::FromString(L"\uE756")) \ + X(bool, SuppressApplicationTitle, "suppressApplicationTitle", false) \ + X(guid, ConnectionType, "connectionType") \ + X(CloseOnExitMode, CloseOnExit, "closeOnExit", CloseOnExitMode::Automatic) \ + X(hstring, TabTitle, "tabTitle") \ + X(Model::BellStyle, BellStyle, "bellStyle", BellStyle::Audible) \ + X(IEnvironmentVariableMap, EnvironmentVariables, "environment", nullptr) \ + X(bool, RightClickContextMenu, "rightClickContextMenu", false) \ + X(Windows::Foundation::Collections::IVector, BellSound, "bellSound", nullptr) \ + X(bool, Elevate, "elevate", false) \ + X(bool, AutoMarkPrompts, "autoMarkPrompts", true) \ + X(bool, ShowMarks, "showMarksOnScrollbar", false) \ + X(bool, RepositionCursorWithMouse, "experimental.repositionCursorWithMouse", false) \ + X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \ + X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \ + X(bool, ForceVTInput, "compatibility.input.forceVT", false) \ + X(bool, AllowKittyKeyboardMode, "compatibility.kittyKeyboardMode", true) \ + X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \ + X(bool, AllowVtCursorBlinking, "compatibility.allowCursorBlinking", true) \ + X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \ + X(bool, AllowOscNotifications, "compatibility.allowOSC777", false) \ + X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \ + X(hstring, DragDropDelimiter, "dragDropDelimiter", L" ") \ + X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None) \ + X(Microsoft::Terminal::Control::OutputNotificationStyle, NotifyOnActivity, "notifyOnActivity", Microsoft::Terminal::Control::OutputNotificationStyle::None) \ + X(Microsoft::Terminal::Control::OutputNotificationStyle, NotifyOnNextPrompt, "notifyOnNextPrompt", Microsoft::Terminal::Control::OutputNotificationStyle::None) \ + X(int32_t, NotifyOnActivityThreshold, "notifyOnActivityThreshold", 5) \ + X(int32_t, NotifyOnNextPromptThreshold, "notifyOnNextPromptThreshold", 5) \ + X(bool, AutoDetectRunningCommand, "autoDetectRunningCommand", false) // Intentionally omitted Profile settings: // * Name diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index a8b77fef360..9e54a758ce2 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -99,5 +99,10 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.PathTranslationStyle, PathTranslationStyle); INHERITABLE_PROFILE_SETTING(String, DragDropDelimiter); + INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.OutputNotificationStyle, NotifyOnActivity); + INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.OutputNotificationStyle, NotifyOnNextPrompt); + INHERITABLE_PROFILE_SETTING(Int32, NotifyOnActivityThreshold); + INHERITABLE_PROFILE_SETTING(Int32, NotifyOnNextPromptThreshold); + INHERITABLE_PROFILE_SETTING(Boolean, AutoDetectRunningCommand); } } diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index 61bcf7243a7..b4efb4561f8 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -139,6 +139,37 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::BellStyle) } }; +JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Control::OutputNotificationStyle) +{ + static constexpr std::array mappings = { + pair_type{ "none", AllClear }, + pair_type{ "taskbar", ValueType::Taskbar }, + pair_type{ "audible", ValueType::Audible }, + pair_type{ "tab", ValueType::Tab }, + pair_type{ "notification", ValueType::Notification }, + pair_type{ "all", AllSet }, + }; + + auto FromJson(const Json::Value& json) + { + if (json.isBool()) + { + return json.asBool() ? ValueType::Tab : AllClear; + } + return BaseFlagMapper::FromJson(json); + } + + bool CanConvert(const Json::Value& json) + { + return BaseFlagMapper::CanConvert(json) || json.isBool(); + } + + Json::Value ToJson(const ::winrt::Microsoft::Terminal::Control::OutputNotificationStyle& style) + { + return BaseFlagMapper::ToJson(style); + } +}; + JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::ConvergedAlignment) { // reduce repetition diff --git a/src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp b/src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp index da3d2b1eb3b..86c33e23fbf 100644 --- a/src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp +++ b/src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp @@ -381,66 +381,68 @@ void TerminalCoreUnitTests::TerminalApiTest::SetTaskbarProgress() auto& stateMachine = *(term._stateMachine); + using TaskbarState = ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState; + // Initial values for taskbar state and progress should be 0 - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(0)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Clear); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(0)); // Set some values for taskbar state and progress through state machine stateMachine.ProcessString(L"\x1b]9;4;1;50\x1b\\"); - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(1)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Set); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(50)); // Reset to 0 stateMachine.ProcessString(L"\x1b]9;4;0;0\x1b\\"); - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(0)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Clear); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(0)); // Set an out of bounds value for state stateMachine.ProcessString(L"\x1b]9;4;5;50\x1b\\"); // Nothing should have changed (dispatch should have returned false) - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(0)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Clear); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(0)); // Set an out of bounds value for progress stateMachine.ProcessString(L"\x1b]9;4;1;999\x1b\\"); // Progress should have been clamped to 100 - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(1)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Set); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(100)); // Don't specify any params stateMachine.ProcessString(L"\x1b]9;4\x1b\\"); // State and progress should both be reset to 0 - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(0)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Clear); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(0)); // Specify additional params stateMachine.ProcessString(L"\x1b]9;4;1;80;123\x1b\\"); // Additional params should be ignored, state and progress still set normally - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(1)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Set); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(80)); // Edge cases + trailing semicolon testing stateMachine.ProcessString(L"\x1b]9;4;2;\x1b\\"); // String should be processed correctly despite the trailing semicolon, // taskbar progress should remain unchanged from previous value - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(2)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Error); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(80)); stateMachine.ProcessString(L"\x1b]9;4;3;75\x1b\\"); // Given progress value should be ignored because this is the indeterminate state, // so the progress value should remain unchanged - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(3)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Indeterminate); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(80)); stateMachine.ProcessString(L"\x1b]9;4;0;50\x1b\\"); // Taskbar progress should be 0 (the given value should be ignored) - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(0)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Clear); VERIFY_ARE_EQUAL(term.GetTaskbarProgress(), gsl::narrow(0)); stateMachine.ProcessString(L"\x1b]9;4;2;\x1b\\"); // String should be processed correctly despite the trailing semicolon, // taskbar progress should be set to a 'minimum', non-zero value - VERIFY_ARE_EQUAL(term.GetTaskbarState(), gsl::narrow(2)); + VERIFY_ARE_EQUAL(term.GetTaskbarState(), TaskbarState::Error); VERIFY_IS_GREATER_THAN(term.GetTaskbarProgress(), gsl::narrow(0)); } diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 2ef1cece1fe..1a855101b9a 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -106,7 +106,7 @@ void AppHost::SetTaskbarProgress(const winrt::Windows::Foundation::IInspectable& if (_windowLogic) { const auto state = _windowLogic.TaskbarState(); - _window->SetTaskbarProgress(gsl::narrow_cast(state.State()), + _window->SetTaskbarProgress(state.State(), gsl::narrow_cast(state.Progress())); } } diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index e627bd44957..c78f9d1d929 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -930,27 +930,28 @@ void IslandWindow::FlashTaskbar() // Arguments: // - state: indicates the progress state // - progress: indicates the progress value -void IslandWindow::SetTaskbarProgress(const size_t state, const size_t progress) +void IslandWindow::SetTaskbarProgress(const winrt::Microsoft::Terminal::Control::TaskbarState state, const size_t progress) { if (_taskbar) { + using TbState = winrt::Microsoft::Terminal::Control::TaskbarState; switch (state) { - case 0: + case TbState::Clear: // removes the taskbar progress indicator _taskbar->SetProgressState(_window.get(), TBPF_NOPROGRESS); break; - case 1: + case TbState::Set: // sets the progress value to value given by the 'progress' parameter _taskbar->SetProgressState(_window.get(), TBPF_NORMAL); _taskbar->SetProgressValue(_window.get(), progress, 100); break; - case 2: + case TbState::Error: // sets the progress indicator to an error state _taskbar->SetProgressState(_window.get(), TBPF_ERROR); _taskbar->SetProgressValue(_window.get(), progress, 100); break; - case 3: + case TbState::Indeterminate: // sets the progress indicator to an indeterminate state. // FIRST, set the progress to "no progress". That'll clear out any // progress value from the previous state. Otherwise, a transition @@ -959,7 +960,7 @@ void IslandWindow::SetTaskbarProgress(const size_t state, const size_t progress) _taskbar->SetProgressState(_window.get(), TBPF_NOPROGRESS); _taskbar->SetProgressState(_window.get(), TBPF_INDETERMINATE); break; - case 4: + case TbState::Paused: // sets the progress indicator to a pause state _taskbar->SetProgressState(_window.get(), TBPF_PAUSED); _taskbar->SetProgressValue(_window.get(), progress, 100); diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index 83afeaf44f5..439e4d9a0b6 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -53,7 +53,7 @@ class IslandWindow : virtual void SetShowTabsFullscreen(const bool newShowTabsFullscreen); void FlashTaskbar(); - void SetTaskbarProgress(const size_t state, const size_t progress); + void SetTaskbarProgress(const winrt::Microsoft::Terminal::Control::TaskbarState state, const size_t progress); void SummonWindow(winrt::TerminalApp::SummonWindowBehavior args); diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index b9931cf497c..4e7aa2898eb 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -64,32 +64,37 @@ // --------------------------- Control Settings --------------------------- // All of these settings are defined in IControlSettings. -#define CONTROL_SETTINGS(X) \ - X(winrt::guid, SessionId) \ - X(bool, EnableUnfocusedAcrylic, false) \ - X(winrt::hstring, Padding, DEFAULT_PADDING) \ - X(winrt::hstring, FontFace, L"Consolas") \ - X(float, FontSize, DEFAULT_FONT_SIZE) \ - X(winrt::Windows::UI::Text::FontWeight, FontWeight) \ - X(IFontFeatureMap, FontFeatures) \ - X(IFontAxesMap, FontAxes) \ - X(bool, EnableBuiltinGlyphs, true) \ - X(bool, EnableColorGlyphs, true) \ - X(winrt::hstring, CellWidth) \ - X(winrt::hstring, CellHeight) \ - X(winrt::hstring, Commandline) \ - X(winrt::hstring, StartingDirectory) \ - X(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible) \ - X(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale) \ - X(winrt::Microsoft::Terminal::Control::GraphicsAPI, GraphicsAPI) \ - X(bool, DisablePartialInvalidation, false) \ - X(bool, SoftwareRendering, false) \ - X(winrt::Microsoft::Terminal::Control::TextMeasurement, TextMeasurement) \ - X(winrt::Microsoft::Terminal::Control::AmbiguousWidth, AmbiguousWidth, winrt::Microsoft::Terminal::Control::AmbiguousWidth::Narrow) \ - X(winrt::Microsoft::Terminal::Control::DefaultInputScope, DefaultInputScope, winrt::Microsoft::Terminal::Control::DefaultInputScope::Default) \ - X(bool, UseBackgroundImageForWindow, false) \ - X(bool, ShowMarks, false) \ - X(winrt::Microsoft::Terminal::Control::CopyFormat, CopyFormatting, 0) \ - X(bool, RightClickContextMenu, false) \ - X(winrt::Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, winrt::Microsoft::Terminal::Control::PathTranslationStyle::None) \ +#define CONTROL_SETTINGS(X) \ + X(winrt::guid, SessionId) \ + X(bool, EnableUnfocusedAcrylic, false) \ + X(winrt::hstring, Padding, DEFAULT_PADDING) \ + X(winrt::hstring, FontFace, L"Consolas") \ + X(float, FontSize, DEFAULT_FONT_SIZE) \ + X(winrt::Windows::UI::Text::FontWeight, FontWeight) \ + X(IFontFeatureMap, FontFeatures) \ + X(IFontAxesMap, FontAxes) \ + X(bool, EnableBuiltinGlyphs, true) \ + X(bool, EnableColorGlyphs, true) \ + X(winrt::hstring, CellWidth) \ + X(winrt::hstring, CellHeight) \ + X(winrt::hstring, Commandline) \ + X(winrt::hstring, StartingDirectory) \ + X(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible) \ + X(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale) \ + X(winrt::Microsoft::Terminal::Control::GraphicsAPI, GraphicsAPI) \ + X(bool, DisablePartialInvalidation, false) \ + X(bool, SoftwareRendering, false) \ + X(winrt::Microsoft::Terminal::Control::TextMeasurement, TextMeasurement) \ + X(winrt::Microsoft::Terminal::Control::AmbiguousWidth, AmbiguousWidth, winrt::Microsoft::Terminal::Control::AmbiguousWidth::Narrow) \ + X(winrt::Microsoft::Terminal::Control::DefaultInputScope, DefaultInputScope, winrt::Microsoft::Terminal::Control::DefaultInputScope::Default) \ + X(bool, UseBackgroundImageForWindow, false) \ + X(bool, ShowMarks, false) \ + X(winrt::Microsoft::Terminal::Control::CopyFormat, CopyFormatting, 0) \ + X(bool, RightClickContextMenu, false) \ + X(winrt::Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, winrt::Microsoft::Terminal::Control::PathTranslationStyle::None) \ + X(winrt::Microsoft::Terminal::Control::OutputNotificationStyle, NotifyOnActivity, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::None) \ + X(winrt::Microsoft::Terminal::Control::OutputNotificationStyle, NotifyOnNextPrompt, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::None) \ + X(int32_t, NotifyOnActivityThreshold, 5) \ + X(int32_t, NotifyOnNextPromptThreshold, 5) \ + X(bool, AutoDetectRunningCommand, false) \ X(winrt::hstring, DragDropDelimiter, L" ") diff --git a/src/features.xml b/src/features.xml index ee6c5be6399..063dd9d22c9 100644 --- a/src/features.xml +++ b/src/features.xml @@ -187,6 +187,13 @@ + + Feature_NotifyOnActivity + Enables activity and prompt notifications and automatic running command detection. + AlwaysEnabled + + + Feature_WarnOnInvalidSettingsMediaResources Controls whether Terminal should display a warning dialog when icon, backgroundImage, shader, etc. could not be found. diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 155e4e8ab20..4d8a8a96c18 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -447,7 +447,7 @@ void ConhostInternalGetSet::NotifyBufferRotation(const int) { } -void ConhostInternalGetSet::NotifyShellIntegrationMark() +void ConhostInternalGetSet::NotifyShellIntegrationMark(ShellIntegrationMark /*mark*/) { // Not implemented for conhost - shell integration marks are a Terminal app feature. } diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index 9c9e4a20647..807d647e5c6 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -68,7 +68,7 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: bool IsVtInputEnabled() const override; void NotifyBufferRotation(const int delta) override; - void NotifyShellIntegrationMark() override; + void NotifyShellIntegrationMark(ShellIntegrationMark mark) override; void InvokeCompletions(std::wstring_view menuJson, unsigned int replaceLength) override; diff --git a/src/terminal/adapter/ITerminalApi.hpp b/src/terminal/adapter/ITerminalApi.hpp index 87a930265b3..c8ed1f0fc20 100644 --- a/src/terminal/adapter/ITerminalApi.hpp +++ b/src/terminal/adapter/ITerminalApi.hpp @@ -87,7 +87,16 @@ namespace Microsoft::Console::VirtualTerminal virtual bool ResizeWindow(const til::CoordType width, const til::CoordType height) = 0; virtual void NotifyBufferRotation(const int delta) = 0; - virtual void NotifyShellIntegrationMark() = 0; + + enum class ShellIntegrationMark + { + Prompt, + Command, + Output, + CommandFinished, + Other + }; + virtual void NotifyShellIntegrationMark(ShellIntegrationMark mark) = 0; virtual void InvokeCompletions(std::wstring_view menuJson, unsigned int replaceLength) = 0; diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index bd3ded01e94..55507f2515d 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -3650,7 +3650,7 @@ void AdaptDispatch::DoConEmuAction(const std::wstring_view string) else if (subParam == 12) { _pages.ActivePage().Buffer().StartCommand(); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::Command); } else { @@ -3685,7 +3685,7 @@ void AdaptDispatch::DoITerm2Action(const std::wstring_view string) if (action == L"SetMark") { _pages.ActivePage().Buffer().StartPrompt(); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::Prompt); } else { @@ -3723,19 +3723,19 @@ void AdaptDispatch::DoFinalTermAction(const std::wstring_view string) case L'A': // FTCS_PROMPT { _pages.ActivePage().Buffer().StartPrompt(); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::Prompt); break; } case L'B': // FTCS_COMMAND_START { _pages.ActivePage().Buffer().StartCommand(); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::Command); break; } case L'C': // FTCS_COMMAND_EXECUTED { _pages.ActivePage().Buffer().StartOutput(); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::Output); break; } case L'D': // FTCS_COMMAND_FINISHED @@ -3756,7 +3756,7 @@ void AdaptDispatch::DoFinalTermAction(const std::wstring_view string) } _pages.ActivePage().Buffer().EndCurrentCommand(error); - _api.NotifyShellIntegrationMark(); + _api.NotifyShellIntegrationMark(ITerminalApi::ShellIntegrationMark::CommandFinished); break; } diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index f56a3125751..d57cdcd1f2f 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -218,7 +218,7 @@ class TestGetSet final : public ITerminalApi Log::Comment(L"NotifyBufferRotation MOCK called..."); } - void NotifyShellIntegrationMark() override + void NotifyShellIntegrationMark(ShellIntegrationMark /*mark*/) override { Log::Comment(L"NotifyShellIntegrationMark MOCK called..."); } diff --git a/src/terminal/input/terminalInput.cpp b/src/terminal/input/terminalInput.cpp index 07283394bf4..322f965e25f 100644 --- a/src/terminal/input/terminalInput.cpp +++ b/src/terminal/input/terminalInput.cpp @@ -463,20 +463,6 @@ DWORD TerminalInput::_trackControlKeyState(const KEY_EVENT_RECORD& key) noexcept // can be misinterpreted as an Alt+AltGr key combination. const auto rightAltDown = key.bKeyDown && key.wVirtualKeyCode == VK_MENU && WI_IsFlagSet(key.dwControlKeyState, ENHANCED_KEY); WI_ClearFlagIf(_lastControlKeyState, RIGHT_ALT_PRESSED, WI_IsFlagSet(pressedKeyState, RIGHT_ALT_PRESSED) && !rightAltDown); - // We also take this opportunity to record the time at which the LeftCtrl - // and RightAlt keys are pressed. This is needed to determine whether the - // Ctrl key was pressed by the user, or fabricated by an AltGr key press. - if (key.bKeyDown) - { - if (WI_IsFlagSet(pressedKeyState, LEFT_CTRL_PRESSED)) - { - _lastLeftCtrlTime = GetTickCount64(); - } - if (WI_IsFlagSet(pressedKeyState, RIGHT_ALT_PRESSED)) - { - _lastRightAltTime = GetTickCount64(); - } - } return _lastControlKeyState; }