{"id":20284216,"url":"https://github.com/viert/smartpty","last_synced_at":"2026-06-22T19:31:39.135Z","repository":{"id":57650761,"uuid":"155245200","full_name":"viert/smartpty","owner":"viert","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-10T11:09:13.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T03:42:00.326Z","etag":null,"topics":["golang","golang-library","pexpect","pty"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/viert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-29T16:32:06.000Z","updated_at":"2019-01-10T11:09:14.000Z","dependencies_parsed_at":"2022-09-13T11:10:41.654Z","dependency_job_id":null,"html_url":"https://github.com/viert/smartpty","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/viert/smartpty","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viert%2Fsmartpty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viert%2Fsmartpty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viert%2Fsmartpty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viert%2Fsmartpty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viert","download_url":"https://codeload.github.com/viert/smartpty/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viert%2Fsmartpty/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34663524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-library","pexpect","pty"],"created_at":"2024-11-14T14:18:46.994Z","updated_at":"2026-06-22T19:31:39.116Z","avatar_url":"https://github.com/viert.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SmartPTY Golang library\n\n**SmartPTY** is a simple expect/pexpect like library for go which makes you able to start a terminal with a standard **exec.Cmd** inside and react to certain expressions coming from the terminal output.\n\nThe most obvious way you can use it is starting a shell or a ssh session and make it type password for you automatically. You can find _sudo.go_ in _examples_ folder which does exactly that.\n\n#### Methods\n\n**func Create(\\*exec.Cmd) \\*SmartPTY**\ncreates a smartpty object based on the given Cmd\n\n**func (sp \\*SmartPTY) Start() error**\nstarts the terminal. Be sure to configure reaction callbacks before calling Start()\n\n**func (sp \\*SmartPTY) Close()**\ncloses the terminal and stops all the goroutines. This is not very useful as you can always call myCmd.Process.Kill() which will close related file descriptors and SmartPTY goroutines processing stdin/stdout should then stop automatically.\n\n**func (sp \\*SmartPTY) Once(expr \\*regexp.Regexp, cb ExpressionCallback)**\n\n**func (sp \\*SmartPTY) Always(expr \\*regexp.Regexp, cb ExpressionCallback)**\n\n**func (sp \\*SmartPTY) Times(expr \\*regexp.Regexp, cb ExpressionCallback, int times)**\n\nThese functions create a reaction callback based on `expr` argument. When SmartPTY finds a chunk of data matching the expression, the `cb` function is called. The difference between these functions are kinda self-explanatory: `Once()` will run the callback just once, `Always()` will run its callback every time SmartPTY receives the matching chunk of data, and `Times()` will react exactly `times` times.\n\n**type ExpressionCallback func(data []byte, tty \\*os.File) []byte**\nThis is the callback function signature. SmartPTY will pass the whole data chunk matching the expression, the pseudo-terminal _\\*os.File_ object where you can respond to using `tty.Write([]byte)`. In the end of each callback you can either return the whole chunk (_return data_) or modify it as you wish to, for example you may want to remove the _\"Password:\"_ prompt from the output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviert%2Fsmartpty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviert%2Fsmartpty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviert%2Fsmartpty/lists"}