Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract segments to a dedicated package
This is the first step to allow creating powerline extensions inspired by git and kubectl extensions where an executable starting with powerline-go- will be considered as an extension that should print a segment list on stdout. To make extension developers life easier, export the segment structure they will be able to import to fill their segments and dump it
- Loading branch information
Showing
32 changed files
with
258 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ powerline-go | |
.glide/ | ||
|
||
/.idea/ | ||
~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package powerline | ||
|
||
import ( | ||
runewidth "github.com/mattn/go-runewidth" | ||
) | ||
|
||
// Segment describes an information to display on the command line prompt | ||
type Segment struct { | ||
// Content is the text to be displayed on the command line prompt | ||
Content string | ||
// Foreground is the text color (see https://misc.flogisoft.com/bash/tip_colors_and_formatting#background1) | ||
Foreground uint8 | ||
// Background is the color of the filling background (see https://misc.flogisoft.com/bash/tip_colors_and_formatting#background1) | ||
Background uint8 | ||
// Separator is the character to be used when generating multiple segments to override the default separator | ||
Separator string | ||
// SeparatorForeground is the character to be used when generating multiple segments to override the default foreground separator | ||
SeparatorForeground uint8 | ||
// Priority is the priority of the segment. The higher, the less probable the segment will be dropped if the total length is too long | ||
Priority int | ||
// HideSeparators indicated not to display any separator with next segment. | ||
HideSeparators bool | ||
Width int | ||
} | ||
|
||
func (s Segment) ComputeWidth(condensed bool) int { | ||
if condensed { | ||
return runewidth.StringWidth(s.Content) + runewidth.StringWidth(s.Separator) | ||
} | ||
return runewidth.StringWidth(s.Content) + runewidth.StringWidth(s.Separator) + 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.