Skip to content

Commit

Permalink
feat: image background color
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCraver committed Sep 17, 2021
1 parent 6bef088 commit bf51f59
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions docs/docs/contributors.md
Expand Up @@ -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>

Expand Down
2 changes: 2 additions & 0 deletions docs/docs/share-theme.mdx
Expand Up @@ -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">
Expand All @@ -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>
6 changes: 4 additions & 2 deletions docs/export_themes.js
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}`;
}
Expand Down
3 changes: 2 additions & 1 deletion src/image.go
Expand Up @@ -98,6 +98,7 @@ type ImageRenderer struct {
ansiString string
author string
ansi *ansiUtils
bgColor string

factor float64

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/init/omp.ps1
Expand Up @@ -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"
}

Expand Down
6 changes: 6 additions & 0 deletions src/main.go
Expand Up @@ -56,6 +56,7 @@ type args struct {
Author *string
CursorPadding *int
RPromptOffset *int
BGColor *string
StackCount *int
Command *string
PrintTransient *bool
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -224,6 +229,7 @@ func main() {
author: *args.Author,
cursorPadding: *args.CursorPadding,
rPromptOffset: *args.RPromptOffset,
bgColor: *args.BGColor,
ansi: ansi,
}
imageCreator.init()
Expand Down

0 comments on commit bf51f59

Please sign in to comment.