0

When using the crossterm library with this code:

fn draw_box(stdout: &mut Stdout, x: u16, y: u16) -> Result<()> {
    let size = 5;

    let outline = (x..x + size)
        .map(|i| (i, y))
        .chain((y + 1..y + size - 1).map(|i| (x + size - 1, i)))
        .chain((y + 1..y + size - 1).map(|i| (x, i)))
        .chain((x..x + size).map(|i| (i, y + size - 1)))
        .collect::<Vec<_>>();

    for (a, b) in outline {
        stdout
            .queue(cursor::MoveTo(a, b))?
            .queue(style::Print("x"))?;
    }

    stdout.flush()?;

    stdout
        .queue(cursor::MoveTo(x + 2, y + 2))?
        .queue(style::Print("o"))?;

    stdout.flush()?;

    Ok(())
}

The last draw command clears the rest of the output to give this:

xxxxx
x   x
x o%  

If I remove that command I get the full box:

xxxxx
x   x
x   x
x   x
xxxxx%  

How can I draw the box and then draw the circle inside of the box?

dvreed77
  • 2,217
  • 2
  • 27
  • 42

0 Answers0