Skip to content

Introduction

At the moment, we have everything in just one file. However, this can be impractical if we want to expand our app further.

Let’s start by creating a number of different files to represent the various concepts we covered in the previous section:

Terminal window
$ tree .
├── Cargo.toml
├── LICENSE
└── src
├── app.rs
├── event.rs
├── main.rs
├── tui.rs
├── ui.rs
└── update.rs

If you want to explore the code on your own, you can check out the completed source code here: https://github.com/ratatui-org/website/tree/main/code/ratatui-counter-app

Let’s go ahead and declare these files as modules in src/main.rs

/// Application.
pub mod app;
/// Terminal events handler.
pub mod event;
/// Widget renderer.
pub mod ui;
/// Terminal user interface.
pub mod tui;
/// Application updater.
pub mod update;

We are going to use anyhow in this section of the tutorial.

Terminal window
cargo add anyhow

Now we are ready to start refactoring our app.