{"id":13438697,"url":"https://github.com/ihalila/pancurses","last_synced_at":"2025-05-15T19:08:29.740Z","repository":{"id":40314753,"uuid":"54257042","full_name":"ihalila/pancurses","owner":"ihalila","description":"A Rust curses library, supports Unix platforms and Windows","archived":false,"fork":false,"pushed_at":"2024-07-12T18:27:16.000Z","size":1158,"stargazers_count":403,"open_issues_count":27,"forks_count":41,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-11T23:58:53.823Z","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/ihalila.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2016-03-19T09:04:49.000Z","updated_at":"2025-01-02T11:30:37.000Z","dependencies_parsed_at":"2024-06-18T21:10:17.024Z","dependency_job_id":"defffdb0-1747-402c-aab5-a76ddc568316","html_url":"https://github.com/ihalila/pancurses","commit_stats":{"total_commits":247,"total_committers":17,"mean_commits":"14.529411764705882","dds":"0.10526315789473684","last_synced_commit":"69eaec248f29bff8dcdb4acc30be600d93a2d002"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihalila%2Fpancurses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihalila%2Fpancurses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihalila%2Fpancurses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihalila%2Fpancurses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ihalila","download_url":"https://codeload.github.com/ihalila/pancurses/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254404357,"owners_count":22065641,"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-07-31T03:01:07.648Z","updated_at":"2025-05-15T19:08:29.722Z","avatar_url":"https://github.com/ihalila.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","库"],"sub_categories":["Command-line","命令行 Command-line","命令行"],"readme":"# pancurses [![Build Status](https://travis-ci.org/ihalila/pancurses.svg?branch=master)](https://travis-ci.org/ihalila/pancurses) [![Build status](https://ci.appveyor.com/api/projects/status/x4j52ihig9n2e25y?svg=true)](https://ci.appveyor.com/project/ihalila/pancurses) [![Crates.io](https://img.shields.io/crates/v/pancurses.svg)](https://crates.io/crates/pancurses)\r\n\r\npancurses is a curses library for Rust that supports both Linux and Windows\r\nby abstracting away the backend that it uses\r\n([ncurses-rs](https://github.com/jeaye/ncurses-rs) and\r\n[pdcurses-sys](https://github.com/ihalila/pdcurses-sys) respectively).\r\n\r\nThe aim is to provide a more Rustic interface over the usual curses functions\r\nfor ease of use while remaining close enough to curses to make porting easy.\r\n\r\n## [Documentation](https://docs.rs/pancurses)\r\n\r\n## Requirements\r\n#### Linux\r\nncurses-rs links with the native ncurses library so that needs to be installed\r\nso that the linker can find it.\r\n\r\nCheck [ncurses-rs](https://github.com/jeaye/ncurses-rs) for more details.\r\n\r\n#### Windows\r\npdcurses-sys compiles the native PDCurses library as part of the build process,\r\nso you need to have a compatible C compiler available that matches the ABI of\r\nthe version of Rust you're using (so either gcc for the GNU ABI or cl for MSVC)\r\n\r\nCheck [pdcurses-sys](https://github.com/ihalila/pdcurses-sys) for more details.\r\n\r\n## Usage\r\nCargo.toml\r\n```toml\r\n[dependencies]\r\npancurses = \"0.17\"\r\n```\r\n\r\nmain.rs\r\n```rust\r\nextern crate pancurses;\r\n\r\nuse pancurses::{initscr, endwin};\r\n\r\nfn main() {\r\n  let window = initscr();\r\n  window.printw(\"Hello Rust\");\r\n  window.refresh();\r\n  window.getch();\r\n  endwin();\r\n}\r\n```\r\n\r\n## Pattern matching with getch()\r\n\r\n```rust\r\nextern crate pancurses;\r\n\r\nuse pancurses::{initscr, endwin, Input, noecho};\r\n\r\nfn main() {\r\n  let window = initscr();\r\n  window.printw(\"Type things, press delete to quit\\n\");\r\n  window.refresh();\r\n  window.keypad(true);\r\n  noecho();\r\n  loop {\r\n      match window.getch() {\r\n          Some(Input::Character(c)) =\u003e { window.addch(c); },\r\n          Some(Input::KeyDC) =\u003e break,\r\n          Some(input) =\u003e { window.addstr(\u0026format!(\"{:?}\", input)); },\r\n          None =\u003e ()\r\n      }\r\n  }\r\n  endwin();\r\n}\r\n```\r\n\r\n## Handling mouse input\r\n\r\nTo receive mouse events you need to both enable keypad mode and set a mouse mask that corresponds\r\nto the events you are interested in. Mouse events are received in the same way as keyboard events,\r\nie. by calling getch().\r\n\r\n```rust\r\nextern crate pancurses;\r\n\r\nuse pancurses::{ALL_MOUSE_EVENTS, endwin, getmouse, initscr, mousemask, Input};\r\n\r\nfn main() {\r\n    let window = initscr();\r\n\r\n    window.keypad(true); // Set keypad mode\r\n    mousemask(ALL_MOUSE_EVENTS, std::ptr::null_mut()); // Listen to all mouse events\r\n\r\n    window.printw(\"Click in the terminal, press q to exit\\n\");\r\n    window.refresh();\r\n\r\n    loop {\r\n        match window.getch() {\r\n            Some(Input::KeyMouse) =\u003e {\r\n                if let Ok(mouse_event) = getmouse() {\r\n                    window.mvprintw(1, 0,\r\n                                    \u0026format!(\"Mouse at {},{}\", mouse_event.x, mouse_event.y),\r\n                    );\r\n                };\r\n            }\r\n            Some(Input::Character(x)) if x == 'q' =\u003e break,\r\n            _ =\u003e (),\r\n        }\r\n    }\r\n    endwin();\r\n}\r\n```\r\n\r\nYou can also receive events for the mouse simply moving (as long as the terminal you're running on\r\nsupports it) by also specifying the REPORT_MOUSE_POSITION flag:\r\n```rust\r\nmousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, std::ptr::null_mut());\r\n```\r\n\r\n## Terminal resizing\r\n\r\nWhenever the terminal is resized by the user a Input::KeyResize event is raised. You should handle\r\nthis by calling ```resize_term(0, 0)``` to have curses adjust it's internal structures to match the\r\nnew size.\r\n\r\n## PDCurses (Windows) details\r\n\r\npdcurses-sys supports two flavors of PDCurses, win32a and win32. win32a is the GDI mode while win32\r\nruns in the Windows console. win32a has better support for colors and text effects.\r\n\r\nBy default the win32a flavor is used, but you can specify which one you want to use by using Cargo\r\nflags. Simply specify the feature in Cargo.toml like so:\r\n\r\n```rust\r\n[dependencies.pancurses]\r\nversion = \"0.17\"\r\nfeatures = [\"win32a\"]\r\n```\r\nor\r\n\r\n```rust\r\n[dependencies.pancurses]\r\nversion = \"0.17\"\r\nfeatures = [\"win32\"]\r\n```\r\n\r\n### (Font, Paste) menu\r\n\r\nPDCurses win32a has a menu that allows you to change the font and paste text into the window.\r\npancurses disables the window by default, though the user can still right-click the title bar to \r\naccess it. If you want to retain the PDCurses default behaviour of having the menu there set the \r\nfeature ```\"show_menu\"```.\r\n\r\n### Resizing\r\n\r\nOn win32a the default is to allow the user to freely resize the window. If you wish to disable\r\nresizing set the feature ```\"disable_resize\"```\r\n\r\n## License\r\n\r\nLicensed under the MIT license, see [LICENSE.md](LICENSE.md)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fihalila%2Fpancurses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fihalila%2Fpancurses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fihalila%2Fpancurses/lists"}