Update overwrites the content of the AreaPrinter. Can be used live.
(text ...any)
| 56 | // Update overwrites the content of the AreaPrinter. |
| 57 | // Can be used live. |
| 58 | func (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. |
| 92 | func (p *AreaPrinter) Start(text ...any) (*AreaPrinter, error) { |