Skip to content

Commit

Permalink
Fix the README
Browse files Browse the repository at this point in the history
Summary: Its useful if the README is correct.

Reviewed By: lmvasquezg

Differential Revision: D46436301

fbshipit-source-id: 55a0f58423444a6047347daa783e587c07fdfc16
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Jun 5, 2023
1 parent 657b19b commit 740a337
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Line>> {
Ok(vec![vec!["hello world"].try_into()?])
fn draw_unchecked(&self, _dimensions: Dimensions, _mode: DrawMode) -> anyhow::Result<Lines> {
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(())
}
```
Expand Down
40 changes: 40 additions & 0 deletions examples/readme.rs
Original file line number Diff line number Diff line change
@@ -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<Lines> {
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(())
}

0 comments on commit 740a337

Please sign in to comment.