mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat(log): add segment info
This commit is contained in:
parent
1f59e3d420
commit
5bf3d613ae
|
@ -227,6 +227,7 @@ func (b *Block) Debug() (int, []*SegmentTiming) {
|
|||
if segmentTiming.nameLength > largestSegmentNameLength {
|
||||
largestSegmentNameLength = segmentTiming.nameLength
|
||||
}
|
||||
b.env.DebugF("Segment: %s", segmentTiming.name)
|
||||
start := time.Now()
|
||||
segment.SetEnabled(b.env)
|
||||
segment.SetText()
|
||||
|
|
|
@ -263,6 +263,7 @@ func (e *Engine) PrintDebug(startTime time.Time, version string) string {
|
|||
e.write(log.Text("\nSegments:\n\n").Green().Bold().Plain().String())
|
||||
// console title timing
|
||||
titleStartTime := time.Now()
|
||||
e.Env.Debug("Segment: Title")
|
||||
title := e.getTitleTemplateText()
|
||||
consoleTitleTiming := &SegmentTiming{
|
||||
name: "ConsoleTitle",
|
||||
|
|
|
@ -48,15 +48,6 @@ func Debug(message string) {
|
|||
printLn(debug, header, message)
|
||||
}
|
||||
|
||||
func DebugF(fn func() string) {
|
||||
if !enabled {
|
||||
return
|
||||
}
|
||||
fn2, line := funcSpec()
|
||||
header := fmt.Sprintf("%s:%d", fn2, line)
|
||||
printLn(debug, header, fn())
|
||||
}
|
||||
|
||||
func Error(err error) {
|
||||
if !enabled {
|
||||
return
|
||||
|
|
|
@ -256,6 +256,10 @@ func (env *MockedEnvironment) Debug(message string) {
|
|||
_ = env.Called(message)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) DebugF(format string, a ...any) {
|
||||
_ = env.Called(format, a)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) Error(err error) {
|
||||
_ = env.Called(err)
|
||||
}
|
||||
|
|
|
@ -257,6 +257,7 @@ type Environment interface {
|
|||
CursorPosition() (row, col int)
|
||||
SystemInfo() (*SystemInfo, error)
|
||||
Debug(message string)
|
||||
DebugF(format string, a ...any)
|
||||
Error(err error)
|
||||
Trace(start time.Time, args ...string)
|
||||
}
|
||||
|
@ -379,12 +380,16 @@ func (env *Shell) Debug(message string) {
|
|||
log.Debug(message)
|
||||
}
|
||||
|
||||
func (env *Shell) Error(err error) {
|
||||
log.Error(err)
|
||||
func (env *Shell) DebugF(format string, a ...any) {
|
||||
if !env.CmdFlags.Debug {
|
||||
return
|
||||
}
|
||||
message := fmt.Sprintf(format, a...)
|
||||
log.Debug(message)
|
||||
}
|
||||
|
||||
func (env *Shell) debugF(fn func() string) {
|
||||
log.DebugF(fn)
|
||||
func (env *Shell) Error(err error) {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
func (env *Shell) Getenv(key string) string {
|
||||
|
@ -456,7 +461,7 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool {
|
|||
return false
|
||||
}
|
||||
hasFilesInDir := len(matches) > 0
|
||||
env.debugF(func() string { return strconv.FormatBool(hasFilesInDir) })
|
||||
env.DebugF("%t", hasFilesInDir)
|
||||
return hasFilesInDir
|
||||
}
|
||||
|
||||
|
@ -488,8 +493,9 @@ func (env *Shell) HasFolder(folder string) bool {
|
|||
env.Debug("false")
|
||||
return false
|
||||
}
|
||||
env.debugF(func() string { return strconv.FormatBool(f.IsDir()) })
|
||||
return f.IsDir()
|
||||
isDir := f.IsDir()
|
||||
env.DebugF("%t", isDir)
|
||||
return isDir
|
||||
}
|
||||
|
||||
func (env *Shell) ResolveSymlink(path string) (string, error) {
|
||||
|
@ -525,13 +531,7 @@ func (env *Shell) LsDir(path string) []fs.DirEntry {
|
|||
env.Error(err)
|
||||
return nil
|
||||
}
|
||||
env.debugF(func() string {
|
||||
var entriesStr string
|
||||
for _, entry := range entries {
|
||||
entriesStr += entry.Name() + "\n"
|
||||
}
|
||||
return entriesStr
|
||||
})
|
||||
env.DebugF("%v", entries)
|
||||
return entries
|
||||
}
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ func (env *Shell) isWriteable(folder string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
env.debugF(func() string { return ace.AccessMask.permissions() })
|
||||
env.DebugF("%v", ace.AccessMask.permissions())
|
||||
if ace.AccessMask.canWrite() {
|
||||
env.Debug("user has write access")
|
||||
return true
|
||||
|
|
Loading…
Reference in a new issue