MCPcopy
hub / github.com/pterm/pterm / Update

Method Update

area_printer.go:58–89  ·  view source on GitHub ↗

Update overwrites the content of the AreaPrinter. Can be used live.

(text ...any)

Source from the content-addressed store, hash-verified

56// Update overwrites the content of the AreaPrinter.
57// Can be used live.
58func (p *AreaPrinter) Update(text ...any) {
59 if p.area == nil {
60 newArea := cursor.NewArea()
61 p.area = &newArea
62 }
63 str := Sprint(text...)
64 p.content = str
65
66 if p.Center {
67 str = DefaultCenter.Sprint(str)
68 }
69
70 if p.Fullscreen {
71 str = strings.TrimRight(str, "\n")
72 height := GetTerminalHeight()
73 contentHeight := strings.Count(str, "\n")
74
75 topPadding := 0
76 bottomPadding := height - contentHeight - 2
77
78 if p.Center {
79 topPadding = (bottomPadding / 2) + 1
80 bottomPadding /= 2
81 }
82
83 if height > contentHeight {
84 str = strings.Repeat("\n", topPadding) + str
85 str += strings.Repeat("\n", bottomPadding)
86 }
87 }
88 p.area.Update(str)
89}
90
91// Start the AreaPrinter.
92func (p *AreaPrinter) Start(text ...any) (*AreaPrinter, error) {

Callers 15

StartMethod · 0.95
TestAreaPrinter_NilPrintFunction · 0.95
TestAreaPrinter_ClearFunction · 0.95
StartMethod · 0.80
StopMethod · 0.80
ShowMethod · 0.80
ShowMethod · 0.80
ShowMethod · 0.80
updateAreaMethod · 0.80

Calls 3

SprintFunction · 0.85
GetTerminalHeightFunction · 0.85
SprintMethod · 0.65

Tested by 5

TestAreaPrinter_NilPrintFunction · 0.76
TestAreaPrinter_ClearFunction · 0.76