{"id":15675301,"url":"https://github.com/hibariya/pty-rs","last_synced_at":"2025-04-15T05:56:43.485Z","repository":{"id":34469112,"uuid":"38406077","full_name":"hibariya/pty-rs","owner":"hibariya","description":"Fork with new pseudo-terminal (PTY)","archived":false,"fork":false,"pushed_at":"2021-02-02T01:57:02.000Z","size":3026,"stargazers_count":30,"open_issues_count":7,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T05:56:38.699Z","etag":null,"topics":[],"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/hibariya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-02T02:14:32.000Z","updated_at":"2024-07-31T23:19:52.000Z","dependencies_parsed_at":"2022-08-03T21:00:10.329Z","dependency_job_id":null,"html_url":"https://github.com/hibariya/pty-rs","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hibariya%2Fpty-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hibariya%2Fpty-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hibariya%2Fpty-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hibariya%2Fpty-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hibariya","download_url":"https://codeload.github.com/hibariya/pty-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016320,"owners_count":21198832,"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":[],"created_at":"2024-10-03T15:58:14.218Z","updated_at":"2025-04-15T05:56:43.469Z","avatar_url":"https://github.com/hibariya.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PTY \n[![Crate][crate-badge]][crate] [![docs-badge][]][docs] [![license-badge][]][license] [![travis-badge][]][travis]\n\n[crate-badge]: https://img.shields.io/badge/crates.io-v0.2.0-orange.svg?style=flat-square\n[crate]: https://crates.io/crates/pty\n\n[docs-badge]: https://img.shields.io/badge/API-docs-blue.svg?style=flat-square\n[docs]: http://note.hibariya.org/pty-rs/pty/index.html\n\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n[license]: https://github.com/hibariya/pty-rs/blob/master/LICENSE.txt\n\n[travis-badge]: https://travis-ci.org/hibariya/pty-rs.svg?branch=master\u0026style=flat-square\n[travis]: https://travis-ci.org/hibariya/pty-rs\n\nThe `pty` crate provides `pty::fork()`. That makes a parent process fork with new pseudo-terminal (PTY).\n\nThis crate depends on followings:\n\n* `libc` library\n* POSIX environment\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\npty = \"0.2\"\n```\n\nand this to your crate root:\n\n```rust\nextern crate pty;\n```\n\n### pty::fork()\n\nThis function returns `pty::Child`. It represents the child process and its PTY.\n\nFor example, the following code spawns `tty(1)` command by `pty::fork()` and outputs the result of the command.\n\n```rust\nextern crate pty;\nextern crate libc;\n\nuse std::ffi::CString;\nuse std::io::Read;\nuse std::ptr;\n\nuse pty::fork::*;\n\nfn main() {\n  let fork = Fork::from_ptmx().unwrap();\n\n  if let Some(mut master) = fork.is_parent().ok() {\n    // Read output via PTY master\n    let mut output = String::new();\n\n    match master.read_to_string(\u0026mut output) {\n      Ok(_nread) =\u003e println!(\"child tty is: {}\", output.trim()),\n      Err(e)     =\u003e panic!(\"read error: {}\", e),\n    }\n  }\n  else {\n    // Child process just exec `tty`\n    Command::new(\"tty\").status().expect(\"could not execute tty\");\n  }\n}\n```\n\nWhen run this, we get new PTY in the child process.\n\n```\n$ tty\n/dev/pts/5\n$ cargo run\n    Running `target/debug/example`\nchild tty is: /dev/pts/8\n```\n\n## Documentation\n\nAPI documentation for latest version: http://hibariya.github.io/pty-rs/pty/index.html\n\n## Contributing\n\n1. Fork it ( https://github.com/hibariya/pty-rs/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nCopyright (c) 2015 Hika Hibariya\n\nDistributed under the [MIT License](LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhibariya%2Fpty-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhibariya%2Fpty-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhibariya%2Fpty-rs/lists"}