feat: support crystal language

This commit is contained in:
Jan De Dobbeleer 2021-05-14 13:39:49 +02:00 committed by Jan De Dobbeleer
parent a0ae4a7e4b
commit 8f473df62f
5 changed files with 94 additions and 1 deletions

View file

@ -0,0 +1,33 @@
---
id: crystal
title: Crystal
sidebar_label: Crystal
---
## What
Display the currently active crystal version.
## Sample Configuration
```json
{
"type": "crystal",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#4063D8",
"properties": {
"prefix": " \uE370 "
}
}
```
## Properties
- display_version: `boolean` - display the julia version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
- `files`: the segment is only displayed when `*.cr` or `shard.yml` files are present (default)

View file

@ -32,6 +32,7 @@ module.exports = {
"azfunc", "azfunc",
"battery", "battery",
"command", "command",
"crystal",
"dotnet", "dotnet",
"environment", "environment",
"executiontime", "executiontime",

View file

@ -111,6 +111,8 @@ const (
PoshGit SegmentType = "poshgit" PoshGit SegmentType = "poshgit"
// AZFunc writes current AZ func version // AZFunc writes current AZ func version
AZFunc SegmentType = "azfunc" AZFunc SegmentType = "azfunc"
// Crystal writes the active crystal version
Crystal SegmentType = "crystal"
) )
func (segment *Segment) string() string { func (segment *Segment) string() string {
@ -236,6 +238,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
Java: &java{}, Java: &java{},
PoshGit: &poshgit{}, PoshGit: &poshgit{},
AZFunc: &azfunc{}, AZFunc: &azfunc{},
Crystal: &crystal{},
} }
if writer, ok := functions[segment.Type]; ok { if writer, ok := functions[segment.Type]; ok {
props := &properties{ props := &properties{

29
src/segment_crystal.go Normal file
View file

@ -0,0 +1,29 @@
package main
type crystal struct {
language *language
}
func (c *crystal) string() string {
return c.language.string()
}
func (c *crystal) init(props *properties, env environmentInfo) {
c.language = &language{
env: env,
props: props,
extensions: []string{"*.cr", "shard.yml"},
commands: []*cmd{
{
executable: "crystal",
args: []string{"--version"},
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)",
}
}
func (c *crystal) enabled() bool {
return c.language.enabled()
}

View file

@ -152,7 +152,8 @@
"aws", "aws",
"java", "java",
"poshgit", "poshgit",
"azfunc" "azfunc",
"crystal"
] ]
}, },
"style": { "style": {
@ -690,6 +691,32 @@
} }
} }
}, },
{
"if": {
"properties": {
"type": { "const": "crystal" }
}
},
"then": {
"title": "Crystal Segment",
"description": "https://ohmyposh.dev/docs/crystal",
"properties": {
"properties": {
"properties": {
"display_version": {
"$ref": "#/definitions/display_version"
},
"display_mode": {
"$ref": "#/definitions/display_mode"
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
}
}
}
}
}
},
{ {
"if": { "if": {
"properties": { "properties": {