mirror of
https://github.com/manifoldco/promptui.git
synced 2026-03-14 14:25:53 +01:00
add a test for the clearScreen function
This commit is contained in:
parent
04552e61bb
commit
601d387fcc
2 changed files with 25 additions and 3 deletions
10
select.go
10
select.go
|
|
@ -380,9 +380,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
|
|||
item := items[idx]
|
||||
|
||||
if s.HideSelected {
|
||||
sb.Reset()
|
||||
sb.Clear()
|
||||
sb.Flush()
|
||||
clearScreen(sb)
|
||||
} else {
|
||||
sb.Reset()
|
||||
sb.Write(render(s.Templates.selected, item))
|
||||
|
|
@ -622,3 +620,9 @@ func render(tpl *template.Template, data interface{}) []byte {
|
|||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func clearScreen(sb *screenbuf.ScreenBuf) {
|
||||
sb.Reset()
|
||||
sb.Clear()
|
||||
sb.Flush()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package promptui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/manifoldco/promptui/screenbuf"
|
||||
)
|
||||
|
||||
func TestSelectTemplateRender(t *testing.T) {
|
||||
|
|
@ -148,3 +151,18 @@ Description: {{.Description}}`,
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestClearScreen(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
sb := screenbuf.New(&buf)
|
||||
|
||||
sb.WriteString("test")
|
||||
clearScreen(sb)
|
||||
|
||||
got := buf.String()
|
||||
except := "\x1b[1A\x1b[2K\r"
|
||||
|
||||
if except != got {
|
||||
t.Errorf("expected %q, got %q", except, got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue