forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_title.go
54 lines (47 loc) · 1.14 KB
/
console_title.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"strings"
)
type consoleTitle struct {
env environmentInfo
config *Config
ansi *ansiUtils
}
// ConsoleTitleStyle defines how to show the title in the console window
type ConsoleTitleStyle string
const (
// FolderName show the current folder name
FolderName ConsoleTitleStyle = "folder"
// FullPath show the current path
FullPath ConsoleTitleStyle = "path"
// Template allows a more powerful custom string
Template ConsoleTitleStyle = "template"
)
func (t *consoleTitle) getConsoleTitle() string {
var title string
switch t.config.ConsoleTitleStyle {
case FullPath:
title = t.getPwd()
case Template:
title = t.getTemplateText()
case FolderName:
fallthrough
default:
title = base(t.getPwd(), t.env)
}
title = t.ansi.escapeText(title)
return fmt.Sprintf(t.ansi.title, title)
}
func (t *consoleTitle) getTemplateText() string {
template := &textTemplate{
Template: t.config.ConsoleTitleTemplate,
Env: t.env,
}
return template.renderPlainContextTemplate(nil)
}
func (t *consoleTitle) getPwd() string {
pwd := t.env.getcwd()
pwd = strings.Replace(pwd, t.env.homeDir(), "~", 1)
return pwd
}