Can't get Oh My Posh foreground_templates to work for 'text' segment - oh-my-posh

I cannot seem to get foreground_templates to work for a text segment. Below is the last block of my prompt.
If I am running with normal privileges, I should see just a green "crescent moon" prompt character. If I am running with elevated privileges, I should see a red pill with an "unlocked" icon, followed by a space, then a red crescent moon prompt character.
The {{ if .Root }} template in the text property to add the additional space works. The {{ if .Root }} template in the foreground_templates does not work. No matter what I try, I always get a green crescent moon.
I can work around it using template coloring in the text property, but it is quite a bit uglier:
"text": "{{ if .Root }} <lightRed>\uF5DA</>{{ else }}\uF5DA{{ end }}"
I can't spot anything wrong. Can you?
Environment:
Windows 10
Consoles tested (all render the same):
Windows Terminal 1.11.2921.0
Powershell 5.1
PowerShell 7.0.3
oh-my-posh 6.4.3
SauceCodePro Nerd Font
{
"type": "prompt",
"alignment": "left",
"newline": true,
"segments": [
{
"type": "root",
"style": "diamond",
"leading_diamond": "\uE0B6",
"trailing_diamond": "\uE0B4",
"foreground": "black",
"background": "lightRed",
"properties": {
"root_icon": "\uF13E"
}
},
{
"type": "text",
"style": "plain",
"foreground": "lightGreen",
"foreground_templates": [
"{{ if .Root }}lightRed{{ end }}"
],
"properties": {
"prefix": "",
"text": "{{ if .Root }} {{ end }}\uF5DA"
}
}
]
}

Related

Microsoft Teams Adaptive Card - Dark Mode Color Issue

I am trying to develope a simple messagaging extension app for Microsoft Teams. With the use of Task Modules I can load a simple Adative Card. Works as designed. The only problem I have with it, is that my Adaptive Card has a color issue withing Microsoft Teams in Dark Mode.
Take a look at the image below. 1 shows a very simple Adaptive Card designed via https://adaptivecards.io/designer/ (preview mode). 2 the very same Adaptive Card but now an actual snippet from Microsoft Teams. As you can see the card below has some color issues which makes the input hard to see.
Here is the code I've used:
public async handleTeamsMessagingExtensionFetchTask(
context: TurnContext,
action: any
): Promise<any> {
const adaptiveCard = CardFactory.adaptiveCard({
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "${title}"
},
{
"type": "Input.Text",
"placeholder": "Placeholder text"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3"
});
return {
task: {
type: 'continue',
value: {
card: adaptiveCard,
height: 535,
title: '${title}',
url: null,
width: 500
}
}
};
}
There's not much that can be done about the input box itself in this case, but maybe try changing the colour of the label above it, something like this (I've changed some of your property names as well, as they were invalid case - things like "medium" instead of "Medium":
"size": "medium",
"weight": "bolder",
"text": "${title}",
"color": "good"
Color allows the following values:
"default"
"dark"
"light"
"accent"
"good"
"warning"
"attention"
If you nest your Text input into a Container, you are able change the Container's style to provide a coloured background upon which the Text input sits.
It's not necessarily right for your use case, but it could be a workaround of interest
Container Style colour options
{
"type": "Container",
"style": "emphasis",
"bleed": true,
"items": [
{
"type": "TextBlock",
"text": "Request New Ticket",
"wrap": true,
"fontType": "Default",
"style": "heading",
"size": "Large",
"color": "Good",
"weight": "Bolder",
"horizontalAlignment": "Center"
}
]
}

ARM Template concat with multiline

I'm almost sure last time I was playing with ARM templates there was some trick to make code tidy and concat() with multiple lines. Yes, I know I could use
"myvar": "[concat(
'abc',
'def
)]"
if I'm deploying with cli/powershell, but I won't control the tools of the template's users, so they'll very likely just copy-paste into web console.
Any idea? Besides having a custom function to join multi-line text encoded as array:
"variables": {
"splitStr": [
"first line",
"second line",
"third line"
],
"output": "[custom.join(variables('splitStr'))]"
},
"functions": [
{
"namespace": "custom",
"members": {
"join": {
"parameters": [
{
"type": "array",
"name": "splitStr"
}
],
"output": {
"type": "string",
"value": "[replace(replace(replace(string(parameters('splitStr')), '[\"', ''), '\"]', ''), '\",\"', '\\n')]"
}
}
}
}
],
We're talking about a working sample code pushing hundred-ish lines of configuration text into a deployed VM, so text readability is important.

Why would a previously stable and working Liquid template fail after the most recent Azure API Management upgrade?

We have an Azure API Management endpoint that receives requests in the following format:
{
"messageType": "EVENT",
"eventData": {
"installedApp": {
"installedAppId": "xxx",
"locationId": "yyy"
},
"events": [
{
"eventTime": "2020-11-13T13:14:50.8011105+00:00",
"eventType": "DEVICE_EVENT",
"deviceEvent": {
"eventId": "3a08b3f3-25b1-11eb-962f-975d499d1166",
"locationId": "yyy",
"ownerId": "a975533a-a1ae-49f7-88f1-94368bd4d605",
"ownerType": "LOCATION",
"deviceId": "c3fdc7c6-08f2-4ba3-92b3-0cdfa2b141f5",
"componentId": "main",
"capability": "motionSensor",
"attribute": "motion",
"value": "inactive",
"valueType": "string",
"stateChange": true,
"data": {},
"subscriptionName": "all_motion_sub"
}
}
]
}
}
It passes them through a Liquid template:
<set-body template="liquid">{
"id": "{{context.Variables["RequestId"]}}",
"API": "SmartThings",
"InstalledAppId": "{{body.eventData.installedApp.installedAppId}}",
"LocationId": "{{body.eventData.installedApp.locationId}}",
"DeviceEvents":[
{% assign device_events = body.eventData.events | Where: "eventType", "DEVICE_EVENT" %}
{% JSONArrayFor event in device_events %}
{
"EventId": "{{event.deviceEvent.eventId}}",
"LocationId": "{{event.deviceEvent.locationId}}",
"DeviceId": "{{event.deviceEvent.deviceId}}",
"ComponentId": "{{event.deviceEvent.componentId}}",
"Capability": "{{event.deviceEvent.capability}}",
"Attribute": "{{event.deviceEvent.attribute}}",
"Value": "{{event.deviceEvent.value}}",
"StateChange": {{event.deviceEvent.stateChange}},
"EventTime": "{{event.eventTime | Date: "yyyy-MM-ddTHH:mm:sszzz" | Default: context.Variables["RequestDateTime"] }}"
}
{% endJSONArrayFor %}
],
"EventTime": "{{context.Variables["RequestDateTime"]}}"
}</set-body>
And generates an output which is sent to a Logic App for further processing:
{
"id": "d5e2a032-14b3-40ca-9c6b-4e13f8d2285c",
"API": "SmartThings",
"InstalledAppId": "xxx",
"LocationId": "yyy",
"DeviceEvents": [
{
"EventId": "3a08b3f3-25b1-11eb-962f-975d499d1166",
"LocationId": "yyy",
"DeviceId": "c3fdc7c6-08f2-4ba3-92b3-0cdfa2b141f5",
"ComponentId": "main",
"Capability": "motionSensor",
"Attribute": "motion",
"Value": "inactive",
"StateChange": true,
"EventTime": "2020-11-13T13:14:50.8011105+00:00"
}
],
"EventTime": "2020-11-13T13:14:50.8011105+00:00"
}
Until around 23:00Z on 11/11/2020, this worked as expected, and had been working in production for several months. Commencing at that time, the Liquid mapping began to fail, producing instead:
{
"id": "2c93647c-f9ef-4747-adfb-985805a71f0c",
"API": "SmartThings",
"InstalledAppId": "xxx",
"LocationId": "yyy",
"DeviceEvents": [
{
"EventId": "",
"LocationId": "",
"DeviceId": "",
"ComponentId": "",
"Capability": "",
"Attribute": "",
"Value": "",
"StateChange": ,
"EventTime": "2020-11-13T13:14:50.8011105+00:00"
}
],
"EventTime": "2020-11-13T13:14:50.8011105+00:00"
}
We have a scheduled maintenance event in the logs to 'Upgrade API Management' from midnight Thursday, so it looks like there was some kind of breaking change.
What changed to cause this, and how do we go about fixing it?
For this problem, I test it in my side and also reproduce your situation. It seems there is bug of liquid template in APIM. After reproduce your problem, I test in another APIM but it doesn't show same problem, the liquid template works fine in that APIM. Then I test in multiple APIM(with same set-body policy and request body) and summarize the result as below:
According to many test and the test result above, I guess it may be some bug after upgrade APIM. And the bug may be related to location or pricing tier(I'm not sure) because I can't find any differences between these APIM except location and pricing tier. So I suggest you to do same job in another APIM(with different location and pricing tier), it will solve the problem temporarily.
===============================Update=============================
I did some further test and found a workaround for this problem. I found the problem was caused by the line {% assign device_events = body.eventData.events | Where: "eventType", "DEVICE_EVENT" %}. If we don't assign body.eventData.events to device_events, instead use body.eventData.events directly in for loop like {% JSONArrayFor event in body.eventData.events %}. Then the liquid template works fine.
So we can just remove the line of "assign" and do "where" condition in for loop. Please refer to my liquid template below:

Can we limit the visibility GUI element in Azure ARM template based on location?

i want to display a Azure GUI element in solution offer only if the deployment is being done in certain region. I know there is a "visible" field for createUIdefinition elements. But Can i use location function with it.
I tried below, it seems to not work though. what am i missing:
{
"name": "MyDropdown",
"type": "Microsoft.Common.DropDown",
"label": "Only show in EastUS",
"defaultValue": "blah",
"toolTip": "select from below",
"constraints": {
"allowedValues": [
{
"label": "yes",
"value": "yes"
},
{
"label": "no",
"value": "no"
},
]
},
"visible": "[ equals(location(), 'eastus') ]"
}
Looks like above example not working for createUIdefinition's basics section. Though , it works for steps section.

Function highlighting with monokai in VS Code / Atom and Sublime

While running Sublime Text 3 and VS Code (or Atom) with the Monokai color theme, the Sublime Text syntax highlighting uses blue for function calls, such as in the example below
However, when I open the same code in VS Code using the monokai theme, functions are not painted blue
I would really like to change that, the code looks much better with function calls highlighted. However, I looked around the web and couldn't find how to change this behavior. Does anyone have any tips for that?
Thanks!
SEE UPDATE BELOW!
Seems like I've found a temporary solution. Go to this folder (if you are on Mac) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/theme-monokai/themes and put this code in monokai-color-theme.json file:
{
"name": "Function call",
"scope": "meta.function-call.generic",
"settings": {
"foreground": "#66d9efff"
}
},
Here is an example how it can look like:
screenshot
But keep in mind, that after theme update this changes may disappear!
UPDATE:
After having a couple more troubles with highlighting, I decided to upload the file with theme to GitHub and keep it up to date. So, if you don't want to dive into the code, just look in my repository: https://github.com/spyker77/monokai-theme-extended
UPDATE (April 2021)
It turns out that the previous solution is not sustainable. Therefore at the moment a better one could be:
In you Visual Studio Code go to "Code" => "Preferences" => "Color Theme" and pick Monokai;
Open settings.json file (how-to);
There will probably already be a bunch of settings in there, so all you need to do is just add the following customisations at the end and before the closing brace (don't forget a trailing comma after the last setting you continue):
"editor.tokenColorCustomizations": {
"[Monokai]": {
"textMateRules": [
{
"name": "Decorator definition decorator",
"scope": "punctuation.definition.decorator.python",
"settings": {
"foreground": "#F92672"
}
},
{
"name": "Meta function-call",
"scope": "meta.function-call.generic.python",
"settings": {
"foreground": "#66D9EF"
}
},
{
"name": "Storage type function async",
"scope": "storage.type.function.async.python",
"settings": {
"foreground": "#F92672",
}
},
{
"name": "Punctuation separator period",
"scope": "punctuation.separator.period.python",
"settings": {
"foreground": "#F8F8F2",
}
},
{
"name": "Entity name function decorator",
"scope": "entity.name.function.decorator.python",
"settings": {
"foreground": "#66D9EF",
}
},
{
"name": "Entity name type class",
"scope": "entity.name.type.class.python",
"settings": {
"fontStyle": ""
}
},
{
"name": "Entity other inherited-class",
"scope": "entity.other.inherited-class.python",
"settings": {
"fontStyle": "italic"
}
},
{
"name": "Support type python",
"scope": "support.type.python",
"settings": {
"fontStyle": ""
}
},
{
"name": "String quoted docstring multi python",
"scope": "string.quoted.docstring.multi.python",
"settings": {
"foreground": "#88846F",
}
}
]
}
}
after trying for server hours finally found a solution and I came back to you to share the solution since I tried the answer above and couldn't make it work.
it turns out that the problem I with VScode extensions (python for Vscode), so disable that first,extension
then go to your setting.json file like that how to open setting
add this to the top of your file
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "meta.function-call.generic",
"settings": {
"foreground":"#19D1E5"
}
}
]
},
and restart VScode and this should work, btw I am using monokai vibrent, and I am sure it will work in any theme you like.
setting.json
like this here
In settings.json:
"editor.tokenColorCustomizations": {
"[Monokai]": {
{
"scope": "entity.name.function",
"settings": {
"foreground": "#fdc306d0", // use your desired color
"fontStyle": "underline" // I like this, foreground color has some reduced opacity
}
}
}
}
might do the trick.

Resources