开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (3)
标签 (3)
master
zadjii-msft-patch-readme
richturn/retarget-echocon
1904.29002
1810.02002
1708.14008
master
分支 (3)
标签 (3)
master
zadjii-msft-patch-readme
richturn/retarget-echocon
1904.29002
1810.02002
1708.14008
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (3)
标签 (3)
master
zadjii-msft-patch-readme
richturn/retarget-echocon
1904.29002
1810.02002
1708.14008
Terminal
/
src
/
host
/
utils.cpp
Terminal
/
src
/
host
/
utils.cpp
utils.cpp 8.79 KB
一键复制 编辑 原始数据 按行查看 历史
Dustin Howett 提交于 2019年05月03日 06:29 +08:00 . Initial release of the Windows Terminal source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "utils.hpp"
#include "..\interactivity\inc\ServiceLocator.hpp"
#include "srvinit.h"
short CalcWindowSizeX(const SMALL_RECT& rect) noexcept
{
return rect.Right - rect.Left + 1;
}
short CalcWindowSizeY(const SMALL_RECT& rect) noexcept
{
return rect.Bottom - rect.Top + 1;
}
short CalcCursorYOffsetInPixels(const short sFontSizeY, const ULONG ulSize) noexcept
{
// TODO: MSFT 10229700 - Note, we want to likely enforce that this isn't negative.
// Pretty sure there's not a valid case for negative offsets here.
return (short)((sFontSizeY)-(ulSize));
}
WORD ConvertStringToDec(_In_ PCWSTR pwchToConvert, _Out_opt_ PCWSTR * const ppwchEnd) noexcept
{
WORD val = 0;
while (*pwchToConvert != L'0円')
{
WCHAR ch = *pwchToConvert;
if (L'0' <= ch && ch <= L'9')
{
val = (val * 10) + (ch - L'0');
}
else
{
break;
}
pwchToConvert++;
}
if (nullptr != ppwchEnd)
{
*ppwchEnd = pwchToConvert;
}
return val;
}
// Routine Description:
// - Retrieves string resources from our resource files.
// Arguments:
// - id - Resource id from resource.h to the string we need to load.
// Return Value:
// - The string resource
std::wstring _LoadString(const UINT id)
{
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
WCHAR ItemString[70];
size_t ItemLength = 0;
LANGID LangId;
const NTSTATUS Status = GetConsoleLangId(gci.OutputCP, &LangId);
if (NT_SUCCESS(Status))
{
ItemLength = s_LoadStringEx(ServiceLocator::LocateGlobals().hInstance, id, ItemString, ARRAYSIZE(ItemString), LangId);
}
if (!NT_SUCCESS(Status) || ItemLength == 0)
{
ItemLength = LoadStringW(ServiceLocator::LocateGlobals().hInstance, id, ItemString, ARRAYSIZE(ItemString));
}
return std::wstring(ItemString, ItemLength);
}
// Routine Description:
// - Helper to retrieve string resources from a MUI with a particular LANGID.
// Arguments:
// - hModule - The module related to loading the resource
// - wID - The resource ID number
// - lpBuffer - Buffer to place string data when read.
// - cchBufferMax - Size of buffer
// - wLangId - Language ID of resources that we should retrieve.
UINT s_LoadStringEx(_In_ HINSTANCE hModule, _In_ UINT wID, _Out_writes_(cchBufferMax) LPWSTR lpBuffer, _In_ UINT cchBufferMax, _In_ WORD wLangId)
{
// Make sure the parms are valid.
if (lpBuffer == nullptr)
{
return 0;
}
UINT cch = 0;
// String Tables are broken up into 16 string segments. Find the segment containing the string we are interested in.
HANDLE const hResInfo = FindResourceEx(hModule, RT_STRING, (LPTSTR)((LONG_PTR)(((USHORT)wID >> 4) + 1)), wLangId);
if (hResInfo != nullptr)
{
// Load that segment.
HANDLE const hStringSeg = (HRSRC)LoadResource(hModule, (HRSRC)hResInfo);
// Lock the resource.
LPTSTR lpsz;
if (hStringSeg != nullptr && (lpsz = (LPTSTR)LockResource(hStringSeg)) != nullptr)
{
// Move past the other strings in this segment. (16 strings in a segment -> & 0x0F)
wID &= 0x0F;
for (;;)
{
cch = *((WCHAR *)lpsz++); // PASCAL like string count
// first WCHAR is count of WCHARs
if (wID-- == 0)
{
break;
}
lpsz += cch; // Step to start if next string
}
// chhBufferMax == 0 means return a pointer to the read-only resource buffer.
if (cchBufferMax == 0)
{
*(LPTSTR *)lpBuffer = lpsz;
}
else
{
// Account for the nullptr
cchBufferMax--;
// Don't copy more than the max allowed.
if (cch > cchBufferMax)
cch = cchBufferMax;
// Copy the string into the buffer.
memmove(lpBuffer, lpsz, cch * sizeof(WCHAR));
}
}
}
// Append a nullptr.
if (cchBufferMax != 0)
{
lpBuffer[cch] = 0;
}
return cch;
}
// Routine Description:
// - Compares two coordinate positions to determine whether they're the same, left, or right within the given buffer size
// Arguments:
// - bufferSize - The size of the buffer to use for measurements.
// - coordFirst - The first coordinate position
// - coordSecond - The second coordinate position
// Return Value:
// - Negative if First is to the left of the Second.
// - 0 if First and Second are the same coordinate.
// - Positive if First is to the right of the Second.
// - This is so you can do s_CompareCoords(first, second) <= 0 for "first is left or the same as second".
// (the < looks like a left arrow :D)
// - The magnitude of the result is the distance between the two coordinates when typing characters into the buffer (left to right, top to bottom)
int Utils::s_CompareCoords(const COORD bufferSize, const COORD coordFirst, const COORD coordSecond) noexcept
{
const short cRowWidth = bufferSize.X;
// Assert that our coordinates are within the expected boundaries
const short cRowHeight = bufferSize.Y;
FAIL_FAST_IF(!(coordFirst.X >= 0 && coordFirst.X < cRowWidth));
FAIL_FAST_IF(!(coordSecond.X >= 0 && coordSecond.X < cRowWidth));
FAIL_FAST_IF(!(coordFirst.Y >= 0 && coordFirst.Y < cRowHeight));
FAIL_FAST_IF(!(coordSecond.Y >= 0 && coordSecond.Y < cRowHeight));
// First set the distance vertically
// If first is on row 4 and second is on row 6, first will be -2 rows behind second * an 80 character row would be -160.
// For the same row, it'll be 0 rows * 80 character width = 0 difference.
int retVal = (coordFirst.Y - coordSecond.Y) * cRowWidth;
// Now adjust for horizontal differences
// If first is in position 15 and second is in position 30, first is -15 left in relation to 30.
retVal += (coordFirst.X - coordSecond.X);
// Further notes:
// If we already moved behind one row, this will help correct for when first is right of second.
// For example, with row 4, col 79 and row 5, col 0 as first and second respectively, the distance is -1.
// Assume the row width is 80.
// Step one will set the retVal as -80 as first is one row behind the second.
// Step two will then see that first is 79 - 0 = +79 right of second and add 79
// The total is -80 + 79 = -1.
return retVal;
}
// Routine Description:
// - Compares two coordinate positions to determine whether they're the same, left, or right
// Arguments:
// - coordFirst - The first coordinate position
// - coordSecond - The second coordinate position
// Return Value:
// - Negative if First is to the left of the Second.
// - 0 if First and Second are the same coordinate.
// - Positive if First is to the right of the Second.
// - This is so you can do s_CompareCoords(first, second) <= 0 for "first is left or the same as second".
// (the < looks like a left arrow :D)
// - The magnitude of the result is the distance between the two coordinates when typing characters into the buffer (left to right, top to bottom)
int Utils::s_CompareCoords(const COORD coordFirst, const COORD coordSecond) noexcept
{
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
// find the width of one row
const COORD coordScreenBufferSize = gci.GetActiveOutputBuffer().GetBufferSize().Dimensions();
return s_CompareCoords(coordScreenBufferSize, coordFirst, coordSecond);
}
// Routine Description:
// - Finds the opposite corner given a rectangle and one of its corners.
// - For example, finds the bottom right corner given a rectangle and its top left corner.
// Arguments:
// - srRectangle - The rectangle to check
// - coordCorner - One of the corners of the given rectangle
// Return Value:
// - The opposite corner of the one given.
COORD Utils::s_GetOppositeCorner(const SMALL_RECT srRectangle, const COORD coordCorner) noexcept
{
// Assert we were given coordinates that are indeed one of the corners of the rectangle.
FAIL_FAST_IF(!(coordCorner.X == srRectangle.Left || coordCorner.X == srRectangle.Right));
FAIL_FAST_IF(!(coordCorner.Y == srRectangle.Top || coordCorner.Y == srRectangle.Bottom));
return { (srRectangle.Left == coordCorner.X) ? srRectangle.Right : srRectangle.Left,
(srRectangle.Top == coordCorner.Y) ? srRectangle.Bottom : srRectangle.Top };
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

The new Windows Terminal, and the original Windows console host -- all in the same place!
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/AbstractFactory/Terminal.git
git@gitee.com:AbstractFactory/Terminal.git
AbstractFactory
Terminal
Terminal
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /