MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Write

Method Write

pkg/util/term/fb.go:70–150  ·  view source on GitHub ↗

Write draws the character buffer to the screen frame buffer.

(p []byte)

Source from the content-addressed store, hash-verified

68
69// Write draws the character buffer to the screen frame buffer.
70func (fb FrameBuffer) Write(p []byte) (int, error) {
71 bufferInfo, err := getScreenBufferInfo(fb.handle)
72 if err != nil {
73 return 0, err
74 }
75 if len(p) == 1 {
76 return 0, nil
77 }
78
79 rows := int(bufferInfo.rect.bottom)
80 cols := int(bufferInfo.rect.right)
81
82 chars := make([]charInfo, cols*rows)
83
84 var x int
85 var y int
86 var newLine bool
87
88 for _, char := range string(p) {
89 c := char
90 if c == '\n' || c == '\r' {
91 newLine = true
92 }
93 r, c := utf16.EncodeRune(c)
94 if r == 0xFFFD {
95 c = char
96 }
97 y++
98 // if the last column has been reached and a new line was encountered at
99 // that position then we'll stop the iteration and reset the column number
100 if y == cols {
101 y = 0
102 if newLine {
103 newLine = false
104 continue
105 }
106 }
107 if newLine {
108 newLine = false
109 space := y
110 // keep filling the rectangle with spaces until we reach the last column. Then
111 // we'll reset the column and stop the current iteration
112 for space <= cols {
113 if space-1 > len(chars)-1 {
114 continue
115 }
116 chars[space-1].char = uint16(' ')
117 space++
118 x++
119 }
120 y = 0
121 continue
122 }
123
124 if x > len(chars)-1 {
125 continue
126 }
127

Callers

nothing calls this directly

Calls 4

clsMethod · 0.95
uintptrMethod · 0.95
getScreenBufferInfoFunction · 0.85
CallMethod · 0.65

Tested by

no test coverage detected