Documentation
¶
Index ¶
- Constants
- Variables
- func IsAuth(err error) bool
- func IsCanceled(err error) bool
- func IsDial(err error) bool
- func IsTimeout(err error) bool
- type Config
- type Error
- type ReadWriter
- func (r *ReadWriter) IsEndLine(s string) bool
- func (r *ReadWriter) Prompt() string
- func (r *ReadWriter) Read(ctx context.Context, stopOnEndLine bool, onOut func(lines []string), ...) (err error)
- func (r *ReadWriter) ReadAll(timeout time.Duration, onOut func(lines []string), ...) (err error)
- func (r *ReadWriter) ReadToEndLine(timeout time.Duration, onOut func(lines []string), ...) (err error)
- func (r *ReadWriter) Stop()
- func (r *ReadWriter) Write(cmd string) (err error)
- func (r *ReadWriter) WriteRaw(b []byte) (err error)
Constants ¶
View Source
const ( DefaultPromptTailChars = `$#%>\]:` DefaultPromptSuffixPattern = `.*[` + DefaultPromptTailChars + `]\s*$` )
Variables ¶
View Source
var ( DefaultPromptRegex = regexp.MustCompile(`\S+` + DefaultPromptSuffixPattern) FlexibleOptionPromptRegex = regexp.MustCompile(interceptor.FlexibleOptionPromptPattern) UsernameRegex = regexp.MustCompile(`(?i).*(login|user(name)?):\s*$`) PasswordRegex = regexp.MustCompile(`(?i).*pass(word)?:\s*$`) )
Functions ¶
func IsCanceled ¶
Types ¶
type Config ¶
type Config struct { // 输出 io.Reader 中读取的原始数据,用于上层调试 RawOut io.Writer // 从 io.Reader 中读取到数据后,用来过滤特殊字符的自定义函数,在 Decoder 前执行 Filter filter.IFilter // 从 io.Reader 中读取到数据后,用来解码的自定义函数 Decoder func(b []byte) ([]byte, error) // 命令行提示符的匹配规则 PromptRegex []*regexp.Regexp // 是否自动纠正命令行提示符,仅当未指定 PromptRegex 时有效 // 该参数为true时,会在默认规则第一次匹配到结束符时尝试修正匹配规则,某些情况下可能修正后的规则不如默认规则灵活,慎用 AutoPrompt bool // 是否输出命令行提示符 ShowPrompt bool // 调用 ReadToEndLine 时的确认次数 ReadConfirm int // 调用 ReadToEndLine 时的确认间隔 ReadConfirmWait time.Duration // 调用 ReadXXX 函数前的自定义回调函数 BeforeRead func() error // 延迟触发 OnOut 的时间间隔 // 如果需要在超过指定间隔或输出内容超过指定长度后再触发 OnOut、而不是实时触发 OnOut,可以指定 LazyOutInterval 和 LazyOutSize LazyOutInterval time.Duration // 延迟触发 OnOut 的缓冲区大小 // 如果需要在超过指定间隔或输出内容超过指定长度后再触发 OnOut、而不是实时触发 OnOut,可以指定 LazyOutInterval 和 LazyOutSize LazyOutSize int }
type Error ¶
type Error struct { // Op is the operation which caused the error, such as "dial" or "auth". Op string // For operations involving a remote network connection. // like Dial, Read, or Write, Addr is the remote address of that connection. Addr string // Err is the error that occurred during the operation. Err error }
type ReadWriter ¶
type ReadWriter struct {
// contains filtered or unexported fields
}
func (*ReadWriter) IsEndLine ¶
func (r *ReadWriter) IsEndLine(s string) bool
func (*ReadWriter) Prompt ¶
func (r *ReadWriter) Prompt() string
Prompt 命令交互过程中提示符可能发生变化,该方法获取最新的提示符
func (*ReadWriter) Read ¶
func (r *ReadWriter) Read(ctx context.Context, stopOnEndLine bool, onOut func(lines []string), interceptors ...interceptor.Interceptor) (err error)
func (*ReadWriter) ReadAll ¶
func (r *ReadWriter) ReadAll(timeout time.Duration, onOut func(lines []string), interceptors ...interceptor.Interceptor) (err error)
func (*ReadWriter) ReadToEndLine ¶
func (r *ReadWriter) ReadToEndLine(timeout time.Duration, onOut func(lines []string), interceptors ...interceptor.Interceptor) (err error)
func (*ReadWriter) Stop ¶
func (r *ReadWriter) Stop()
func (*ReadWriter) Write ¶
func (r *ReadWriter) Write(cmd string) (err error)
Write 写入一个命令(自动在末尾补充 \n 换行符)。
func (*ReadWriter) WriteRaw ¶
func (r *ReadWriter) WriteRaw(b []byte) (err error)
WriteRaw 向输入流写入指定内容,并等待指定时间(默认 10 毫秒)。
Click to show internal directories.
Click to hide internal directories.