Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Azure functions' segment gets wrapped to next line #1108

Closed
1 task done
JatinSanghvi opened this issue Oct 23, 2021 · 5 comments · Fixed by #1119
Closed
1 task done

'Azure functions' segment gets wrapped to next line #1108

JatinSanghvi opened this issue Oct 23, 2021 · 5 comments · Fixed by #1119
Assignees
Labels
🐛 bug Something isn't working 🤔 info needed Further information is requested

Comments

@JatinSanghvi
Copy link

Code of Conduct

  • I agree to follow this project's Code of Conduct

What happened?

I have set display_version property value to true in azfunc segment. That makes the prompt wrap to next line for some reason.

Segment

{
  "type": "azfunc",
  "style": "plain",
  "foreground": "#333",
  "background": "#ccc",
  "properties": {
    "display_version": true
  }
}

PowerShell

image

Version

5.12.1

Theme

Custom Theme

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Relevant log output

No response

@JatinSanghvi JatinSanghvi added the 🐛 bug Something isn't working label Oct 23, 2021
@JatinSanghvi JatinSanghvi changed the title 'Azure functions' segment spans across line 'Azure functions' segment gets wrapped to next line Oct 23, 2021
@JanDeDobbeleer
Copy link
Owner

Interesting. Maybe there's a line break in the output.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 24, 2021

@JatinSanghvi I can't reproduce this, can I get the full theme config?

image

@JanDeDobbeleer JanDeDobbeleer added the 🤔 info needed Further information is requested label Oct 24, 2021
@JatinSanghvi
Copy link
Author

JatinSanghvi commented Oct 25, 2021

@JanDeDobbeleer - Here's the complete config:

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "azfunc",
          "style": "plain",
          "foreground": "black",
          "background": "white",
          "properties": {
            "display_version": true
          }
        }
      ]
    }
  ],
  "final_space": true
}

I also installed Azure Functions Core Tools on Ubuntu 18.04 WSL, and set the same config for bash shell. Did not find any problem there.

image

@JatinSanghvi
Copy link
Author

JatinSanghvi commented Oct 25, 2021

Here's a short Go program I came up with that should give the clue.

package main

import (
	"fmt"
	"regexp"
)

func main() {
	ver := parse(`(?P<version>.+)`, "3.0.3785\x0d\x0a")
	fmt.Println("Windows PowerShell: Azure Functions version segment", []byte(ver.full))

	ver = parse(`(?:(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?:\d{2})(?P<patch>[0-9]{1}))))`, "5.0.402\x0d\x0a")
	fmt.Println("Windows PowerShell: .NET version segment           ", []byte(ver.full))

	ver = parse(`(?P<version>.+)`, "3.0.3785\x0a")
	fmt.Println("Ubuntu Bash:        Azure Functions version segment", []byte(ver.full))
}

type version struct {
	full, major, minor, patch string
}

func parse(regex, versionInfo string) version {
	values := findNamedRegexMatch(regex, versionInfo)
	return version{values["version"], values["major"], values["minor"], values["patch"]}
}

func findNamedRegexMatch(pattern, text string) map[string]string {
	re := regexp.MustCompile(pattern)
	match := re.FindStringSubmatch(text)

	result := make(map[string]string)
	for i, name := range re.SubexpNames() {
		if i == 0 {
			continue
		}
		result[name] = match[i]
	}
	return result
}

Output

Windows PowerShell: Azure Functions version segment [51 46 48 46 51 55 56 53 13]
Windows PowerShell: .NET version segment            [53 46 48 46 52 48 50]
Ubuntu Bash:        Azure Functions version segment [51 46 48 46 51 55 56 53]

Note that only the version of Azure Functions on Windows has carriage return (ASCII code 13 in decimal) added to the end. Updating the value of language.commands.regex property of azfunc struct will be one of the ways to fix it.

Copy link

github-actions bot commented Apr 1, 2024

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Something isn't working 🤔 info needed Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants