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

Add an experimental setting for making suggestions RGB #17416

Merged
merged 20 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
cleanup for review
  • Loading branch information
zadjii-msft committed Jun 6, 2024
commit 5647c6d4c043784114d39ff5ef8eccb6fff7ac71
60 changes: 27 additions & 33 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,7 @@

void Terminal::PreviewText(std::wstring_view input)
{
// Our suggestion text is default-on-default, in italics.
static constexpr TextAttribute previewAttrs{ CharacterAttributes::Italics, TextColor{}, TextColor{}, 0u, TextColor{} };

auto lock = LockForWriting();
Expand All @@ -1597,44 +1598,37 @@
return;
}

// HACK trim off leading DEL chars.
// When we're previewing suggestions, they might be preceeded with DEL

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

preceeded is not a recognized word. (unrecognized-spelling)
// characters to backspace off the old command.
//
// But also, in the case of something like pwsh, there might be MORE "ghost"
// text in the buffer _after_ the commandline.
//
// We need to trim off the leading DELs, then pad out the rest of the line
// to cover any other ghost text.
std::wstring_view view{ input };
// Where do the DELs end?
const auto strBegin = view.find_first_not_of(L"\x7f");

// // What we actually want to display is the text that would remain after
// // accounting for the leading backspaces. So trim off the leading
// // backspaces, AND and equal number of "real" characters.
// if (strBegin != std::wstring::npos)
// {
// view = view.substr(strBegin * 2);
// }

// snippetPreview.text = view;
// // // Hack, part the second: Pad the remaining text with spaces.
// // const auto originalLen = input.size();
// // const auto unpaddedLen = snippetPreview.text.size();
// // if (unpaddedLen < originalLen)
// // {
// // snippetPreview.text.insert(snippetPreview.text.size(), originalLen + unpaddedLen, L' ');
// // }
if (strBegin != std::wstring::npos)
{
// Attempt 2
const auto bufferWidth = _GetMutableViewport().Width();
const auto cursorX = _activeBuffer().GetCursor().GetPosition().x;
const auto expectedLenTillEnd = strBegin + (bufferWidth - cursorX);
if (strBegin != std::wstring::npos)
{
view = view.substr(strBegin);
}
snippetPreview.text = view;
const auto originalSize{ snippetPreview.text.size() };
if (expectedLenTillEnd > originalSize)
{
snippetPreview.text.insert(originalSize, expectedLenTillEnd - originalSize, L' ');
}
// Trim them off.
view = view.substr(strBegin);
}
// How many spaces do we need, so that the preview exactly covers the entire
// prompt, all the way to the end of the viewport?
const auto bufferWidth = _GetMutableViewport().Width();
const auto cursorX = _activeBuffer().GetCursor().GetPosition().x;
const auto expectedLenTillEnd = strBegin + (bufferWidth - cursorX);
std::wstring preview{ view };
const auto originalSize{ preview.size() };
if (expectedLenTillEnd > originalSize)
{
// pad it out
preview.insert(originalSize, expectedLenTillEnd - originalSize, L' ');
}
snippetPreview.text = til::visualize_nonspace_control_codes(preview);
// Build our composition data
const auto len = snippetPreview.text.size();
// snippetPreview.attributes[0] = Microsoft::Console::Render::CompositionRange{ len, TextAttribute{} };
snippetPreview.attributes.clear();
snippetPreview.attributes.emplace_back(len, previewAttrs);
snippetPreview.cursorPos = len;
Expand Down
Loading