| Crates.io | rust-bf |
| lib.rs | rust-bf |
| version | 0.4.0 |
| created_at | 2025-09-03 19:07:58.632245+00 |
| updated_at | 2025-09-03 19:07:58.632245+00 |
| description | A Brainfuck interpreter, generator, REPL, and IDE written in Rust |
| homepage | |
| repository | https://github.com/kennethlove/rust-bf |
| max_upload_size | |
| id | 1823061 |
| size | 218,790 |
A Brainfuck interpreter written in Rust, exposed as a library, a reader, a writer, a REPL, and an IDE.
, reads a single byte from stdin (EOF sets current cell to 0). prints the byte as a character (no newline); the CLI appends a trailing newline for readability[]; unmatched brackets are an erroru8) for + and ---debug or -d) prints a step-by-step execution table instead of performing I/OTo install the CLI tool, you can use Cargo:
cargo install --locked rust-bf
If you want to build from source:
cargo buildcargo testcargo run --example usageThe read command interprets and runs Brainfuck code. It prints a trailing newline after execution.
Flags:
--debug or -d: run in debug mode (prints a step-by-step table)--memory <size> or -m <size>: set custom memory tape size (default: 30,000 cells)--max-steps <steps> or -s <steps>: limit execution to a maximum number of steps (default: unlimited)--timeout <seconds> or -t <seconds>: limit execution time (default: unlimited)--help or -h: show help informationEnv vars:
BF_TIMEOUT: set default timeout in seconds (overridden by --timeout)BF_MAX_STEPS: set default max steps (overridden by --max-steps)Examples:
Hello World
cargo run -- read "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++. ------.--------.>+.>."Echo a single byte from stdin (",.")
printf 'Z' | cargo run -- read ",."Z followed by a newline from the CLIDebug mode (prints a table instead of executing I/O)
cargo run -- read --debug ">+.<", behaves as EOF (cell set to 0) and . output is suppressedFrom a file
cargo run -- read --file ./hello.bfFrom a file with custom memory size and max steps
cargo run -- read --file ./hello.bf --memory 10000 --max-steps 100000From a file with a timeout of 2 seconds
cargo run -- read --file ./hello.bf --timeout 2Notes:
[ or ] cause an error.Generate Brainfuck code that prints the provided input.
Examples:
-- separator):
cargo run -- write "Hello world"echo -n 'Hello' | cargo run --bin bf -- writecargo run -- write --file ./message.txtcargo run -- write --bytes --file ./image.binThe output is Brainfuck code printed to stdout (a trailing newline is added for readability).
Interactive REPL for Brainfuck code execution.
cargo run -- replBF_REPL_TIMEOUT - max execution time in seconds (default: 2,000)BF_REPL_MAX_STEPS - max execution steps (default: unlimited):):
:help - show help:exit - exit the REPL:reset - clear the current buffer:dump - print the current buffer
-n to print line numbers-stderr to send everything to stderrSubmission model and Ctrl-C
Stream separation
:dump defaults: content to stdout, framing to stderr; flags can change this (see below).Modes and navigation
Interactive vs bare mode
--bare (alias: --non-interactive): force bare mode even on a TTY.--editor: force interactive mode; on non-TTY stdin prints an error to stderr and exits 1.Timeouts and step limits
Meta commands (start a line with “:”)
:exit — Exit immediately with code 0.:help — Show key bindings, modes, EOF per OS, timeout/step-limit policy, and examples.:reset — Clear the current buffer; history is unchanged.:dump — Print the current buffer for inspection.
-n — include line numbers (stdout)--stderr — send everything (content + framing) to stderr:dump:dump -n:dump --stderrKey bindings (quick reference)
IDE for Brainfuck code authoring.
cargo run -- idecargo run -- ide --file ./example.bf to open a file on startup[ or ]).Create the file ~/.config/bf.toml. Customize with your selected ANSI colors.
Here's the default theme:
[colors]
editor_title_focused = "cyan" # Editor pane title when focused
editor_title_unfocused = "gray" # Editor pane title when unfocused
gutter_text = "darkgray" # Gutter (line numbers) text color
output_title_focused = "cyan" # Output pane title when focused
output_title_unfocused = "gray" # Output pane title when unfocused
tape_border_focused = "cyan" # Tape pane border when focused
tape_border_unfocused = "gray" # Tape pane border when unfocused
tape_cell_empty = "darkgray" # Empty tape cell (0)
tape_cell_nonzero = "white" # Non-zero tape cell
tape_cell_pointer = "yellow" # Current cell (pointer)
status_text = "white" # Status bar text color
dialog_title = "white" # Dialog title text color
dialog_bg = "black" # Dialog background color
dialog_error = "red" # Error dialog text color
dialog_text = "white" # Dialog normal text color
help_hint = "gray" # Help hint text color
editor_op_right = "cyan" # '>'
editor_op_left = "green" # '<'
editor_op_inc = "lightgreen" # '+'
editor_op_dec = "red" # '-'
editor_op_output = "yellow" # '.'
editor_op_input = "magenta" # ','
editor_op_bracket = "lightmagenta" # '[' or ']'
editor_non_bf = "gray" # non-Brainfuck characters
Add this crate to your project. Then:
use rust_bf::Brainfuck;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Classic Hello World
let code = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
let mut bf = Brainfuck::new(code.to_string());
bf.run()?;
println!(); // optional: newline for readability
Ok(())
}
Debug run (no real I/O; prints a table):
use rust_bf::Brainfuck;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let code = ">+.<"; // simple program
let mut bf = Brainfuck::new(code.to_string());
bf.run_debug()?; // prints a step-by-step table
Ok(())
}
use rust_bf::Brainfuck;
let mut bf = Brainfuck::new_with_memory(
"+>+<[->+<]".to_string(),
1024, // custom tape size
);
let _ = bf.run();
,: reads exactly one byte from stdin. On EOF, sets current cell to 0..: prints the current cell as a char (no newline).> / <: moving beyond the tape bounds returns PointerOutOfBounds.UnmatchedBrackets.><+-.,[] produces InvalidCharacter.IoError(std::io::Error).src/lib.rs.tests/stdin_read.rs verifies stdin handling for the CLItests/debug_flag.rs verifies the --debug table outputcargo testexamples/usage.rs shows a minimal library usage example.examples/debug.rs shows how to run a program in debug mode (prints a step-by-step table).Run:
cargo run --example usagecargo run --example debugApache 2.0