-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update widgets section and conclusion
- Loading branch information
Showing
10 changed files
with
116 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: App | ||
--- | ||
|
||
Finally, let's make a field in the app struct that uses the `SearchPage` widget: | ||
|
||
```rust | ||
{{#include @code/crates-tui-tutorial-app/src/app.rs:imports_core}} | ||
|
||
{{#include @code/crates-tui-tutorial-app/src/app.rs:app}} | ||
``` | ||
|
||
With this refactor, now `./src/app.rs` becomes a lot simpler. For example, app now delegates to the | ||
search page widget for all core functionality. | ||
|
||
```rust | ||
impl App { | ||
{{#include @code/crates-tui-tutorial-app/src/app.rs:app_handle_action}} | ||
} | ||
``` | ||
|
||
And rendering delegates to `SearchPageWidget`: | ||
|
||
```rust | ||
impl App { | ||
{{#include @code/crates-tui-tutorial-app/src/app.rs:app_statefulwidget}} | ||
} | ||
``` | ||
|
||
<details> | ||
|
||
<summary>Copy the following into <code>src/app.rs</code></summary> | ||
|
||
```rust | ||
{{#include @code/crates-tui-tutorial-app/src/app.rs}} | ||
``` | ||
|
||
</details> | ||
|
||
Your final folder structure will look like this: | ||
|
||
``` | ||
. | ||
├── Cargo.lock | ||
├── Cargo.toml | ||
└── src | ||
├── app.rs | ||
├── crates_io_api_helper.rs | ||
├── errors.rs | ||
├── events.rs | ||
├── main.rs | ||
├── tui.rs | ||
├── widgets | ||
│ ├── search_page.rs | ||
│ ├── search_prompt.rs | ||
│ └── search_results.rs | ||
└── widgets.rs | ||
``` | ||
|
||
If you put all of it together, you should be able run the TUI. | ||
|
||
![](./crates-tui-demo.gif) | ||
|
||
Search for your favorite crates and explore crates.io. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters