feat: console title style

resolves #149
This commit is contained in:
Jan De Dobbeleer 2020-11-13 13:24:08 +01:00 committed by Jan De Dobbeleer
parent 395a250ca5
commit 7cb752abcb
3 changed files with 30 additions and 7 deletions

View file

@ -47,16 +47,22 @@ theme.
oh-my-posh -config sample.json -shell universal
```
If all goes according to plan, you should see the prompt being printed out on the line below. In case you see a lot of boxes with
question marks, [set up your terminal][setupterm] to use a supported font before continuing.
If all goes according to plan, you should see the prompt being printed out on the line below. In case you see a lot of
boxes with question marks, [set up your terminal][setupterm] to use a supported font before continuing.
## General Settings
- final_space: `boolean` - when true adds a space at the end of the prompt
- console_title: `boolean` - when true sets the current location as the console title
- console_title_style: `string` - the title to set in the console - defaults to `folder`
> "I Like The Way You Speak Words" - Gary Goodspeed
### Console Title Style
- `folder`: show the current folder name
- `path`: show the current path
## Block
Let's take a closer look at what defines a block.

View file

@ -140,7 +140,14 @@ func (e *engine) render() {
}
}
if e.settings.ConsoleTitle {
e.renderer.setConsoleTitle(e.env.getcwd())
switch e.settings.ConsoleTitleStyle {
case FullPath:
e.renderer.setConsoleTitle(e.env.getcwd())
case FolderName:
fallthrough
default:
e.renderer.setConsoleTitle(base(e.env.getcwd(), e.env))
}
}
e.renderer.creset()
if e.settings.FinalSpace {

View file

@ -8,9 +8,10 @@ import (
// Settings holds all the theme for rendering the prompt
type Settings struct {
FinalSpace bool `json:"final_space"`
ConsoleTitle bool `json:"console_title"`
Blocks []*Block `json:"blocks"`
FinalSpace bool `json:"final_space"`
ConsoleTitle bool `json:"console_title"`
ConsoleTitleStyle ConsoleTitleStyle `json:"console_title_style"`
Blocks []*Block `json:"blocks"`
}
// BlockType type of block
@ -19,6 +20,9 @@ type BlockType string
// BlockAlignment aligment of a Block
type BlockAlignment string
// ConsoleTitleStyle defines how to show the title in the console window
type ConsoleTitleStyle string
const (
// Prompt writes one or more Segments
Prompt BlockType = "prompt"
@ -28,6 +32,10 @@ const (
Left BlockAlignment = "left"
// Right aligns right
Right BlockAlignment = "right"
// FolderName show the current folder name
FolderName ConsoleTitleStyle = "folder"
// FullPath show the current path
FullPath ConsoleTitleStyle = "path"
)
// Block defines a part of the prompt with optional segments
@ -74,7 +82,9 @@ func loadUserConfiguration(env environmentInfo) (*Settings, error) {
func getDefaultSettings(info string) *Settings {
settings := &Settings{
FinalSpace: true,
FinalSpace: true,
ConsoleTitle: true,
ConsoleTitleStyle: FolderName,
Blocks: []*Block{
{
Type: Prompt,