bestsource

프로그램을 실행한 후 손상된 경우 Windows PowerShell 색상을 재설정하는 방법은 무엇입니까?

bestsource 2023. 8. 22. 22:17
반응형

프로그램을 실행한 후 손상된 경우 Windows PowerShell 색상을 재설정하는 방법은 무엇입니까?

node.js를 사용하여 Windows 프로젝트에 PowerShell을 사용하기 시작했습니다.Powershell 명령줄에서 많은 프로그램(노드, 슈퍼바이저 및 npm 포함)을 실행하면 PowerShell 배경 및 전경 색상이 기본 Powershell 색상에서 변경되기 시작합니다.명령 실행 결과를 쉽게 읽을 수 있도록 PowerShell 내에서 일관된 모양을 유지하려면 어떻게 해야 합니까?

일회성 작업으로 다음을 실행합니다.

> [Console]::ResetColor()

문서에서: (강조 추가됨)

전경색과 배경색은 현재 프로세스가 시작되었을 때 존재했던 색으로 복원됩니다.

특히 빌드를 Ctrl+C로 누를 때 MSBuild에 이 문제가 있습니다.이것은 제가 제 profile.ps1 파일에 넣은 것입니다.

$OrigBgColor = $host.ui.rawui.BackgroundColor
$OrigFgColor = $host.ui.rawui.ForegroundColor

# MSBUILD has a nasty habit of leaving the foreground color red
# if you Ctrl+C while it is outputting errors.
function Reset-Colors {
    $host.ui.rawui.BackgroundColor = $OrigBgColor
    $host.ui.rawui.ForegroundColor = $OrigFgColor
}

그런 다음 MSBuild가 색상을 잘못 설정했을 때 색상 재설정을 호출합니다.

프로필이 아직 없는 경우 먼저 PowerShell에서 프로필을 생성합니다.

test-path $profile
new-item -path $profile -itemtype file -force
notepad $profile

두 번째로, 다음 코드를 파일에 넣습니다.

function prompt {
  [Console]::ResetColor()
}

셋째, PowerShell에서 스크립트를 실행할 수 있는지 확인합니다.

Get-ExecutionPolicy

이 메시지가 제한됨으로 표시되면 다음 AS 관리자를 실행합니다(보안 관련 내용을 이해했는지 확인하십시오).

Set-ExecutionPolicy RemoteSigned

새 PowerShell 프롬프트를 열면 색 문제 없이 노드 또는 기타 명령을 실행할 수 있습니다.

다음 명령을 실행하여 색상 문제를 해결합니다.

cmd
color 07
exit

이 명령어는 PowerShell에서 cmd를 실행합니다.color 07색상을 수정하려면 cmd를 종료하고 PowerShell로 되돌립니다.

언급URL : https://stackoverflow.com/questions/13805646/how-can-you-reset-the-colors-for-windows-powershell-if-they-become-corrupted-aft

반응형