Skip to content
Myr

renderer.go

This file

Path

renderer.go

104 lines · 2.6 KiB · Go

Last changed by

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

History of this file

Take it

The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 1–2why, one step back
1package tea
2

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 3–16why, one step back
3import (
4 "fmt"56 "github.com/charmbracelet/colorprofile"7 "github.com/charmbracelet/x/ansi"8)910const (11 // defaultFramerate specifies the maximum interval at which we should12 // update the view.13 defaultFPS = 6014 maxFPS = 12015)16

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 17–18why, one step back
17// renderer is the interface for Bubble Tea renderers.
18type renderer interface {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 19why, one step back
19 // start starts the renderer.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 20–21why, one step back
20 start()
21

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 22–23why, one step back
22 // close closes the renderer and flushes any remaining data.
23 close() error

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 24why, one step back
24

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 25–26why, one step back
25 // render renders a frame to the output.
26 render(View)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 27why, one step back
27

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 28–29why, one step back
28 // flush flushes the renderer's buffer to the output.
29 flush(closing bool) error

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 30why, one step back
30

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 31–32why, one step back
31 // reset resets the renderer's state to its initial state.
32 reset()

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 33why, one step back
33

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 34–35why, one step back
34 // insertAbove inserts unmanaged lines above the renderer.
35 insertAbove(string) error

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 36why, one step back
36

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 37–38why, one step back
37 // setSyncdUpdates sets whether to use synchronized updates.
38 setSyncdUpdates(bool)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 39why, one step back
39

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 40–41why, one step back
40 // setWidthMethod sets the method for calculating the width of the terminal.
41 setWidthMethod(ansi.Method)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 42why, one step back
42

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 43–44why, one step back
43 // resize notify the renderer of a terminal resize.
44 resize(int, int)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 45why, one step back
45

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 46–47why, one step back
46 // setColorProfile sets the color profile.
47 setColorProfile(colorprofile.Profile)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 48why, one step back
48

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 49–50why, one step back
49 // clearScreen clears the screen.
50 clearScreen()

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 51why, one step back
51

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 52–53why, one step back
52 // writeString writes a string to the renderer's output.
53 writeString(string) (int, error)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 54why, one step back
54

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 55–57why, one step back
55 // onMouse handles a mouse event.
56 onMouse(MouseMsg) Cmd57}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 58why, one step back
58

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 59–61why, one step back
59type printLineMessage struct {
60 messageBody string61}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 62why, one step back
62

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 63–76why, one step back
63// Println prints above the Program. This output is unmanaged by the program and
64// will persist across renders by the Program.65//66// Unlike fmt.Println (but similar to log.Println) the message will be print on67// its own line.68//69// If the altscreen is active no output will be printed.70func Println(args ...any) Cmd {71 return func() Msg {72 return printLineMessage{73 messageBody: fmt.Sprint(args...),74 }75 }76}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 77why, one step back
77

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 78–91why, one step back
78// Printf prints above the Program. It takes a format template followed by
79// values similar to fmt.Printf. This output is unmanaged by the program and80// will persist across renders by the Program.81//82// Unlike fmt.Printf (but similar to log.Printf) the message will be print on83// its own line.84//85// If the altscreen is active no output will be printed.86func Printf(template string, args ...any) Cmd {87 return func() Msg {88 return printLineMessage{89 messageBody: fmt.Sprintf(template, args...),90 }91 }

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 92–93why, one step back
92}
93

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 94–104why, one step back
94// encodeCursorStyle returns the integer value for the given cursor style and
95// blink state.96func encodeCursorStyle(style CursorShape, blink bool) int {97 // We're using the ANSI escape sequence values for cursor styles.98 // We need to map both [style] and [steady] to the correct value.99 style = (style * 2) + 1 //nolint:mnd100 if !blink {101 style++102 }103 return int(style)104}