MCPcopy Create free account
hub / github.com/diillson/chatcli / DrainStdinChannel

Method DrainStdinChannel

cli/coder/input_guard.go:72–93  ·  view source on GitHub ↗

DrainStdinChannel non-blockingly empties the channel and returns the discarded lines. The caller is responsible for any logging beyond the DEBUG-level summary emitted here.

(ch <-chan string)

Source from the content-addressed store, hash-verified

70// discarded lines. The caller is responsible for any logging beyond the
71// DEBUG-level summary emitted here.
72func (g *InputGuard) DrainStdinChannel(ch <-chan string) []string {
73 if ch == nil {
74 return nil
75 }
76 var discarded []string
77 for {
78 select {
79 case line, ok := <-ch:
80 if !ok {
81 return discarded
82 }
83 discarded = append(discarded, line)
84 default:
85 if len(discarded) > 0 {
86 g.logger.Debug("input guard: drained pending stdin lines before security prompt",
87 zap.Int("count", len(discarded)),
88 zap.String("first_preview", preview(discarded[0])))
89 }
90 return discarded
91 }
92 }
93}
94
95// FlushTTYInput discards any unread input bytes still buffered by the kernel
96// for the controlling terminal. On platforms where the operation is not

Calls 2

previewFunction · 0.85
StringMethod · 0.45