Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert pasted line endings #2009

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5d60f7d
Adding convertPasteLineEndings
DTeachs Jul 17, 2019
24406f7
f
DTeachs Jul 17, 2019
6343bd0
Convert paste line endings
DTeachs Jul 17, 2019
5de9819
Fixed Typo
DTeachs Jul 17, 2019
461f68c
Changed it so that no compiler upgrade is needed, because it cannot d…
DTeachs Jul 17, 2019
ea3cc88
Revert "Changed it so that no compiler upgrade is needed, because it …
DTeachs Jul 17, 2019
8aad3e0
Revert "Fixed Typo"
DTeachs Jul 17, 2019
ec4f595
Fixed typo
DTeachs Jul 17, 2019
b37f01b
fixed line
DTeachs Jul 17, 2019
17d13f1
Include regex so we can process the string being copied.
DTeachs Jul 17, 2019
ba71caa
The spice must flow. (#2096)
miniksa Jul 25, 2019
7d5a3f4
The Azure cloud shell connector (#1808)
Jul 25, 2019
70dee2d
f
DTeachs Jul 17, 2019
aa2d626
Changed it so that no compiler upgrade is needed, because it cannot d…
DTeachs Jul 17, 2019
95e5849
Revert "Changed it so that no compiler upgrade is needed, because it …
DTeachs Jul 17, 2019
299e68e
fixed line
DTeachs Jul 17, 2019
9f93fa9
Fixed merge conflicts
DTeachs Jul 27, 2019
cfc9b66
Update TermControl.cpp
DTeachs Jul 27, 2019
f6ea1d5
Format fixes
DTeachs Jul 27, 2019
c4389b4
Fix compilation errors
DTeachs Jul 27, 2019
9e09e36
Update TrueTypeFontList.cpp
Aug 5, 2019
113c6e7
Update ColorsPage.cpp
Aug 6, 2019
8b11847
Revert "Update TrueTypeFontList.cpp"
DTeachs Aug 8, 2019
97319e2
Rebase?
DTeachs Aug 8, 2019
fbb798d
Revert "Rebase?"
DTeachs Aug 8, 2019
0ff56a9
Update ci.yml
Aug 8, 2019
7242396
Update
DTeachs Aug 8, 2019
a0b3ba3
Update
DTeachs Aug 8, 2019
0f8646b
Update Wil
DTeachs Aug 8, 2019
a42d49e
Fix
DTeachs Aug 8, 2019
f3c48db
Fix compilation error by bad rebase and an extra curly brace
DTeachs Aug 8, 2019
861fcfa
Format fix
DTeachs Aug 8, 2019
7120c53
Fix formatting
DTeachs Aug 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dep/gsl
Submodule gsl updated 2 files
+7 −13 appveyor.yml
+5 −5 include/gsl/multi_span
5 changes: 2 additions & 3 deletions src/cascadia/CascadiaPackage/CascadiaPackage.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@
<!-- Override the filename for OpenConsole.exe (only) -->
<TargetPath Condition="'%(Filename)' == 'OpenConsole' and '%(Extension)' == '.exe'">conhost.exe</TargetPath>
<!-- Blank the SourceProject here to vend all files into the root of the package. -->
<SourceProject>
</SourceProject>
<SourceProject></SourceProject>
</_FilteredNonWapProjProjectOutput>
</ItemGroup>
</Target>
Expand All @@ -305,4 +304,4 @@
</ItemGroup>
</Target>

</Project>
</Project>
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,4 +642,4 @@ Profile CascadiaSettings::_CreateDefaultProfile(const std::wstring_view name)
newProfile.SetIconPath(iconPath);

return newProfile;
}
}
16 changes: 16 additions & 0 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static constexpr std::string_view UseAcrylicKey{ "useAcrylic" };
static constexpr std::string_view ScrollbarStateKey{ "scrollbarState" };
static constexpr std::string_view CloseOnExitKey{ "closeOnExit" };
static constexpr std::string_view PaddingKey{ "padding" };
static constexpr std::string_view ConvertPasteLineEndingsKey{ "convertPasteLineEndings" };
static constexpr std::string_view StartingDirectoryKey{ "startingDirectory" };
static constexpr std::string_view IconKey{ "icon" };
static constexpr std::string_view BackgroundImageKey{ "backgroundImage" };
Expand Down Expand Up @@ -99,6 +100,7 @@ Profile::Profile(const winrt::guid& guid) :
_useAcrylic{ false },
_scrollbarState{},
_closeOnExit{ true },
_convertPasteLineEndings{},
_padding{ DEFAULT_PADDING },
_icon{},
_backgroundImage{},
Expand Down Expand Up @@ -164,6 +166,10 @@ TerminalSettings Profile::CreateTerminalSettings(const std::vector<ColorScheme>&
// Fill in the remaining properties from the profile
terminalSettings.UseAcrylic(_useAcrylic);
terminalSettings.CloseOnExit(_closeOnExit);
if (_convertPasteLineEndings)
{
terminalSettings.ConvertPasteLineEndings(_convertPasteLineEndings.value());
}
terminalSettings.TintOpacity(_acrylicTransparency);

terminalSettings.FontFace(_fontFace);
Expand Down Expand Up @@ -283,10 +289,16 @@ Json::Value Profile::ToJson() const
root[JsonKey(CloseOnExitKey)] = _closeOnExit;
root[JsonKey(PaddingKey)] = winrt::to_string(_padding);

if (_convertPasteLineEndings)
{
root[JsonKey(ConvertPasteLineEndingsKey)] = _convertPasteLineEndings.value();
}

if (_connectionType)
{
root[JsonKey(ConnectionTypeKey)] = winrt::to_string(Utils::GuidToString(_connectionType.value()));
}

if (_scrollbarState)
{
const auto scrollbarState = winrt::to_string(_scrollbarState.value());
Expand Down Expand Up @@ -452,6 +464,10 @@ Profile Profile::FromJson(const Json::Value& json)
{
result._closeOnExit = closeOnExit.asBool();
}
if (auto convertPasteLineEndings{ json[JsonKey(ConvertPasteLineEndingsKey)] })
{
result._convertPasteLineEndings = convertPasteLineEndings.asBool();
}
if (auto padding{ json[JsonKey(PaddingKey)] })
{
result._padding = GetWstringFromJson(padding);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class TerminalApp::Profile final

std::optional<std::wstring> _scrollbarState;
bool _closeOnExit;
std::optional<bool> _convertPasteLineEndings;
std::wstring _padding;

std::optional<std::wstring> _icon;
Expand Down
54 changes: 36 additions & 18 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pch.h"
#include "TermControl.h"
#include <regex>
#include <argb.h>
#include <DefaultSettings.h>
#include <unicode.hpp>
Expand Down Expand Up @@ -956,11 +957,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// - mouseDelta: the mouse wheel delta that triggered this event.
void TermControl::_MouseZoomHandler(const double mouseDelta)
{
const auto fontDelta = mouseDelta < 0 ? -1 : 1;
try
{
// Make sure we have a non-zero font size
const auto newSize = std::max(gsl::narrow<short>(_desiredFont.GetEngineSize().Y + fontDelta), static_cast<short>(1));
const auto newSize = std::max(gsl::narrow<short>(_desiredFont.GetEngineSize().Y + (mouseDelta < 0 ? -1 : 1)), static_cast<short>(1));
const auto* fontFace = _settings.FontFace().c_str();
_actualFont = { fontFace, 0, 10, { 0, newSize }, CP_UTF8, false };
_desiredFont = { _actualFont };
Expand Down Expand Up @@ -1192,6 +1192,25 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
}
}

// Method Description:
// - Pre-process (if necessary) text pasted (presumably from the clipboard)
// before sending it over the terminal's connection, respecting
// appropriate terminal settings
void TermControl::_SendPastedTextToConnection(const std::wstring& wstr)
{
// Check settings to see if we should be converting line
// endings
if (_settings.ConvertPasteLineEndings())
{
const static std::wregex rgx{ L"\n\r" };
std::wstring stripped = std::regex_replace(wstr, rgx, L"\n");
_SendInputToConnection(stripped);
return;
}

_SendInputToConnection(wstr);
}

void TermControl::_SendInputToConnection(const std::wstring& wstr)
{
_connection.WriteInput(wstr);
Expand Down Expand Up @@ -1253,11 +1272,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
void TermControl::_BlinkCursor(Windows::Foundation::IInspectable const& /* sender */,
Windows::Foundation::IInspectable const& /* e */)
{
if ((_closing) || (!_terminal->IsCursorBlinkingAllowed() && _terminal->IsCursorVisible()))
if (!_closing && (_terminal->IsCursorBlinkingAllowed() || !_terminal->IsCursorVisible()))
{
return;
_terminal->SetCursorVisible(!_terminal->IsCursorVisible());
}
_terminal->SetCursorVisible(!_terminal->IsCursorVisible());
}

// Method Description:
Expand Down Expand Up @@ -1379,11 +1397,12 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

hstring TermControl::Title()
{
if (!_initializedTerminal)
return L"";

hstring hstr(_terminal->GetConsoleTitle());
return hstr;
if (_initializedTerminal)
{
hstring hstr(_terminal->GetConsoleTitle());
return hstr;
}
return L"";
}

// Method Description:
Expand All @@ -1408,7 +1427,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
// attach TermControl::_SendInputToConnection() as the clipboardDataHandler.
// This is called when the clipboard data is loaded.
auto clipboardDataHandler = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1);
auto clipboardDataHandler = std::bind(&TermControl::_SendPastedTextToConnection, this, std::placeholders::_1);
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);

// send paste event up to TermApp
Expand Down Expand Up @@ -1636,13 +1655,13 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// std::stod will throw out_of_range expection if the input value is more than DBL_MAX
try
{
for (; std::getline(tokenStream, token, singleCharDelim) && (paddingPropIndex < thicknessArr.size()); paddingPropIndex++)
while (std::getline(tokenStream, token, singleCharDelim) && (paddingPropIndex < thicknessArr.size()))
{
// std::stod internall calls wcstod which handles whitespace prefix (which is ignored)
// & stops the scan when first char outside the range of radix is encountered
// We'll be permissive till the extent that stod function allows us to be by default
// Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail
thicknessArr[paddingPropIndex] = std::stod(token, idx);
thicknessArr[paddingPropIndex++] = std::stod(token, idx);
}
}
catch (...)
Expand Down Expand Up @@ -1770,11 +1789,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
// exit early. This is a single click.
_multiClickCounter = 1;
return 1; //return single click
}
else
{
_multiClickCounter++;
}

_multiClickCounter++;
return _multiClickCounter;
}

Expand Down Expand Up @@ -1802,4 +1820,4 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// clang-format on

DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, PasteFromClipboard, _clipboardPasteHandlers, TerminalControl::TermControl, TerminalControl::PasteFromClipboardEventArgs);
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
void _BlinkCursor(Windows::Foundation::IInspectable const& sender, Windows::Foundation::IInspectable const& e);
void _SetEndSelectionPointAtCursor(Windows::Foundation::Point const& cursorPosition);
void _SendInputToConnection(const std::wstring& wstr);
void _SendPastedTextToConnection(const std::wstring& wstr);
void _SwapChainSizeChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
void _SwapChainScaleChanged(Windows::UI::Xaml::Controls::SwapChainPanel const& sender, Windows::Foundation::IInspectable const& args);
void _DoResize(const double newWidth, const double newHeight);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettings/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace Microsoft.Terminal.Settings
{
Boolean UseAcrylic;
Boolean CloseOnExit;
Boolean ConvertPasteLineEndings;

Double TintOpacity;
ScrollbarState ScrollState;

Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalSettings/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_wordDelimiters{ DEFAULT_WORD_DELIMITERS },
_useAcrylic{ false },
_closeOnExit{ true },
_convertPasteLineEndings{ false },
_tintOpacity{ 0.5 },
_padding{ DEFAULT_PADDING },
_fontFace{ DEFAULT_FONT_FACE },
Expand Down Expand Up @@ -169,6 +170,16 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_closeOnExit = value;
}

bool TerminalSettings::ConvertPasteLineEndings()
{
return _convertPasteLineEndings;
}

void TerminalSettings::ConvertPasteLineEndings(bool value)
{
_convertPasteLineEndings = value;
}

double TerminalSettings::TintOpacity()
{
return _tintOpacity;
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettings/terminalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
void UseAcrylic(bool value);
bool CloseOnExit();
void CloseOnExit(bool value);
bool ConvertPasteLineEndings();
void ConvertPasteLineEndings(bool value);
double TintOpacity();
void TintOpacity(double value);
hstring Padding();
Expand Down Expand Up @@ -102,6 +104,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
uint32_t _cursorHeight;
hstring _wordDelimiters;

bool _convertPasteLineEndings;
bool _useAcrylic;
bool _closeOnExit;
double _tintOpacity;
Expand Down
1 change: 0 additions & 1 deletion src/propsheet/ColorsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ static int iColor;
break;
default:
return SimpleColorControlProc(hColor, wMsg, wParam, lParam);
break;
}
return TRUE;
}
Expand Down