{"id":13598563,"url":"https://github.com/ratatui/ratatui-macros","last_synced_at":"2025-04-10T09:31:37.318Z","repository":{"id":215673615,"uuid":"739532911","full_name":"ratatui/ratatui-macros","owner":"ratatui","description":"Macros for simplifying boilerplate for creating UI using Ratatui.","archived":false,"fork":false,"pushed_at":"2025-03-10T19:58:58.000Z","size":199,"stargazers_count":34,"open_issues_count":5,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-06T01:28:17.854Z","etag":null,"topics":["cli","macros","macros-rust","ratatui","rust","tui"],"latest_commit_sha":null,"homepage":"https://ratatui.rs","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/ratatui.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-01-05T19:51:14.000Z","updated_at":"2025-03-26T13:26:09.000Z","dependencies_parsed_at":"2024-01-23T17:09:54.900Z","dependency_job_id":"98d838ef-9aa9-4a77-a6f9-0c85ffe4701e","html_url":"https://github.com/ratatui/ratatui-macros","commit_stats":null,"previous_names":["kdheepak/ratatui-macros","ratatui-org/ratatui-macros","ratatui/ratatui-macros"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratatui%2Fratatui-macros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratatui%2Fratatui-macros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratatui%2Fratatui-macros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratatui%2Fratatui-macros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ratatui","download_url":"https://codeload.github.com/ratatui/ratatui-macros/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248191728,"owners_count":21062560,"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":["cli","macros","macros-rust","ratatui","rust","tui"],"created_at":"2024-08-01T17:00:53.689Z","updated_at":"2025-04-10T09:31:32.307Z","avatar_url":"https://github.com/ratatui.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ratatui Macros\n\n[![Crates.io badge]][ratatui_macros crate] [![License badge]](./LICENSE)\n[![Docs.rs badge]][API Docs] [![CI Badge]][CI Status]\n[![Crate Downloads badge]][ratatui_macros crate]\n\n`ratatui-macros` is a Rust crate that provides easy-to-use macros for simplifying boilerplate\nassociated with creating UI using [Ratatui].\n\nThis is an experimental playground for us to explore macros that would be useful to have in Ratatui\nproper.\n\n## Features\n\n- Constraint-based Layouts: Easily define layout constraints such as fixed, percentage, minimum, and\n  maximum sizes, as well as ratios.\n- Directional Layouts: Specify layouts as either horizontal or vertical with simple macro commands.\n- Span and Line macros: Make it easier to create spans and lines with styling.\n\n## Getting Started\n\nTo use `ratatui-macros` in your Rust project, add it as a dependency in your `Cargo.toml`:\n\n```shell\ncargo add ratatui-macros\n```\n\nThen, import the macros in your Rust file:\n\n```rust\nuse ratatui_macros::{\n    constraint,\n    constraints,\n    horizontal,\n    vertical,\n    span,\n    line,\n};\n```\n\n### Layout\n\nIf you are new to Ratatui, check out the [Layout concepts] article on the Ratatui website before proceeding.\n\nUse the `constraints!` macro to define layout constraints:\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::constraints;\n\nassert_eq!(\n    constraints![==50, ==30%, \u003e=3, \u003c=1, ==1/2, *=1],\n    [\n        Constraint::Length(50),\n        Constraint::Percentage(30),\n        Constraint::Min(3),\n        Constraint::Max(1),\n        Constraint::Ratio(1, 2),\n        Constraint::Fill(1),\n    ]\n)\n```\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::constraints;\n\nassert_eq!(\n    constraints![==1/4; 4],\n    [\n        Constraint::Ratio(1, 4),\n        Constraint::Ratio(1, 4),\n        Constraint::Ratio(1, 4),\n        Constraint::Ratio(1, 4),\n    ]\n)\n```\n\nUse the `constraint!` macro to define individual constraints:\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::constraint;\n\nassert_eq!(\n    constraint!(==50),\n    Constraint::Length(50),\n)\n```\n\nCreate vertical and horizontal layouts using the `vertical!` and `horizontal!` macros:\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::{vertical, horizontal};\n\nlet area = Rect { x: 0, y: 0, width: 10, height: 10 };\n\nlet [main, bottom] = vertical![==100%, \u003e=3].areas(area);\n\nassert_eq!(bottom.y, 7);\nassert_eq!(bottom.height, 3);\n\nlet [left, main, right] = horizontal![\u003e=3, ==100%, \u003e=3].areas(area);\n\nassert_eq!(left.width, 3);\nassert_eq!(right.width, 3);\n```\n\n## Spans\n\nThe `span!` macro create raw and styled `Span`s. They each take a format string and arguments.\n`span!` accepts as the first parameter any value that can be converted to a `Style` followed by a\n`;` followed by the format string and arguments.\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::span;\n\nlet name = \"world!\";\nlet raw_greeting = span!(\"hello {name}\");\nlet styled_greeting = span!(Style::new().green(); \"hello {name}\");\nlet styled_greeting = span!(Color::Green; \"hello {name}\");\nlet styled_greeting = span!(Modifier::BOLD; \"hello {name}\");\n```\n\n## Line\n\nThe `line!` macro creates a `Line` that contains a sequence of spans. It is similar to the `vec!`\nmacro.\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::line;\n\nlet name = \"world!\";\nlet line = line![\"hello\", format!(\"{name}\")];\nlet line = line![\"bye\"; 2];\n```\n\n## Text\n\nThe `text!` macro creates a `Text` that contains a sequence of lines. It is similar to the `vec!`\nmacro.\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::{span, line, text};\n\nlet name = \"world!\";\nlet text = text![\"hello\", format!(\"{name}\")];\nlet text = text![\"bye\"; 2];\n```\n\nIt is even possible to use `span!` and `line!` in the `text!` macro:\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::{span, line, text};\nlet name = \"Bye!!!\";\nlet text = text![line![\"hello\", \"world\".bold()], span!(Modifier::BOLD; \"{name}\")];\n```\n\n## Row\n\nThe `row!` macro creates a `Row` that contains a sequence of `Cell`. It is similar to the `vec!`\nmacro. A `Row` represents a sequence of `Cell`s in a single row of a table.\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::row;\n\nlet rows = [\n    row![\"hello\", \"world\"],\n    row![\"goodbye\", \"world\"],\n];\n```\n\nIt is even possible to use `span!`, `line!` and `text!` in the `row!` macro:\n\n```rust\nuse ratatui::prelude::*;\nuse ratatui_macros::{span, line, text, row};\nlet name = \"Bye!!!\";\nlet text = row![text![line![\"hello\", \"world\".bold()]], span!(Modifier::BOLD; \"{name}\")];\n```\n\n## Contributing\n\nContributions to `ratatui-macros` are welcome! Whether it's submitting a bug report, a feature\nrequest, or a pull request, all forms of contributions are valued and appreciated.\n\n[Crates.io badge]: https://img.shields.io/crates/v/ratatui-macros?logo=rust\u0026style=flat-square\n[License badge]: https://img.shields.io/crates/l/ratatui-macros\n[CI Badge]:\n  https://img.shields.io/github/actions/workflow/status/ratatui-org/ratatui-macros/ci.yml?logo=github\u0026style=flat-square\n[Docs.rs badge]: https://img.shields.io/docsrs/ratatui-macros?logo=rust\u0026style=flat-square\n[Crate Downloads badge]: https://img.shields.io/crates/d/ratatui-macros?logo=rust\u0026style=flat-square\n[ratatui_macros crate]: https://crates.io/crates/ratatui-macros\n[API Docs]: https://docs.rs/ratatui-macros\n[CI Status]: https://github.com/kdheepak/ratatui-macros/actions\n[Ratatui]: https://github.com/ratatui-org/ratatui\n[Layout concepts]: https://ratatui.rs/concepts/layout\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratatui%2Fratatui-macros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratatui%2Fratatui-macros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratatui%2Fratatui-macros/lists"}