Skip to content

Commit

Permalink
feat: console title style
Browse files Browse the repository at this point in the history
resolves #149
  • Loading branch information
JanDeDobbeleer committed Nov 13, 2020
1 parent 395a250 commit 7cb752a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions docs/docs/configuration.md
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion engine.go
Expand Up @@ -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 {
Expand Down
18 changes: 14 additions & 4 deletions settings.go
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7cb752a

Please sign in to comment.