feat: image background color

This commit is contained in:
Nick Craver 2021-09-17 14:34:43 -04:00 committed by GitHub
parent 6bef088b83
commit bf51f59ceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 5 deletions

View file

@ -667,6 +667,15 @@
"contributions": [
"doc"
]
},
{
"login": "NickCraver",
"name": "Nick Craver",
"avatar_url": "https://avatars.githubusercontent.com/u/454813?v=4",
"profile": "https://nickcraver.com",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,

View file

@ -104,6 +104,7 @@ Thanks goes to these wonderful people ([emoji key][acek]):
<td align="center"><a href="http://www.m365princess.com"><img src="https://avatars.githubusercontent.com/u/49960482?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Luise Freese</b></sub></a><br /><a href="#design-LuiseFreese" title="Design">🎨</a></td>
<td align="center"><a href="https://github.com/asherber"><img src="https://avatars.githubusercontent.com/u/5248041?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aaron Sherber</b></sub></a><br /><a href="https://github.com/JanDeDobbeleer/oh-my-posh/commits?author=asherber" title="Code">💻</a></td>
<td align="center"><a href="http://SeanKilleen.com"><img src="https://avatars.githubusercontent.com/u/2148318?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sean Killeen</b></sub></a><br /><a href="https://github.com/JanDeDobbeleer/oh-my-posh/commits?author=SeanKilleen" title="Documentation">📖</a></td>
<td align="center"><a href="https://nickcraver.com"><img src="https://avatars.githubusercontent.com/u/454813?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nick Craver</b></sub></a><br /><a href="https://github.com/JanDeDobbeleer/oh-my-posh/commits?author=NickCraver" title="Code">💻</a></td>
</tr>
</table>

View file

@ -34,6 +34,7 @@ There are a couple of parameters you can use to tweak the image rendering:
- `CursorPadding`: spaces to add after the cursor indication (`_`)
- `RPromptOffset`: spaces to add **before** a block that's right aligned
- `Author`: the name of the creator, added after `https://ohmyposh.dev`
- `BGColor`: the hex background color to use (e.g. `#222222`)
</TabItem>
<TabItem value="others">
@ -49,6 +50,7 @@ There are a couple of additional switches you can use to tweak the image renderi
- `--cursor-padding`: spaces to add after the cursor indication (`_`)
- `--rprompt-offset`: spaces to add **before** a block that's right aligned
- `--author`: the name of the creator, added after `https://ohmyposh.dev`
- `--bg-color`: the hex background color to use (e.g. `#222222`)
</TabItem>
</Tabs>

View file

@ -8,11 +8,12 @@ const exec = util.promisify(require('child_process').exec);
const themesConfigDir = "./../themes";
const themesStaticDir = "./static/img/themes";
function newThemeConfig(rpromptOffset = 40, cursorPadding = 30, author = "") {
function newThemeConfig(rpromptOffset = 40, cursorPadding = 30, author = "", bgColor = "#151515") {
var config = {
rpromptOffset: rpromptOffset,
cursorPadding: cursorPadding,
author: author
author: author,
bgColor: bgColor
};
return config;
}
@ -69,6 +70,7 @@ themeConfigOverrrides.set('zash.omp.json', newThemeConfig(40, 40));
let poshCommand = `oh-my-posh --config=${configPath} --shell shell --export-png`;
poshCommand += ` --rprompt-offset=${config.rpromptOffset}`;
poshCommand += ` --cursor-padding=${config.cursorPadding}`;
poshCommand += ` --bg-color=${config.cursorPadding}`;
if (config.author !== '') {
poshCommand += ` --author=${config.author}`;
}

View file

@ -98,6 +98,7 @@ type ImageRenderer struct {
ansiString string
author string
ansi *ansiUtils
bgColor string
factor float64
@ -285,7 +286,7 @@ func (ir *ImageRenderer) SavePNG(path string) error {
// Draw rounded rectangle with outline and three button to produce the
// impression of a window with controls and a content area
dc.DrawRoundedRectangle(xOffset, yOffset, width-2*marginX, height-2*marginY, corner)
dc.SetHexColor("#151515")
dc.SetHexColor(ir.bgColor)
dc.Fill()
dc.DrawRoundedRectangle(xOffset, yOffset, width-2*marginX, height-2*marginY, corner)

View file

@ -185,16 +185,22 @@ function global:Export-PoshImage {
$CursorPadding = 30,
[Parameter(Mandatory = $false)]
[string]
$Author
$Author,
[Parameter(Mandatory = $false)]
[string]
$BGColor
)
if ($Author) {
$Author = "--author=$Author"
}
if ($BGColor) {
$BGColor = "--bg-color=$BGColor"
}
$omp = "::OMP::"
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
$standardOut = @(&$omp --config="$config" --pwd="$cleanPWD" --pswd="$cleanPSWD" --export-png --rprompt-offset="$RPromptOffset" --cursor-padding="$CursorPadding" $Author 2>&1)
$standardOut = @(&$omp --config="$config" --pwd="$cleanPWD" --pswd="$cleanPSWD" --export-png --rprompt-offset="$RPromptOffset" --cursor-padding="$CursorPadding" $Author $BGColor 2>&1)
$standardOut -join "`n"
}

View file

@ -56,6 +56,7 @@ type args struct {
Author *string
CursorPadding *int
RPromptOffset *int
BGColor *string
StackCount *int
Command *string
PrintTransient *bool
@ -139,6 +140,10 @@ func main() {
"rprompt-offset",
40,
"Offset the right prompt with x when using --export-img"),
BGColor: flag.String(
"bg-color",
"#151515",
"Set the background color when using --export-img"),
StackCount: flag.Int(
"stack-count",
0,
@ -224,6 +229,7 @@ func main() {
author: *args.Author,
cursorPadding: *args.CursorPadding,
rPromptOffset: *args.RPromptOffset,
bgColor: *args.BGColor,
ansi: ansi,
}
imageCreator.init()