Console printer with a fluent API, written in Rust.
Lazer is a utility for printing to the console using a fluent API. Ported to Rust from the original TypeScript package.
Lazer helps you build, format and print complex messages to the console using an expressive fluent API.
main.rs
```rust use lazer::{lazer};
fn main() { lazer() .print("Hello,") .printspace() .printgreen("Green World") .print_ln("!"); } ```
```bash $ cargo run Hello, Green World!
```
```typescript use lazer::{lazer};
fn main() { let remoteaddr = "127.0.0.1"; let method = "GET"; let path = "/a/really/really/really/long/path/here"; let status = 200; let timems = 20; let sizebytesstring = "1.10kB";
lazer()
.print("[").print_utc_time().print("]")
.print_space(1).print("-").print_space(1)
.print_pad_right(remote_addr, 15, "_")
.print_space(2)
.print_pad_right(method, 4, "_")
.print_space(2)
.print_pad_right(path, 20, "_")
.print_space(2)
.iff(status >= 200 && status < 300)
.print_green(&status.to_string())
.eliff(status >= 300 && status < 400)
.print_yellow(&status.to_string())
.eliff(status >= 400)
.print_red(&status.to_string())
.end()
.print_space(2)
.print_pad_right(&format!("{}ms", time_ms), 6, "_")
.print_space(2)
.print_ln(size_bytes_string);
} ```
```bash $ deno run example.ts [Tue, 11 May 2021 17:25:18 +0000] - 127.0.0.1_ GET_ /a/really/really/r+18 200 20ms__ 1.10kB
```
```typescript import { lazer } from "https://deno.land/x/lazer/mod.ts"
const getLinePrefix = () => { return lazer().buffer() .printyellow('[').printyellow("Line Prefix").printyellow(']') .printspace().print("-").printspace() .printyellow('[').setcoloryellow().printutctime().printyellow(']') .printspace().print("-").print_space() .return(); }
lazer() .print(getLinePrefix()) .printyellowln("This is a prefixed line of text output");
lazer() .print(getLinePrefix()) .printyellowln("This is another prefixed line of text output"); ```
```bash $ deno run example.ts [Line Prefix] - [Mon, 10 May 2021 16:31:29 GMT] - This is a prefixed line of text output [Line Prefix] - [Mon, 10 May 2021 16:31:29 GMT] - This is another prefixed line of text output
```
```typescript import { lazer } from "https://deno.land/x/lazer/mod.ts"
lazer().buffer() .setcolorred().print_ln("Some red output to buffer") .store('i am an alias');
lazer().buffer() .load('i am an alias') .print_b(); ```
```bash $ deno run example.ts Some red output to buffer
```
typescript
import { lazer } from "https://deno.land/x/lazer/mod.ts"
bash
npm i --save lazer-js
javascript
const { lazer } = require('lazer-js');