mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 03:49:40 -08:00
refactor: change powerline config to segment
This commit is contained in:
parent
9a508142fc
commit
1d8e7b2458
|
@ -3,11 +3,11 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffe9aa",
|
||||
"properties": {
|
||||
|
@ -17,6 +17,7 @@
|
|||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
|
@ -26,6 +27,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
|
@ -39,6 +41,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
|
@ -54,6 +57,7 @@
|
|||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
|
@ -63,6 +67,7 @@
|
|||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
|
@ -36,6 +36,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
|
@ -49,6 +50,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
|
@ -20,6 +19,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#C678DD",
|
||||
"properties": {
|
||||
|
@ -30,6 +30,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "exit",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
|
@ -20,6 +19,7 @@
|
|||
{
|
||||
"type": "spotify",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#1BD760",
|
||||
"properties": {
|
||||
|
@ -31,6 +31,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#61AFEF",
|
||||
"properties": {
|
||||
|
@ -41,6 +42,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#ffeb3b",
|
||||
"properties": {
|
||||
|
@ -56,6 +58,7 @@
|
|||
{
|
||||
"type": "battery",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#ffeb3b",
|
||||
"properties": {
|
||||
|
@ -73,6 +76,7 @@
|
|||
{
|
||||
"type": "shell",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#0077c2",
|
||||
"properties": {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffe9aa",
|
||||
"properties": {
|
||||
|
@ -17,6 +17,7 @@
|
|||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
|
@ -26,6 +27,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties": {
|
||||
|
@ -39,6 +41,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
|
@ -54,6 +57,7 @@
|
|||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
|
@ -63,6 +67,7 @@
|
|||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "path",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
|
@ -24,6 +23,7 @@
|
|||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
|
@ -34,6 +34,7 @@
|
|||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
|
@ -49,6 +50,7 @@
|
|||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
|
@ -58,6 +60,7 @@
|
|||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
|
|
19
engine.go
19
engine.go
|
@ -26,12 +26,16 @@ func (e *engine) getPowerlineColor(foreground bool) string {
|
|||
return e.previousActiveSegment.Background
|
||||
}
|
||||
|
||||
func (e *engine) writePowerLineSeparator(background string, foreground string) {
|
||||
if e.activeBlock.InvertPowerlineSeparatorColor {
|
||||
e.renderer.write(foreground, background, e.activeBlock.PowerlineSeparator)
|
||||
func (e *engine) writePowerLineSeparator(background string, foreground string, end bool) {
|
||||
symbol := e.activeSegment.PowerlineSymbol
|
||||
if end {
|
||||
symbol = e.previousActiveSegment.PowerlineSymbol
|
||||
}
|
||||
if e.activeSegment.InvertPowerlineSymbolColor {
|
||||
e.renderer.write(foreground, background, symbol)
|
||||
return
|
||||
}
|
||||
e.renderer.write(background, foreground, e.activeBlock.PowerlineSeparator)
|
||||
e.renderer.write(background, foreground, symbol)
|
||||
}
|
||||
|
||||
func (e *engine) endPowerline() {
|
||||
|
@ -39,12 +43,12 @@ func (e *engine) endPowerline() {
|
|||
e.activeSegment.Style != Powerline &&
|
||||
e.previousActiveSegment != nil &&
|
||||
e.previousActiveSegment.Style == Powerline {
|
||||
e.writePowerLineSeparator(e.getPowerlineColor(false), e.previousActiveSegment.Background)
|
||||
e.writePowerLineSeparator(e.getPowerlineColor(false), e.previousActiveSegment.Background, true)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *engine) renderPowerLineSegment(text string) {
|
||||
e.writePowerLineSeparator(e.activeSegment.Background, e.getPowerlineColor(true))
|
||||
e.writePowerLineSeparator(e.activeSegment.Background, e.getPowerlineColor(true), false)
|
||||
e.renderText(text)
|
||||
}
|
||||
|
||||
|
@ -99,8 +103,9 @@ func (e *engine) renderBlockSegments(block *Block) string {
|
|||
e.renderSegmentText(text)
|
||||
}
|
||||
if e.previousActiveSegment != nil && e.previousActiveSegment.Style == Powerline {
|
||||
e.writePowerLineSeparator(Transparent, e.previousActiveSegment.Background)
|
||||
e.writePowerLineSeparator(Transparent, e.previousActiveSegment.Background, true)
|
||||
}
|
||||
// e.endPowerline()
|
||||
return e.renderer.string()
|
||||
}
|
||||
|
||||
|
|
11
main.go
11
main.go
|
@ -11,6 +11,7 @@ type args struct {
|
|||
ErrorCode *int
|
||||
PrintConfig *bool
|
||||
Config *string
|
||||
Shell *string
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -27,6 +28,10 @@ func main() {
|
|||
"config",
|
||||
"",
|
||||
"Add the path to a configuration you wish to load"),
|
||||
Shell: flag.String(
|
||||
"shell",
|
||||
"",
|
||||
"Override the shell you are working in"),
|
||||
}
|
||||
flag.Parse()
|
||||
env := &environment{
|
||||
|
@ -41,7 +46,11 @@ func main() {
|
|||
colorWriter := &Renderer{
|
||||
Buffer: new(bytes.Buffer),
|
||||
}
|
||||
colorWriter.init(env.getShellName())
|
||||
shell := env.getShellName()
|
||||
if *args.Shell != "" {
|
||||
shell = *args.Shell
|
||||
}
|
||||
colorWriter.init(shell)
|
||||
engine := &engine{
|
||||
settings: settings,
|
||||
env: env,
|
||||
|
|
18
segment.go
18
segment.go
|
@ -4,14 +4,16 @@ import "errors"
|
|||
|
||||
//Segment represent a single segment and it's configuration
|
||||
type Segment struct {
|
||||
Type SegmentType `json:"type"`
|
||||
Style SegmentStyle `json:"style"`
|
||||
Foreground string `json:"foreground"`
|
||||
Background string `json:"background"`
|
||||
LeadingDiamond string `json:"leading_diamond"`
|
||||
TrailingDiamond string `json:"trailing_diamond"`
|
||||
Properties map[Property]interface{} `json:"properties"`
|
||||
writer SegmentWriter
|
||||
Type SegmentType `json:"type"`
|
||||
Style SegmentStyle `json:"style"`
|
||||
PowerlineSymbol string `json:"powerline_symbol"`
|
||||
InvertPowerlineSymbolColor bool `json:"invert_powerline_symbol_color"`
|
||||
Foreground string `json:"foreground"`
|
||||
Background string `json:"background"`
|
||||
LeadingDiamond string `json:"leading_diamond"`
|
||||
TrailingDiamond string `json:"trailing_diamond"`
|
||||
Properties map[Property]interface{} `json:"properties"`
|
||||
writer SegmentWriter
|
||||
}
|
||||
|
||||
//SegmentWriter is the interface used to define what and if to write to the prompt
|
||||
|
|
71
settings.go
71
settings.go
|
@ -31,13 +31,11 @@ const (
|
|||
|
||||
//Block defines a part of the prompt with optional segments
|
||||
type Block struct {
|
||||
Type BlockType `json:"type"`
|
||||
Alignment BlockAlignment `json:"alignment"`
|
||||
PowerlineSeparator string `json:"powerline_separator"`
|
||||
InvertPowerlineSeparatorColor bool `json:"invert_powerline_separator_color"`
|
||||
HorizontalOffset int `json:"horizontal_offset"`
|
||||
VerticalOffset int `json:"vertical_offset"`
|
||||
Segments []*Segment `json:"segments"`
|
||||
Type BlockType `json:"type"`
|
||||
Alignment BlockAlignment `json:"alignment"`
|
||||
HorizontalOffset int `json:"horizontal_offset"`
|
||||
VerticalOffset int `json:"vertical_offset"`
|
||||
Segments []*Segment `json:"segments"`
|
||||
}
|
||||
|
||||
//GetSettings returns the default configuration including possible user overrides
|
||||
|
@ -72,45 +70,50 @@ func getDefaultSettings() *Settings {
|
|||
EndSpaceEnabled: true,
|
||||
Blocks: []*Block{
|
||||
{
|
||||
Type: Prompt,
|
||||
Alignment: Left,
|
||||
PowerlineSeparator: "",
|
||||
Type: Prompt,
|
||||
Alignment: Left,
|
||||
Segments: []*Segment{
|
||||
{
|
||||
Type: Root,
|
||||
Style: Powerline,
|
||||
Background: "#ffe9aa",
|
||||
Foreground: "#100e23",
|
||||
Type: Root,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#ffe9aa",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Session,
|
||||
Style: Powerline,
|
||||
Background: "#ffffff",
|
||||
Foreground: "#100e23",
|
||||
Type: Session,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#ffffff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Path,
|
||||
Style: Powerline,
|
||||
Background: "#91ddff",
|
||||
Foreground: "#100e23",
|
||||
Type: Path,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#91ddff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Git,
|
||||
Style: Powerline,
|
||||
Background: "#95ffa4",
|
||||
Foreground: "#100e23",
|
||||
Type: Git,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#95ffa4",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Venv,
|
||||
Style: Powerline,
|
||||
Background: "#906cff",
|
||||
Foreground: "#100e23",
|
||||
Type: Venv,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#906cff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Exit,
|
||||
Style: Powerline,
|
||||
Background: "#ff8080",
|
||||
Foreground: "#ffffff",
|
||||
Type: Exit,
|
||||
Style: Powerline,
|
||||
PowerlineSymbol: "",
|
||||
Background: "#ff8080",
|
||||
Foreground: "#ffffff",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue