feat: remove enable_hyperlink

This commit is contained in:
Jan De Dobbeleer 2022-01-23 18:48:55 +01:00 committed by Jan De Dobbeleer
parent b816a0bf70
commit f5178e8c8c
37 changed files with 45 additions and 225 deletions

View file

@ -50,8 +50,7 @@ sidebar_label: Sample
"style": "folder",
"exclude_folders": [
"/super/secret/project"
],
"enable_hyperlink": false
]
}
},
{

View file

@ -27,7 +27,6 @@ The free tier for *Current weather and forecasts collection* is sufficient.
"apikey": "<YOUR_API_KEY>",
"location": "AMSTERDAM,NL",
"units": "metric",
"enable_hyperlink" : false,
"http_timeout": 20,
"cache_timeout": 10,
"template": "{{.Weather}} ({{.Temperature}}{{.UnitIcon}})"
@ -43,7 +42,6 @@ The free tier for *Current weather and forecasts collection* is sufficient.
Please, refer to ISO 3166 for the state codes or country codes - defaults to `DE BILT,NL`
- units: `string` - Units of measurement.
Available values are standard (kelvin), metric (celsius), and imperial (fahrenheit) - defaults to `standard`
- enable_hyperlink: `bool` - Displays an hyperlink to get openweathermap data
- http_timeout: `int` - The default timeout for http request is 20ms.
- cache_timeout: `int` - The default timeout for request caching is 10m. A value of 0 disables the cache.
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the

View file

@ -33,8 +33,6 @@ Display the current path.
- folder_icon: `string` - the icon to use as a folder indication - defaults to `..`
- windows_registry_icon: `string` - the icon to display when in the Windows registry - defaults to `\uE0B1`
- style: `enum` - how to display the current path
- enable_hyperlink: `boolean` - displays an hyperlink for the path - defaults to `false`
- mixed_threshold: `number` - the maximum length of a path segment that will be displayed when using `Mixed` -
defaults to `4`
- max_depth: `number` - maximum path depth to display before shortening when using `Agnoster Short` - defaults to `1`

View file

@ -19,7 +19,6 @@ Display the currently active php version.
"background": "#4063D8",
"properties": {
"prefix": " \ue73d ",
"enable_hyperlink": false
}
}
```
@ -33,7 +32,6 @@ Display the currently active php version.
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
- `files`: the segment is only displayed when `*.php, composer.json, composer.lock, .php-version` files are present (default)
- enable_hyperlink: `bool` - display an hyperlink to the php release notes - defaults to `false`
## [Template][templates] Properties

View file

@ -68,7 +68,6 @@ if that color is visible against any of your backgrounds.
- SkiingIcon - defaults to `\ue213`
- WorkOutIcon - defaults to `\ue213`
- UnknownActivityIcon - defaults to `\ue213`
- enable_hyperlink - display an hyperlink to activities - defaults to `false`
## [Template][templates] Properties

View file

@ -39,8 +39,6 @@ type TransientPrompt struct {
}
const (
// EnableHyperlink enable hyperlink
EnableHyperlink Property = "enable_hyperlink"
// HTTPTimeout timeout used when executing http request
HTTPTimeout Property = "http_timeout"
// DefaultHTTPTimeout default timeout used when executing http request

View file

@ -48,7 +48,7 @@ func (a *angular) init(props Properties, env Environment) {
},
},
},
versionURLTemplate: "[%s](https://github.com/angular/angular/releases/tag/%s.%s.%s)",
versionURLTemplate: "https://github.com/angular/angular/releases/tag/{{.Full}}",
}
}

View file

@ -24,7 +24,7 @@ func (c *crystal) init(props Properties, env Environment) {
regex: `Crystal (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://github.com/crystal-lang/crystal/releases/tag/%s.%s.%s)",
versionURLTemplate: "https://github.com/crystal-lang/crystal/releases/tag/{{ .Full }}",
}
}

View file

@ -24,7 +24,7 @@ func (d *dart) init(props Properties, env Environment) {
regex: `Dart SDK version: (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://dart.dev/guides/language/evolution#dart-%s%s)",
versionURLTemplate: "https://dart.dev/guides/language/evolution#dart-{{ .Major }}{{ .Minor }}",
}
}

View file

@ -353,25 +353,6 @@ func (l *language) string() string {
return err.Error()
}
if l.props.getBool(EnableHyperlink, false) {
versionURLTemplate := l.props.getString(VersionURLTemplate, "")
// backward compatibility
if versionURLTemplate == "" {
text = l.buildVersionURL(text)
} else {
template := &textTemplate{
Template: versionURLTemplate,
Context: l.version,
Env: l.env,
}
url, err := template.render()
if err != nil {
return err.Error()
}
text = url
}
}
if l.props.getBool(EnableVersionMismatch, false) {
l.setVersionFileMismatch()
}

View file

@ -30,7 +30,7 @@ func (d *dotnet) init(props Properties, env Environment) {
`(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?))`,
},
},
versionURLTemplate: "[%1s](https://github.com/dotnet/core/blob/master/release-notes/%[2]s.%[3]s/%[2]s.%[3]s.%[4]s/%[2]s.%[3]s.%[4]s.md)",
versionURLTemplate: "https://github.com/dotnet/core/blob/master/release-notes/{{ .Major }}.{{ .Minor }}/{{ .Major }}.{{ .Minor }}.{{ .Patch }}/{{ .Major }}.{{ .Minor }}.{{ .Patch }}.md)", // nolint: lll
}
}

View file

@ -36,7 +36,7 @@ func (g *golang) init(props Properties, env Environment) {
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+)(.(?P<patch>[0-9]+))?)))`,
},
},
versionURLTemplate: "[%s](https://golang.org/doc/go%s.%s)",
versionURLTemplate: "https://golang.org/doc/go{{ .Major }}.{{ .Minor }})",
}
}

View file

@ -24,7 +24,7 @@ func (j *julia) init(props Properties, env Environment) {
regex: `julia version (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://github.com/JuliaLang/julia/releases/tag/v%s.%s.%s)",
versionURLTemplate: "https://github.com/JuliaLang/julia/releases/tag/v{{ .Full }})",
}
}

View file

@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
"strings"
)
type loadContext func()
@ -20,6 +19,7 @@ type version struct {
Patch string
Prerelease string
BuildMetadata string
URL string
}
type cmd struct {
@ -93,25 +93,6 @@ func (l *language) renderTemplate(segmentTemplate string, context SegmentWriter)
if err != nil {
return err.Error()
}
// TODO: this needs to be removed or refactored
if !l.props.getBool(EnableHyperlink, false) {
return text
}
versionURLTemplate := l.props.getString(VersionURLTemplate, "")
// backward compatibility
if versionURLTemplate == "" {
return l.buildVersionURL(text)
}
template = &textTemplate{
Template: versionURLTemplate,
Context: l.version,
Env: l.env,
}
text, err = template.render()
if err != nil {
return err.Error()
}
return text
}
@ -196,6 +177,7 @@ func (l *language) setVersion() error {
return fmt.Errorf("err parsing info from %s with %s", command.executable, versionStr)
}
l.version = *version
l.buildVersionURL()
return nil
}
return errors.New(l.props.getString(MissingCommandText, ""))
@ -226,27 +208,19 @@ func (l *language) setVersionFileMismatch() {
l.colorMismatch()
}
func (l *language) buildVersionURL(text string) string {
if l.versionURLTemplate == "" {
return text
func (l *language) buildVersionURL() {
versionURLTemplate := l.props.getString(VersionURLTemplate, l.versionURLTemplate)
if len(versionURLTemplate) == 0 {
return
}
truncatingSprintf := func(str string, args ...interface{}) (string, error) {
n := strings.Count(str, "%s")
if n > len(args) {
return "", errors.New("Too many parameters")
template := &textTemplate{
Template: versionURLTemplate,
Context: l.version,
Env: l.env,
}
if n == 0 {
return fmt.Sprintf(str, args...), nil
}
arguments := make([]interface{}, 0, n)
for i := 0; i < n; i++ {
arguments = append(arguments, args[i])
}
return fmt.Sprintf(str, arguments...), nil
}
version, err := truncatingSprintf(l.versionURLTemplate, text, l.version.Major, l.version.Minor, l.version.Patch)
url, err := template.render()
if err != nil {
return text
return
}
return version
l.version.URL = url
}

View file

@ -353,9 +353,6 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) {
}
func TestLanguageHyperlinkEnabled(t *testing.T) {
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
commands: []*cmd{
{
@ -369,22 +366,19 @@ func TestLanguageHyperlinkEnabled(t *testing.T) {
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s)",
versionURLTemplate: "https://unicor.org/doc/{{ .Full }}",
extensions: []string{uni, corn},
enabledExtensions: []string{corn},
enabledCommands: []string{"corn"},
version: universion,
properties: props,
properties: properties{},
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.enabled())
assert.Equal(t, "[1.3.307](https://unicor.org/doc/1.3.307)", lang.string())
assert.Equal(t, "https://unicor.org/doc/1.3.307", lang.version.URL)
}
func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
commands: []*cmd{
{
@ -398,47 +392,18 @@ func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
regex: `wrong`,
},
},
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s)",
versionURLTemplate: "https://unicor.org/doc/{{ .Full }}",
extensions: []string{uni, corn},
enabledExtensions: []string{corn},
enabledCommands: []string{"corn"},
version: universion,
properties: props,
properties: properties{},
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.enabled())
assert.Equal(t, "err parsing info from corn with 1.3.307", lang.string())
}
func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
commands: []*cmd{
{
executable: "uni",
args: []string{"--version"},
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
{
executable: "corn",
args: []string{"--version"},
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://unicor.org/doc/%s)",
extensions: []string{uni, corn},
enabledExtensions: []string{corn},
enabledCommands: []string{"corn"},
version: universion,
properties: props,
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.enabled())
assert.Equal(t, "[1.3.307](https://unicor.org/doc/1)", lang.string())
}
func TestLanguageEnabledInHome(t *testing.T) {
cases := []struct {
Case string
@ -471,32 +436,3 @@ func TestLanguageEnabledInHome(t *testing.T) {
assert.Equal(t, tc.ExpectedEnabled, lang.enabled(), tc.Case)
}
}
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
commands: []*cmd{
{
executable: "uni",
args: []string{"--version"},
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
{
executable: "corn",
args: []string{"--version"},
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s.%s)",
extensions: []string{uni, corn},
enabledExtensions: []string{corn},
enabledCommands: []string{"corn"},
version: universion,
properties: props,
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.enabled())
assert.Equal(t, "1.3.307", lang.string())
}

View file

@ -218,7 +218,6 @@ func TestOWMSegmentIcons(t *testing.T) {
Location: "AMSTERDAM,NL",
Units: "metric",
CacheTimeout: 0,
EnableHyperlink: true,
SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})",
},
env: env,
@ -264,7 +263,6 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
EnableHyperlink: true,
SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})",
},
env: env,

View file

@ -14,6 +14,7 @@ type path struct {
pwd string
Path string
StackCount int
Location string
}
const (
@ -79,12 +80,10 @@ func (pt *path) enabled() bool {
pt.Path = fmt.Sprintf("Path style: %s is not available", style)
}
pt.Path = pt.formatWindowsDrive(pt.Path)
if pt.props.getBool(EnableHyperlink, false) {
// wsl check
if pt.env.isWsl() {
pt.pwd, _ = pt.env.runCommand("wslpath", "-m", pt.pwd)
}
pt.Path = fmt.Sprintf("[%s](file://%s)", pt.Path, pt.pwd)
pt.Location, _ = pt.env.runCommand("wslpath", "-m", pt.pwd)
} else {
pt.Location = pt.pwd
}
pt.StackCount = pt.env.stackCount()

View file

@ -429,6 +429,7 @@ func TestAgnosterPathStyles(t *testing.T) {
env.On("pwd").Return(tc.Pwd)
env.On("getRuntimeGOOS").Return(tc.GOOS)
env.On("stackCount").Return(0)
env.On("isWsl").Return(false)
args := &args{
PSWD: &tc.Pswd,
}
@ -551,6 +552,7 @@ func TestGetFullPath(t *testing.T) {
env.On("pwd").Return(tc.Pwd)
env.On("getRuntimeGOOS").Return(tc.GOOS)
env.On("stackCount").Return(tc.StackCount)
env.On("isWsl").Return(false)
args := &args{
PSWD: &tc.Pswd,
}

View file

@ -20,6 +20,7 @@ type strava struct {
Hours int
Authenticate bool
Error string
URL string
}
const (
@ -130,9 +131,7 @@ func (s *strava) string() string {
if err != nil {
return err.Error()
}
if s.props.getBool(EnableHyperlink, false) {
text = fmt.Sprintf("[%s](https://www.strava.com/activities/%d)", text, s.ID)
}
s.URL = fmt.Sprintf("https://www.strava.com/activities/%d", s.ID)
return text
}

View file

@ -40,8 +40,7 @@
"home_icon": "",
"folder_icon": " \uf07b ",
"style": "folder",
"prefix": " \uf07b\uf553",
"enable_hyperlink": true
"prefix": " \uf07b\uf553"
}
},
{

View file

@ -22,9 +22,7 @@
"foreground": "#ff5555",
"properties": {
"prefix": "<#ffffff>[</>",
"postfix": "<#ffffff>]</>",
"style": "folder",
"enable_hyperlink": true
"postfix": "<#ffffff>]</>"
}
},
{

View file

@ -141,9 +141,7 @@
"properties": {
"folder_separator_icon": " \uf554 ",
"home_icon": "\uf7db ",
"folder_icon": "\uf07b ",
"style": "agnoster_full",
"enable_hyperlink": true
"folder_icon": "\uf07b "
}
}
]

View file

@ -109,7 +109,6 @@
"properties": {
"prefix": "<#000000> \ue5ff </>",
"style": "agnoster_short",
"enable_hyperlink": true,
"home_icon": "\uF7DB ",
"folder_icon": "<#000000>\ue5fe </>",
"folder_separator_icon": "<#000000>\uE0B1 </>"

View file

@ -58,8 +58,7 @@
"properties": {
"style": "mixed",
"home_icon": "\uf7dd ",
"prefix": "",
"enable_hyperlink": true
"prefix": ""
}
},
{

View file

@ -45,9 +45,7 @@
"foreground": "#fffef9",
"background": "#C678DD",
"properties": {
"style": "full",
"prefix": "",
"enable_hyperlink": false
"style": "full"
}
},
{

View file

@ -58,7 +58,6 @@
"folder_separator_icon": "/",
"prefix": " \uE5FE ",
"home_icon": "~",
"enable_hyperlink": true,
"max_depth": 2
}
},

View file

@ -49,8 +49,7 @@
"folder_separator_icon": " <#011627>\uE0B1</> ",
"home_icon": "\uf7db ",
"folder_icon": "\uf07c ",
"style": "agnoster",
"enable_hyperlink": true
"style": "agnoster"
}
},
{

View file

@ -37,7 +37,6 @@
"folder_separator_icon": "\ue0b9",
"mixed_threshold": 8,
"style": "mixed",
"enable_hyperlink": true,
"mapped_locations": {
"C:\\Users": "\uf007",
"C:\\Windows": "\ue62a"

View file

@ -103,7 +103,6 @@
"properties": {
"prefix": "<#f2f200> \ue5ff </>",
"style": "agnoster_short",
"enable_hyperlink": true,
"home_icon": "\uF7DB ",
"folder_icon": "<#B5B2C2>\ue5fe </>",
"folder_separator_icon": "<#ffea00>\uE0B1 </>"

View file

@ -39,12 +39,6 @@
"description": "Fetch the version number",
"default": true
},
"enable_hyperlink": {
"type": "boolean",
"title": "Enable hyperlink",
"description": "Displays an hyperlink for the current segment",
"default": false
},
"http_timeout": {
"type": "integer",
"title": "Http request timeout",
@ -407,9 +401,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -614,9 +605,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -643,9 +631,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -672,9 +657,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -701,9 +683,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -730,9 +709,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -907,9 +883,6 @@
"title": "NPM Icon",
"description": "Icon/text to use for NPM",
"default": " \uE71E"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -1167,9 +1140,6 @@
"title": "Enable the Mapped Locations feature",
"description": "Replace known locations in the path with the replacements before applying the style.",
"default": true
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -1199,9 +1169,6 @@
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}
@ -1444,9 +1411,6 @@
"default": "standard",
"enum": ["standard", "metric", "imperial"]
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
},
"http_timeout": {
"$ref": "#/definitions/http_timeout"
},
@ -1595,9 +1559,6 @@
"title": "cache timeout",
"description": "The number of minutes the response is cached. A value of 0 disables the cache.",
"default": 10
},
"enable_hyperlink": {
"$ref": "#/definitions/enable_hyperlink"
}
}
}

View file

@ -63,7 +63,6 @@
"properties": {
"prefix": "<#f2f200> \ue5ff </>",
"style": "agnoster_short",
"enable_hyperlink": true,
"home_icon": "\uf015",
"folder_icon": "<#B5B2C2>\ue5fe </>",
"folder_separator_icon": "<#B5B2C2>\ue0bf </>"

View file

@ -63,7 +63,6 @@
"properties": {
"prefix": "<#f2f200> \ue5ff </>",
"style": "full",
"enable_hyperlink": false,
"folder_icon": "<#B5B2C2>\ue5fe </>"
}
},

View file

@ -24,8 +24,7 @@
"home_icon": "\u2764",
"folder_separator_icon": " 🢖 ",
"prefix": "<#eaeaea>⎧</> ⟨",
"postfix": "⟩ ",
"enable_hyperlink": false
"postfix": "⟩ "
}
},
{

View file

@ -50,8 +50,7 @@
"home_icon": "\uF7DB",
"folder_icon": "\ue5fe",
"folder_separator_icon": "<transparent> \uE0BD </>",
"style": "agnoster_short",
"enable_hyperlink": true
"style": "agnoster_short"
}
},
{

View file

@ -50,8 +50,7 @@
"home_icon": "\uF7DB",
"folder_icon": "\ue5fe",
"folder_separator_icon": "<transparent> \uE0BD </>",
"style": "agnoster_short",
"enable_hyperlink": true
"style": "agnoster_short"
}
},
{

View file

@ -58,8 +58,7 @@
"foreground": "#100e23",
"background": "#91ddff",
"properties": {
"style": "folder",
"enable_hyperlink": false
"style": "folder"
}
},
{

View file

@ -30,8 +30,7 @@
"background": "#0080ff",
"properties": {
"prefix": " \uE5FF ",
"style": "full",
"enable_hyperlink": true
"style": "full"
}
},
{