mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-10-26 15:13:22 +03:00
Use Once for CachedHostname
This commit is contained in:
parent
e6662e11c3
commit
5b160ea599
@ -96,7 +96,7 @@ func (self *Context) hyperlink_for_path(path string, text string) string {
|
||||
if err == nil && fi.IsDir() {
|
||||
path = strings.TrimSuffix(path, "/") + "/"
|
||||
}
|
||||
host := utils.CachedHostname()
|
||||
host := utils.Hostname()
|
||||
url := "file://" + host + path
|
||||
return self.hyperlink_for_url(url, text)
|
||||
}
|
||||
@ -119,7 +119,7 @@ func (self *Context) link(x string) string {
|
||||
|
||||
func (self *Context) ref_hyperlink(x string, prefix string) string {
|
||||
text, target := text_and_target(x)
|
||||
url := "kitty+doc://" + utils.CachedHostname() + "/#ref=" + prefix + target
|
||||
url := "kitty+doc://" + utils.Hostname() + "/#ref=" + prefix + target
|
||||
text = replace_all_rst_roles(text, func(group rst_format_match) string {
|
||||
return group.payload
|
||||
})
|
||||
|
@ -11,14 +11,10 @@ var _ = fmt.Print
|
||||
|
||||
var hostname string = "*"
|
||||
|
||||
func CachedHostname() string {
|
||||
if hostname == "*" {
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = h
|
||||
} else {
|
||||
hostname = ""
|
||||
}
|
||||
var Hostname = (&Once[string]{Run: func() string {
|
||||
h, err := os.Hostname()
|
||||
if err == nil {
|
||||
return h
|
||||
}
|
||||
return hostname
|
||||
}
|
||||
return ""
|
||||
}}).Get
|
||||
|
Loading…
Reference in New Issue
Block a user