{"id":13636624,"url":"https://github.com/zhiburt/expectrl","last_synced_at":"2026-04-06T06:04:01.653Z","repository":{"id":38295080,"uuid":"380309062","full_name":"zhiburt/expectrl","owner":"zhiburt","description":"A rust library for controlling interactive programs in a pseudo-terminal ","archived":false,"fork":false,"pushed_at":"2024-12-13T22:13:50.000Z","size":719,"stargazers_count":187,"open_issues_count":18,"forks_count":15,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T15:17:25.194Z","etag":null,"topics":["console","expect","hacktoberfest","pexpect","process","processes","pty","rexpect","rust","terminal","tty","unix"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/zhiburt.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-25T17:21:43.000Z","updated_at":"2025-03-18T02:25:31.000Z","dependencies_parsed_at":"2024-03-02T02:26:02.451Z","dependency_job_id":"6da0c146-79bf-4bb1-a71d-dbf353dc5b33","html_url":"https://github.com/zhiburt/expectrl","commit_stats":{"total_commits":336,"total_committers":2,"mean_commits":168.0,"dds":"0.0029761904761904656","last_synced_commit":"976028f6b4522a24cf986cce3337fcf98b1f77a6"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiburt%2Fexpectrl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiburt%2Fexpectrl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiburt%2Fexpectrl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiburt%2Fexpectrl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhiburt","download_url":"https://codeload.github.com/zhiburt/expectrl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249650291,"owners_count":21305990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["console","expect","hacktoberfest","pexpect","process","processes","pty","rexpect","rust","terminal","tty","unix"],"created_at":"2024-08-02T00:01:03.428Z","updated_at":"2026-04-06T06:04:01.642Z","avatar_url":"https://github.com/zhiburt.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","Rust"],"sub_categories":["Command-line","命令行 Command-line"],"readme":"[![Build](https://github.com/zhiburt/expectrl/actions/workflows/ci.yml/badge.svg)](https://github.com/zhiburt/expectrl/actions/workflows/ci.yml)\n[![coverage status](https://coveralls.io/repos/github/zhiburt/expectrl/badge.svg?branch=main)](https://coveralls.io/github/zhiburt/expectrl?branch=main)\n[![crate](https://img.shields.io/crates/v/expectrl)](https://crates.io/crates/expectrl)\n[![docs.rs](https://img.shields.io/docsrs/expectrl?color=blue)](https://docs.rs/expectrl/*/expectrl/)\n\n# expectrl\n\nExpectrl is a tool for automating terminal applications.\n\nExpectrl is a rust module for spawning child applications and controlling them and responding to expected patterns in process's output. Expectrl works like Don Libes' Expect. Expectrl allows your script to spawn a child application and control it as if a human were typing commands.\n\nUsing the library you can:\n\n- Spawn process\n- Control process\n- Interact with process's IO(input/output).\n\n`expectrl` like original `expect` may shine when you're working with interactive applications.\nIf your application is not interactive you may not find the library the best choiсe.\n\n## Usage\n\nAdd `expectrl` to your Cargo.toml.\n\n```toml\n# Cargo.toml\n[dependencies]\nexpectrl = \"0.8\"\n```\n\nAn example where the program simulates a used interacting with `ftp`.\n\n```rust\nuse expectrl::{Regex, Eof, Error, Expect};\n\nfn main() -\u003e Result\u003c(), Error\u003e {\n    let mut p = expectrl::spawn(\"ftp speedtest.tele2.net\")?;\n    p.expect(Regex(\"Name \\\\(.*\\\\):\"))?;\n    p.send_line(\"anonymous\")?;\n    p.expect(\"Password\")?;\n    p.send_line(\"test\")?;\n    p.expect(\"ftp\u003e\")?;\n    p.send_line(\"cd upload\")?;\n    p.expect(\"successfully changed.\\r\\nftp\u003e\")?;\n    p.send_line(\"pwd\")?;\n    p.expect(Regex(\"[0-9]+ \\\"/upload\\\"\"))?;\n    p.send_line(\"exit\")?;\n    p.expect(Eof)?;\n\n    Ok(())\n}\n```\n\nThe same example but the password will be read from stdin.\n\n```rust\nuse std::io::stdout;\n\nuse expectrl::{\n    interact::{actions::lookup::Lookup, InteractSession},\n    stream::stdin::Stdin,\n    ControlCode, Error, Expect, Regex,\n};\n\nfn main() -\u003e Result\u003c(), Error\u003e {\n    let mut p = expectrl::spawn(\"ftp bks4-speedtest-1.tele2.net\")?;\n\n    let mut search = Lookup::new();\n    let mut stdin = Stdin::open()?;\n\n    let authenticated = {\n        let mut session = InteractSession::new(\u0026mut p, \u0026mut stdin, stdout(), false);\n        session.set_output_action(move |ctx| {\n            let found = search.on(ctx.buf, ctx.eof, \"Login successful\")?;\n            if found.is_some() {\n                *ctx.state = true;\n                return Ok(true);\n            }\n\n            Ok(false)\n        });\n\n        session.spawn()?;\n\n        session.into_state()\n    };\n\n    stdin.close()?;\n\n    if !authenticated {\n        println!(\"An authentication was not passed\");\n        return Ok(());\n    }\n\n    p.expect(\"ftp\u003e\")?;\n    p.send_line(\"cd upload\")?;\n    p.expect(\"successfully changed.\")?;\n    p.send_line(\"pwd\")?;\n    p.expect(Regex(\"[0-9]+ \\\"/upload\\\"\"))?;\n    p.send(ControlCode::EndOfTransmission)?;\n    p.expect(\"Goodbye.\")?;\n\n    Ok(())\n}\n```\n\n#### [For more examples, check the examples directory.](https://github.com/zhiburt/expectrl/tree/main/examples)\n\n## Features\n\n- It has an `async` support (To enable them you must turn on an `async` feature).\n- It supports logging.\n- It supports interact function.\n- It works on windows.\n\n## Notes\n\nIt was originally inspired by [philippkeller/rexpect] and [pexpect].\n\nLicensed under [MIT License](LICENSE)\n\n[philippkeller/rexpect]: https://github.com/philippkeller/rexpect\n[pexpect]: https://pexpect.readthedocs.io/en/stable/overview.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhiburt%2Fexpectrl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhiburt%2Fexpectrl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhiburt%2Fexpectrl/lists"}