Skip to content

Commit 1d4c94c

Browse files
committed
Reset clipping region and cursor on ClsCol
ClsCol should reset clipping region and cursor position used for printing text.
1 parent c64921b commit 1d4c94c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

print_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestPrint(t *testing.T) {
126126
t.Run("should reset cursor", func(t *testing.T) {
127127
tests := map[string]func(){
128128
"Cls()": func() { pi.Cls() },
129+
"ClsCol(0)": func() { pi.ClsCol(0) },
129130
"CursorReset()": func() { pi.CursorReset() },
130131
"Cursor(0,0)": func() { pi.Cursor(0, 0) },
131132
}

screen.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ func cls() {
4747
}
4848

4949
// ClsCol cleans the entire screen with specified color. It does not take into account any draw state parameters such as clipping region or camera.
50+
//
51+
// ClsCol also resets the cursor used for printing text and resets the clipping region.
5052
func ClsCol(col byte) {
53+
clsCol(col)
54+
CursorReset()
55+
ClipReset()
56+
}
57+
58+
func clsCol(col byte) {
5159
for i := 0; i < len(lineOfScreenWidth); i++ {
5260
lineOfScreenWidth[i] = col
5361
}

screen_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ func TestCls(t *testing.T) {
6969
assert.Equal(t, []byte{0, 0, 0, 0}, pi.ScreenData)
7070
})
7171

72+
testCls(t, pi.Cls)
73+
}
74+
75+
func testCls(t *testing.T, cls func()) {
7276
t.Run("should reset clipping region", func(t *testing.T) {
7377
pi.BootOrPanic()
7478
pi.Clip(1, 2, 3, 4)
7579
// when
76-
pi.Cls() // clips to 0,0,w,h
80+
cls() // clips to 0,0,w,h
7781
// then
7882
prevX, prevY, prevW, prevH := pi.ClipReset()
7983
assert.Zero(t, prevX)
@@ -84,7 +88,7 @@ func TestCls(t *testing.T) {
8488
}
8589

8690
func TestClsCol(t *testing.T) {
87-
t.Run("should clean screen using color 0", func(t *testing.T) {
91+
t.Run("should clean screen using color 7", func(t *testing.T) {
8892
pi.ScreenWidth = 2
8993
pi.ScreenHeight = 2
9094
pi.BootOrPanic()
@@ -94,6 +98,10 @@ func TestClsCol(t *testing.T) {
9498
// then
9599
assert.Equal(t, []byte{7, 7, 7, 7}, pi.ScreenData)
96100
})
101+
102+
testCls(t, func() {
103+
pi.ClsCol(0)
104+
})
97105
}
98106

99107
func TestPset(t *testing.T) {

0 commit comments

Comments
 (0)