+func TestTerminalPromptsAfterIdleEventsAndClearsBeforeShownEvents(t *testing.T) {
+ fd, err := unix.Open("/dev/ptmx", unix.O_RDWR|unix.O_NOCTTY, 0)
+ require.NoError(t, err)
+
+ defer func() {
+ require.NoError(t, unix.Close(fd))
+ }()
+
+ out := TerminalTestOutput{fd: fd}
+ terminalTestShowEvents(t, &out,
+ Event{
+ Kind: "ready",
+ Text: "Example",
+ },
+ Event{
+ Kind: "user",
+ Source: terminalSource,
+ Text: "hidden",
+ },
+ Event{Kind: "unknown"},
+ Event{
+ Kind: "notice",
+ Text: "Idle notice",
+ },
+ Event{
+ Kind: "work",
+ Text: "**Idle report**",
+ },
+ Event{Kind: "busy"},
+ Event{
+ Kind: "notice",
+ Text: "Busy notice",
+ },
+ Event{
+ Kind: "reply",
+ Text: "**Answer**",
+ },
+ Event{Kind: "idle"},
+ Event{
+ Kind: "error",
+ Text: "Idle error",
+ },
+ )
+ require.Equal(t, "[connected to Example]\n> "+
+ "\r\x1b[2KIdle notice\n> "+
+ "\r\x1b[2K\x1b[1mIdle report\x1b[0m\n> "+
+ "\r\x1b[2K[working]\nBusy notice\n\x1b[1mAnswer\x1b[0m\n[done]\n> "+
+ "\r\x1b[2K[error] Idle error\n> ", out.String())
+}
+
+func TestTerminalNonterminalEventsHaveNoPromptOrClearCommands(t *testing.T) {
+ var out strings.Builder
+
+ terminalTestShowEvents(t, &out,
+ Event{
+ Kind: "ready",
+ Text: "Example",
+ },
+ Event{
+ Kind: "notice",
+ Text: "Idle notice",
+ },
+ Event{Kind: "busy"},
+ Event{
+ Kind: "notice",
+ Text: "Busy notice",
+ },
+ Event{
+ Kind: "reply",
+ Text: "**Answer**",
+ },
+ Event{Kind: "idle"},
+ Event{
+ Kind: "notice",
+ Text: "Idle again",
+ },
+ )
+ require.Equal(t, "[connected to Example]\nIdle notice\n[working]\nBusy notice\n**Answer**\n[done]\nIdle again\n", out.String())
+}
+