我的 Windows 终端中正在运行 Git Bash,但是在设置背景图像时遇到了问题,该背景图像仅在终端窗口的右侧可见(被裁剪,而不是被挤压):
起初,我以为 Git Bash 输出的是绘制在图像上的黑色背景,但您看到的灰色背景是从 Windows Terminal 的设置中设置的,可以在那里更改为任何颜色;所以它选择绘制背景颜色而不是图像?
- 我尝试过完全删除颜色选项,但除了图像的右侧部分外,背景都只剩下黑色。
- 该图像在 PowerShell 中正常工作,其他图像具有相同的效果 - 在 Git Bash 中仅可见右侧条带。我尝试了不同的拉伸和位置设置,但始终仅可见右侧条带。
如何让 Windows 终端正确呈现图像?
Windows 终端设置:
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{e1001cad-b4fa-48a0-8617-0791feb59286}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
// Startup values
//"startOnUserLogin": true,
"initialCols": 240,
"initialRows": 60,
"confirmCloseAllTabs": false,
"initialPosition": "20,15",
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"backgroundImage": "C:\\Users\\karel_hrkal\\Desktop\\hexmap-dark.png",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure",
"hidden": false
},
{
"guid" : "{e1001cad-b4fa-48a0-8617-0791feb59286}",
"name" : "Git Bash",
"commandline" : "\"C:\\Programs\\Git\\bin\\bash.exe\" --login -i -l",
"startingDirectory": "C:\\Projekty",
"closeOnExit" : true,
"colorScheme" : "Vintage",
"cursorColor" : "#8080FF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"antialiasingMode": "cleartype",
"historySize" : 9001,
"icon" : "C:\\Programs\\Git\\mingw64\\share\\git\\git-for-windows.ico",
//"backgroundImage": "C:\\Users\\karel_hrkal\\Desktop\\hexmap.png",
"backgroundImage": "C:\\Users\\karel_hrkal\\Desktop\\fantasy-landscape-mountains-waterfall-river-fantasy.png",
"backgroundImageStretchMode": "uniform",
"backgroundImageAlignment": "right",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : false,
"hidden": false
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
Git Bash 提示符设置:
if test -f ~/.config/git/git-prompt.sh; then
. ~/.config/git/git-prompt.sh
else
PS1='\[\033]0;\W\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>
PS1="$PS1"'\[\033[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
if test -z "$WINELOADERNOEXEC"; then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"; then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[1;31m\]' # change color to red
PS1="$PS1"'$ ' # prompt: always $
PS1="$PS1"'\[\033[36m\]' # change color to cyan //0 for white
fi
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
# Evaluate all user-specific Bash completion scripts (if any)
if test -z "$WINELOADERNOEXEC"; then
for c in "$HOME"/bash_completion.d/*.bash; do
# Handle absence of any scripts (or the folder) gracefully
test ! -f "$c" ||
. "$c"
done
fi
答案1
删除antialiasingMode
中的属性settings.json
。
此外,设置backgroundImageStretchMode
模式建议使用fit
或uniformToFill
来使图像按比例适合全屏区域,而不是在侧面留下条形图:
"backgroundImageStretchMode": "fit"