-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Implement OSC 7 for setting the CWD #20019
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2615,6 +2615,27 @@ void AdaptDispatch::SetWindowTitle(std::wstring_view title) | |
| _api.SetWindowTitle(title); | ||
| } | ||
|
|
||
| // OSC 7 - Set Current Working Directory | ||
| // While ConEmu's OSC 9;9 works well for native Windows paths, | ||
| // OSC 7 uses file URIs, which may not always work. | ||
| void AdaptDispatch::SetCurrentWorkingDirectory(std::wstring_view uri) | ||
| { | ||
| // Ensure that the URI has a null terminator. | ||
| std::wstring path{ uri }; | ||
|
|
||
| // PathCreateFromUrlW supports writing to the input pointer, | ||
| // and the resulting path can never be longer than the URI. | ||
| const auto ptr = path.data(); | ||
| auto len = gsl::narrow<DWORD>(path.size()); | ||
| THROW_IF_FAILED(PathCreateFromUrlW(ptr, ptr, &len, 0)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will add a dependency from conhost on the library containing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .... it's in kernelbase?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm where are you hosted little guy
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wellp |
||
| path.resize(len); | ||
|
|
||
| if (til::is_legal_path(path)) | ||
| { | ||
| _api.SetWorkingDirectory(path); | ||
| } | ||
| } | ||
|
|
||
| //Routine Description: | ||
| // HTS - sets a VT tab stop in the cursor's current column. | ||
| //Arguments: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1237,6 +1237,19 @@ const wchar_t* Utils::FindActionableControlCharacter(const wchar_t* beg, const s | |
| return it; | ||
| } | ||
|
|
||
| // Returns true if it's a valid path to a directory. | ||
| bool Utils::IsValidDirectory(const wchar_t* path) noexcept | ||
| { | ||
| if (path == nullptr || *path == L'\0') | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| WIN32_FILE_ATTRIBUTE_DATA data; | ||
| const auto ok = GetFileAttributesExW(path, GetFileExInfoStandard, &data); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I just hate that the std::filesystem::path objects are expensive to construct. Under the hood, it gets passed to Hurr durr "C++ is for low level zero overhead real man's man engineering." |
||
| return ok && (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | ||
| } | ||
|
|
||
| #pragma warning(pop) | ||
|
|
||
| std::wstring Utils::EvaluateStartingDirectory( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i s2g, we just had a whole-ass duplicate of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah lol. I was super surprised about that too. We don't have skeletons in our basement, we got entire graveyards apparently lmao.