Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Don't edit the `bin` list manually. Run `rustlings dev update` after changing
# exercises or solutions.
bin = []
bin = [
{ name = "intro1", path = "exercises/00_intro/intro1.rs" },
{ name = "intro1_sol", path = "solutions/00_intro/intro1.rs" },
]

[package]
name = "ratlings"
Expand Down
1 change: 0 additions & 1 deletion exercises/.gitkeep

This file was deleted.

36 changes: 36 additions & 0 deletions exercises/00_intro/intro1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use ratatui::{DefaultTerminal, Frame};
use std::io::IsTerminal;

// Do not modify this line
fn main() -> std::io::Result<()> {
// TODO: run the TUI app.
// ratatui::run(app)
todo!("run the TUI app.")
}

fn app(terminal: &mut DefaultTerminal) -> std::io::Result<()> {
loop {
terminal.draw(render)?;
if !std::io::stdout().is_terminal() || ratatui::crossterm::event::read()?.is_key_press() {
break Ok(());
}
}
}

fn render(frame: &mut Frame) {
frame.render_widget("hello world", frame.area());
}

#[cfg(test)]
mod tests {
use super::*;
use ratatui::{Terminal, backend::TestBackend};

#[test]
fn renders_hello_world() {
let mut terminal =
Terminal::new(TestBackend::new(15, 1)).expect("test backend initialization");
terminal.draw(render).expect("render frame");
terminal.backend().assert_buffer_lines(["hello world "]);
}
}
7 changes: 5 additions & 2 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ final_message = """
You finished Ratlings! 🎉
"""

exercises = []

# Add exercise metadata here. See CONTRIBUTING.md and the Rustlings community
# exercises guide: https://rustlings.rust-lang.org/community-exercises/
#
# [[exercises]]
# name = "example"
# dir = "section"
# hint = "A helpful hint."

[[exercises]]
name = "intro1"
dir = "00_intro"
hint = "Uncomment the line below the TODO-comment."
1 change: 0 additions & 1 deletion solutions/.gitkeep

This file was deleted.

33 changes: 33 additions & 0 deletions solutions/00_intro/intro1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use ratatui::{DefaultTerminal, Frame};
use std::io::IsTerminal;

fn main() -> std::io::Result<()> {
ratatui::run(app)
}

fn app(terminal: &mut DefaultTerminal) -> std::io::Result<()> {
loop {
terminal.draw(render)?;
if !std::io::stdout().is_terminal() || ratatui::crossterm::event::read()?.is_key_press() {
break Ok(());
}
}
}

fn render(frame: &mut Frame) {
frame.render_widget("hello world", frame.area());
}

#[cfg(test)]
mod tests {
use super::*;
use ratatui::{Terminal, backend::TestBackend};

#[test]
fn renders_hello_world() {
let mut terminal =
Terminal::new(TestBackend::new(15, 1)).expect("test backend initialization");
terminal.draw(render).expect("render frame");
terminal.backend().assert_buffer_lines(["hello world "]);
}
}
Loading