Skip to content

[CLOSED] A more leaner prelude #7

@nik-rev

Description

@nik-rev

cargo-script may be stabilizing soon, and I see myself using farben quite a lot when writing cargo scripts.

farben exposes a high-level interface via all the cprintln! macros and variations. But it also exposes a low-level interface via functions like try_color strip_ansi, ansi_strip!

I don't see these extras being used in the "common case", so I propose to cut down the prelude. (you can always add more stuff to the prelude even after v1.0, but you can't remove stuff from it if you release v1.0)

For example, I don't imagine ever needing to parse colors at runtime when I'm writing scripts:

match try_color("[red]Hello[/]") {
    Ok(s) => print!("{s}"),
    Err(e) => eprintln!("parse error: {e}"),
}

I'd just use cprint!("[red]Hello[/]")

I believe it'd make sense to reduce the prelude to only these:

New prelude

formatting:

  • cformat!
  • cformatb!

write:

  • cwrite!
  • cwriteb!
  • cwriteln!
  • cwritebln!

stdout:

  • cprint!
  • cprintb!
  • cprintln!
  • cprintbln!

stderr:

  • ceprint!
  • ceprintb!
  • ceprintln!
  • ceprintbln!

utilities:

  • style!
  • prefix!

Metadata

Metadata

Assignees

Labels

breakingWould introduce a breaking changeenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions