From 740a33735b175d4a8ce4adebe730912b0c1be7d7 Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Mon, 5 Jun 2023 03:26:25 -0700 Subject: [PATCH] Fix the README Summary: Its useful if the README is correct. Reviewed By: lmvasquezg Differential Revision: D46436301 fbshipit-source-id: 55a0f58423444a6047347daa783e587c07fdfc16 --- README.md | 25 ++++++++++--------------- examples/readme.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 examples/readme.rs diff --git a/README.md b/README.md index 827e04e..e147451 100644 --- a/README.md +++ b/README.md @@ -18,31 +18,26 @@ Finally, superconsole delineates between rendering logic and program state - eac ```rust use std::convert::TryInto; -use superconsole::{ - components::bordering::{Bordered, BorderedSpec}, - Component, Dimensions, DrawMode, Line, State, SuperConsole, -}; +use superconsole::components::bordering::{Bordered, BorderedSpec}; +use superconsole::{Component, Dimensions, DrawMode, Lines, SuperConsole}; #[derive(Debug)] struct HelloWorld; impl Component for HelloWorld { - fn draw_unchecked( - &self, - _dimensions: Dimensions, - _mode: DrawMode, - ) -> anyhow::Result> { - Ok(vec![vec!["hello world"].try_into()?]) + fn draw_unchecked(&self, _dimensions: Dimensions, _mode: DrawMode) -> anyhow::Result { + Ok(Lines(vec![ + vec!["Hello world!".to_owned()].try_into().unwrap(), + ])) } } pub fn main() -> anyhow::Result<()> { let bordering = BorderedSpec::default(); - let mut superconsole = - SuperConsole::new(Box::new(Bordered::new(Box::new(HelloWorld), bordering))) - .ok_or_else(|| anyhow::anyhow!("Not a TTY"))?; - superconsole.render(&state![])?; - superconsole.finalize(&state![])?; + let mut superconsole = SuperConsole::new().ok_or_else(|| anyhow::anyhow!("Not a TTY"))?; + let component = Bordered::new(HelloWorld, bordering); + superconsole.render(&component)?; + superconsole.finalize(&component)?; Ok(()) } ``` diff --git a/examples/readme.rs b/examples/readme.rs new file mode 100644 index 0000000..94b18b3 --- /dev/null +++ b/examples/readme.rs @@ -0,0 +1,40 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under both the MIT license found in the + * LICENSE-MIT file in the root directory of this source tree and the Apache + * License, Version 2.0 found in the LICENSE-APACHE file in the root directory + * of this source tree. + */ + +// If this code needs fixing, make sure you fix the README.md too! + +use std::convert::TryInto; + +use superconsole::components::bordering::Bordered; +use superconsole::components::bordering::BorderedSpec; +use superconsole::Component; +use superconsole::Dimensions; +use superconsole::DrawMode; +use superconsole::Lines; +use superconsole::SuperConsole; + +#[derive(Debug)] +struct HelloWorld; + +impl Component for HelloWorld { + fn draw_unchecked(&self, _dimensions: Dimensions, _mode: DrawMode) -> anyhow::Result { + Ok(Lines(vec![ + vec!["Hello world!".to_owned()].try_into().unwrap(), + ])) + } +} + +pub fn main() -> anyhow::Result<()> { + let bordering = BorderedSpec::default(); + let mut superconsole = SuperConsole::new().ok_or_else(|| anyhow::anyhow!("Not a TTY"))?; + let component = Bordered::new(HelloWorld, bordering); + superconsole.render(&component)?; + superconsole.finalize(&component)?; + Ok(()) +}