Skip to content

Commit

Permalink
fix custom formatters on pointer types
Browse files Browse the repository at this point in the history
  • Loading branch information
a committed Feb 29, 2024
1 parent 63569dc commit a51f0b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions detailviewers.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func (c *CustomFormatter) Format(v *Variable) {
return
}
v.reformatted = true
v.customFormat = true
switch sv := sv.(type) {
case starlark.String:
v.Value = string(sv)
Expand Down
10 changes: 6 additions & 4 deletions infovars.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const (

var changedVariableOpacity uint8

const maxChangedVariableOpacity = 0xd0
const minChangedVariableOpacity = 0x10
const maxChangedVariableOpacity = 0xa0
const minChangedVariableOpacity = 0x08
const opacityFadeoutMilliseconds = 500

var drawStartTime time.Time

Expand All @@ -55,6 +56,7 @@ type Variable struct {

changed bool // value of the underlying variable changed from previous stop
reformatted bool // formatting of variable value changed from last frame
customFormat bool // custom value
requestedLines int // number of lines needed to display the value of the variable

Children []*Variable
Expand Down Expand Up @@ -442,7 +444,7 @@ func updateLocals(container *nucular.Window) {
}

if changedVariableOpacity > minChangedVariableOpacity {
opacityReductionPerMillisecond := float64(maxChangedVariableOpacity-minChangedVariableOpacity) / 1500
opacityReductionPerMillisecond := float64(maxChangedVariableOpacity-minChangedVariableOpacity) / opacityFadeoutMilliseconds
elapsed := time.Since(drawStartTime)
elapsedms := elapsed.Nanoseconds() / 1e6
changedVariableOpacity = maxChangedVariableOpacity - byte(float64(elapsedms)*opacityReductionPerMillisecond)
Expand Down Expand Up @@ -718,7 +720,7 @@ func variableHeader(w *nucular.Window, flags showVariableFlags, exprMenu int, v
} else {
c.Text(getDisplayType(v, fullTypes))
c.Text(" = ")
if v.Value != "" && v.Kind != reflect.Ptr {
if v.Value != "" && (v.Kind != reflect.Ptr || v.customFormat) {
c.Text(v.Value)
} else {
c.Text(v.SinglelineString(false, fullTypes))
Expand Down

0 comments on commit a51f0b1

Please sign in to comment.