2023-07-08 19:02:22 +00:00
|
|
|
# Contribution guidelines
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
First off, thank you for considering contributing to Ratatui.
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
If your contribution is not straightforward, please first discuss the change you wish to make by
|
|
|
|
creating a new issue before making the change, or starting a discussion on
|
|
|
|
[discord](https://discord.gg/pMCEU9hNEj).
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
## Reporting issues
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2024-08-21 18:35:08 +00:00
|
|
|
Before reporting an issue on the [issue tracker](https://github.com/ratatui/ratatui/issues),
|
2023-07-08 19:02:22 +00:00
|
|
|
please check that it has not already been reported by searching for some related keywords. Please
|
|
|
|
also check [`tui-rs` issues](https://github.com/fdehau/tui-rs/issues/) and link any related issues
|
|
|
|
found.
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
## Pull requests
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
All contributions are obviously welcome. Please include as many details as possible in your PR
|
|
|
|
description to help the reviewer (follow the provided template). Make sure to highlight changes
|
2024-08-06 11:12:08 +00:00
|
|
|
which may need additional attention, or you are uncertain about. Any idea with a large scale impact
|
2023-07-08 19:02:22 +00:00
|
|
|
on the crate or its users should ideally be discussed in a "Feature Request" issue beforehand.
|
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
### Keep PRs small, intentional, and focused
|
2023-07-08 19:02:22 +00:00
|
|
|
|
|
|
|
Try to do one pull request per change. The time taken to review a PR grows exponential with the size
|
|
|
|
of the change. Small focused PRs will generally be much more faster to review. PRs that include both
|
|
|
|
refactoring (or reformatting) with actual changes are more difficult to review as every line of the
|
|
|
|
change becomes a place where a bug may have been introduced. Consider splitting refactoring /
|
|
|
|
reformatting changes into a separate PR from those that make a behavioral change, as the tests help
|
|
|
|
guarantee that the behavior is unchanged.
|
|
|
|
|
2023-09-05 07:48:36 +00:00
|
|
|
### Code formatting
|
|
|
|
|
2024-11-23 18:53:40 +00:00
|
|
|
Run `cargo xtask format` before committing to ensure that code is consistently formatted with
|
2024-08-06 11:12:08 +00:00
|
|
|
rustfmt. Configuration is in [`rustfmt.toml`](./rustfmt.toml).
|
2023-09-05 07:48:36 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Search `tui-rs` for similar work
|
|
|
|
|
|
|
|
The original fork of Ratatui, [`tui-rs`](https://github.com/fdehau/tui-rs/), has a large amount of
|
|
|
|
history of the project. Please search, read, link, and summarize any relevant
|
|
|
|
[issues](https://github.com/fdehau/tui-rs/issues/),
|
|
|
|
[discussions](https://github.com/fdehau/tui-rs/discussions/) and [pull
|
|
|
|
requests](https://github.com/fdehau/tui-rs/pulls).
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Use conventional commits
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) and check for them as
|
|
|
|
a lint build step. To help adhere to the format, we recommend to install
|
|
|
|
[Commitizen](https://commitizen-tools.github.io/commitizen/). By using this tool you automatically
|
|
|
|
follow the configuration defined in [.cz.toml](.cz.toml). Your commit messages should have enough
|
|
|
|
information to help someone reading the [CHANGELOG](./CHANGELOG.md) understand what is new just from
|
|
|
|
the title. The summary helps expand on that to provide information that helps provide more context,
|
|
|
|
describes the nature of the problem that the commit is solving and any unintuitive effects of the
|
|
|
|
change. It's rare that code changes can easily communicate intent, so make sure this is clearly
|
|
|
|
documented.
|
2023-02-13 15:10:08 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Run CI tests before pushing a PR
|
|
|
|
|
2024-11-23 18:53:40 +00:00
|
|
|
Running `cargo xtask ci` before pushing will perform the same checks that we do in the CI process.
|
2024-05-19 05:09:15 +00:00
|
|
|
It's not mandatory to do this before pushing, however it may save you time to do so instead of
|
|
|
|
waiting for GitHub to run the checks.
|
2023-07-08 19:02:22 +00:00
|
|
|
|
|
|
|
### Sign your commits
|
|
|
|
|
|
|
|
We use commit signature verification, which will block commits from being merged via the UI unless
|
|
|
|
they are signed. To set up your machine to sign commits, see [managing commit signature
|
|
|
|
verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
|
|
|
|
in GitHub docs.
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2023-02-20 13:28:49 +00:00
|
|
|
## Implementation Guidelines
|
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Setup
|
2023-02-20 13:28:49 +00:00
|
|
|
|
2024-11-23 18:53:40 +00:00
|
|
|
TL;DR: Clone the repo and build it using `cargo xtask`.
|
2023-02-20 13:28:49 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
Ratatui is an ordinary Rust project where common tasks are managed with
|
2024-11-23 18:53:40 +00:00
|
|
|
[cargo-xtask](https://github.com/matklad/cargo-xtask). It wraps common `cargo` commands with sane
|
2023-07-08 19:02:22 +00:00
|
|
|
defaults depending on your platform of choice. Building the project should be as easy as running
|
2024-11-23 18:53:40 +00:00
|
|
|
`cargo xtask build`.
|
2021-05-02 19:33:23 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
```shell
|
2024-08-21 18:35:08 +00:00
|
|
|
git clone https://github.com/ratatui/ratatui.git
|
2023-07-08 19:02:22 +00:00
|
|
|
cd ratatui
|
2024-11-23 18:53:40 +00:00
|
|
|
cargo xtask build
|
2023-07-08 19:02:22 +00:00
|
|
|
```
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Tests
|
2021-05-02 19:33:23 +00:00
|
|
|
|
2024-08-21 18:35:08 +00:00
|
|
|
The [test coverage](https://app.codecov.io/gh/ratatui/ratatui) of the crate is reasonably
|
2023-07-08 19:02:22 +00:00
|
|
|
good, but this can always be improved. Focus on keeping the tests simple and obvious and write unit
|
|
|
|
tests for all new or modified code. Beside the usual doc and unit tests, one of the most valuable
|
|
|
|
test you can write for Ratatui is a test against the `TestBackend`. It allows you to assert the
|
|
|
|
content of the output buffer that would have been flushed to the terminal after a given draw call.
|
|
|
|
See `widgets_block_renders` in [tests/widgets_block.rs](./tests/widget_block.rs) for an example.
|
2021-05-02 19:33:23 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
When writing tests, generally prefer to write unit tests and doc tests directly in the code file
|
|
|
|
being tested rather than integration tests in the `tests/` folder.
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
If an area that you're making a change in is not tested, write tests to characterize the existing
|
|
|
|
behavior before changing it. This helps ensure that we don't introduce bugs to existing software
|
|
|
|
using Ratatui (and helps make it easy to migrate apps still using `tui-rs`).
|
2023-06-04 15:31:49 +00:00
|
|
|
|
2023-07-14 08:37:00 +00:00
|
|
|
For coverage, we have two [bacon](https://dystroy.org/bacon/) jobs (one for all tests, and one for
|
|
|
|
unit tests, keyboard shortcuts `v` and `u` respectively) that run
|
|
|
|
[cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov) to report the coverage. Several plugins
|
|
|
|
exist to show coverage directly in your editor. E.g.:
|
|
|
|
|
|
|
|
- <https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters>
|
|
|
|
- <https://github.com/alepez/vim-llvmcov>
|
|
|
|
|
2023-08-29 20:57:46 +00:00
|
|
|
### Documentation
|
|
|
|
|
2024-02-27 11:39:37 +00:00
|
|
|
Here are some guidelines for writing documentation in Ratatui.
|
|
|
|
|
2023-08-29 20:57:46 +00:00
|
|
|
Every public API **must** be documented.
|
|
|
|
|
|
|
|
Keep in mind that Ratatui tends to attract beginner Rust users that may not be familiar with Rust
|
|
|
|
concepts.
|
|
|
|
|
|
|
|
#### Content
|
|
|
|
|
|
|
|
The main doc comment should talk about the general features that the widget supports and introduce
|
|
|
|
the concepts pointing to the various methods. Focus on interaction with various features and giving
|
|
|
|
enough information that helps understand why you might want something.
|
|
|
|
|
|
|
|
Examples should help users understand a particular usage, not test a feature. They should be as
|
2024-02-27 11:39:37 +00:00
|
|
|
simple as possible. Prefer hiding imports and using wildcards to keep things concise. Some imports
|
|
|
|
may still be shown to demonstrate a particular non-obvious import (e.g. `Stylize` trait to use style
|
|
|
|
methods). Speaking of `Stylize`, you should use it over the more verbose style setters:
|
2023-08-29 20:57:46 +00:00
|
|
|
|
|
|
|
```rust
|
|
|
|
let style = Style::new().red().bold();
|
|
|
|
// not
|
|
|
|
let style = Style::default().fg(Color::Red).add_modifier(Modifiers::BOLD);
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Format
|
|
|
|
|
2024-02-27 11:39:37 +00:00
|
|
|
- First line is summary, second is blank, third onward is more detail
|
2023-09-05 07:48:36 +00:00
|
|
|
|
2023-08-29 20:57:46 +00:00
|
|
|
```rust
|
|
|
|
/// Summary
|
|
|
|
///
|
|
|
|
/// A detailed description
|
|
|
|
/// with examples.
|
|
|
|
fn foo() {}
|
|
|
|
```
|
|
|
|
|
2024-02-27 11:39:37 +00:00
|
|
|
- Max line length is 100 characters
|
2024-08-06 11:12:08 +00:00
|
|
|
See [VS Code rewrap extension](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap)
|
2023-08-29 20:57:46 +00:00
|
|
|
|
2024-02-27 11:39:37 +00:00
|
|
|
- Doc comments are above macros
|
2023-08-29 20:57:46 +00:00
|
|
|
i.e.
|
2023-09-05 07:48:36 +00:00
|
|
|
|
2023-08-29 20:57:46 +00:00
|
|
|
```rust
|
|
|
|
/// doc comment
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Foo {}
|
|
|
|
```
|
|
|
|
|
2024-02-27 11:39:37 +00:00
|
|
|
- Code items should be between backticks
|
2023-08-29 20:57:46 +00:00
|
|
|
i.e. ``[`Block`]``, **NOT** ``[Block]``
|
|
|
|
|
2024-01-07 13:44:51 +00:00
|
|
|
### Deprecation notice
|
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
We generally want to wait at least two versions before removing deprecated items, so users have
|
2024-01-07 13:44:51 +00:00
|
|
|
time to update. However, if a deprecation is blocking for us to implement a new feature we may
|
|
|
|
*consider* removing it in a one version notice.
|
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
### Use of unsafe for optimization purposes
|
2023-06-04 15:31:49 +00:00
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
We don't currently use any unsafe code in Ratatui, and would like to keep it that way. However, there
|
2023-07-08 19:02:22 +00:00
|
|
|
may be specific cases that this becomes necessary in order to avoid slowness. Please see [this
|
2024-08-21 18:35:08 +00:00
|
|
|
discussion](https://github.com/ratatui/ratatui/discussions/66) for more about the decision.
|
2023-06-04 15:31:49 +00:00
|
|
|
|
2021-05-02 19:33:23 +00:00
|
|
|
## Continuous Integration
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
We use GitHub Actions for the CI where we perform the following checks:
|
2023-07-08 19:02:22 +00:00
|
|
|
|
2020-12-06 15:28:25 +00:00
|
|
|
- The code should compile on `stable` and the Minimum Supported Rust Version (MSRV).
|
|
|
|
- The tests (docs, lib, tests and examples) should pass.
|
|
|
|
- The code should conform to the default format enforced by `rustfmt`.
|
|
|
|
- The code should not contain common style issues `clippy`.
|
|
|
|
|
2024-11-23 18:53:40 +00:00
|
|
|
You can also check most of those things yourself locally using `cargo xtask ci` which will offer you
|
2023-07-08 19:02:22 +00:00
|
|
|
a shorter feedback loop than pushing to github.
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
## Relationship with `tui-rs`
|
2020-12-06 15:28:25 +00:00
|
|
|
|
2023-07-08 19:02:22 +00:00
|
|
|
This project was forked from [`tui-rs`](https://github.com/fdehau/tui-rs/) in February 2023, with the
|
|
|
|
[blessing of the original author](https://github.com/fdehau/tui-rs/issues/654), Florian Dehau
|
|
|
|
([@fdehau](https://github.com/fdehau)).
|
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
The original repository contains all the issues, PRs, and discussion that were raised originally, and
|
2023-07-08 19:02:22 +00:00
|
|
|
it is useful to refer to when contributing code, documentation, or issues with Ratatui.
|
|
|
|
|
2024-08-06 11:12:08 +00:00
|
|
|
We imported all the PRs from the original repository, implemented many of the smaller ones, and
|
2023-07-08 19:02:22 +00:00
|
|
|
made notes on the leftovers. These are marked as draft PRs and labelled as [imported from
|
2024-08-21 18:35:08 +00:00
|
|
|
tui](https://github.com/ratatui/ratatui/pulls?q=is%3Apr+is%3Aopen+label%3A%22imported+from+tui%22).
|
2023-07-08 19:02:22 +00:00
|
|
|
We have documented the current state of those PRs, and anyone is welcome to pick them up and
|
|
|
|
continue the work on them.
|
|
|
|
|
|
|
|
We have not imported all issues opened on the previous repository. For that reason, anyone wanting
|
|
|
|
to **work on or discuss** an issue will have to follow the following workflow:
|
|
|
|
|
|
|
|
- Recreate the issue
|
|
|
|
- Start by referencing the **original issue**: ```Referencing issue #[<issue number>](<original
|
|
|
|
issue link>)```
|
|
|
|
- Then, paste the original issues **opening** text
|
|
|
|
|
|
|
|
You can then resume the conversation by replying to this new issue you have created.
|