JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
16.79k stars 2.35k forks source link

how to configure a two-line prompt with text on both sides #321

Closed sql-sith closed 3 years ago

sql-sith commented 3 years ago

Prerequisites

Description

image

I am trying to create a prompt that looks like the PNG embedded above, which is just a mockup. Notice that the prompt is made up of 4 blocks, labeled 1 through 4. And I'm sorry the two fields on the right are so hard to see - the contrast is better in real life.

I am having trouble getting all 4 blocks to be visible with the cursor landing after block 3. Can you help?

FYI, here are some of the things I have tried:

This put all of the blocks in the right places, but the cursor lands on the screen's far-right end, after block 4.

Here's another experiment:

This causes blocks 1, 2, and 4 to be displayed in their proper spots. However, block 4 begins to display immediately after block 3, on the screen's very far right. It then wraps to the next line, leaving a gap on the left side of the screen between blocks 1 and 3.

Another one:

This time everything is great, except there is a gap between blocks 1 and 3. Makes sense - that's obviously what I requested. But I thought this one was close, so I tried tweaking it:

This caused the first 3 blocks to appear where they should, with the cursor after block 3, which is what I want. However, block 4 is not visible after the prompt renders, so it looks like block 3 deleted everything on the second line before being rendered.

I hope this makes sense. I may have made mistakes above as I'm trying to switch configurations in a single config file and then observe the effect and report it here in this little tiny box. :-) But the point is that I can't find a way to put all 4 blocks where I want them, with the cursor ending up after block 3. Is this possible?

Environment

Steps to Reproduce

  1. Use the attached theme, or one of the variants described above
  2. Observe and ponder

Expected behavior: [What you expected to happen] Blocks 1, 2, 3, 4 all where they are in the mockup, with the cursor placed after block 3.

Actual behavior: [What actually happened] It depends on how I order and configure the blocks (see above).

Here is my theme (this is the final layout discussed above which uses vertical offset):

{
  "blocks": [
    {
      "type": "newline"
    },
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "shell",
          "style": "diamond",
          "leading_diamond": "\uE0B6",
          "trailing_diamond": "\uE0B4",
          "foreground": "#ffffff",
          "background": "#444444",
          "properties": {
            "prefix": " \uFCB5 "
          }
        },
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\uE0B4",
          "foreground": "#151515",
          "background": "#448844",
          "properties": {
            "prefix": " \uE5FF ",
            "styles": "agnoster, agnoster_full, agnoster_short, full, folder",
            "style": "agnoster"
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\uE0B4",
          "foreground": "#111111",
          "background": "yellow",
          "properties": {
            "display_stash_count": true,
            "display_upstream_icon": true
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "right",
      "segments": [
        {
          "type": "envvar",
          "style": "diamond",
          "leading_diamond": "\uE0B6",
          "trailing_diamond": "\uE0B4",
          "foreground": "#555555",
          "background": "#000000",
          "powerline_symbol": "\uE0B4",
          "properties": {
            "var_name": "POSH_lastCommandDuration"
          }
        }
      ]
    },
    {
      "type": "newline"
    },
    {
      "type": "prompt",
      "alignment": "right",
      "segments": [
        {
          "type": "time",
          "style": "diamond",
          "leading_diamond": "\uE0B6",
          "trailing_diamond": "\uE0B4",
          "foreground": "#555555",
          "background": "#000000",
          "powerline_symbol": "\uE0B4",
          "properties": {
            "time_format": "mon 02-jan-2006 15:04"
          }
        }
      ]
    },
    {
      "type": "newline"
    },
    {
      "type": "prompt",
      "alignment": "left",
      "vertical_offset": -1,
      "segments": [
        {
          "type": "session",
          "style": "diamond",
          "leading_diamond": "\uE0B6",
          "trailing_diamond": "\uE0B4",
          "foreground": "#ffffff",
          "background": "blue",
          "powerline_symbol": "\uE0B4"
        },
        {
          "type": "root",
          "style": "powerline",
          "powerline_symbol": "\uE0B4",
          "foreground": "#ffff66",
          "background": "#770000"
        },
        {
          "type": "exit",
          "style": "powerline",
          "powerline_symbol": "\uE0B4",
          "foreground": "red",
          "background": "white",
          "always_enabled": true,
          "always_numeric": true,
          "display_exit_code": true
        }
      ]
    }
  ],
  "final_space": true
}
tradiff commented 3 years ago

Maybe something like this:

image

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh3/main/themes/schema.json",
  "blocks": [
    {
      "type": "rprompt",
      "alignment": "left",
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "text": "block 4"
          }
        }
      ]
    },

    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "text": "block 1"
          }
        }
      ]
    },

    {
      "type": "prompt",
      "alignment": "right",
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "text": "block 2"
          }
        }
      ]
    },

    {
      "type": "newline"
    },

    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "text": "block 3"
          }
        }
      ]
    }
  ]
}
sql-sith commented 3 years ago

Thank you, @TravisTX . I had forgotten about rprompt altogether, and it sounds like it may be meant for exactly what I'm trying to do.

However, I am having trouble reproducing your result. When I run your sample as-is I get this:

image

I've tried tweaking it, but this combination of things makes me uncertain of what to tweak:

Thanks again for the prompt response. Sorry I'm not able to sift an answer out of a good reply like that.

JanDeDobbeleer commented 3 years ago

@sql-sith it seems your version of oh-my-posh is rather old. Updating should do the trick as I don't think your version has rprompt support just yet.

sql-sith commented 3 years ago

@JanDeDobbeleer you are correct. I checked for newer versions tonight but obviously messed it up.

By the way, this is one of the most useful and comprehensive updates to a popular open-source project that I've seen for a while. Great job to all.

github-actions[bot] commented 4 months ago

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.