From f4eefced854619cad551ad999276079a3e981f48 Mon Sep 17 00:00:00 2001 From: Adrien Champion Date: Mon, 9 Mar 2026 10:06:15 +0100 Subject: [PATCH 1/2] chore: modules --- Colorized.lean | 36 +++++++++++++++++++++++++++--------- Example.lean | 4 +++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Colorized.lean b/Colorized.lean index 0ee84f9..2435ebb 100644 --- a/Colorized.lean +++ b/Colorized.lean @@ -1,5 +1,9 @@ +module + namespace Colorized +public section + /-! Colorized library for adding color and style to text output. This library provides functionality to change the foreground and background colors, as well as to apply various text styles. -/ @@ -64,19 +68,33 @@ class Colorized (α : Type) where bgColor := colorize Section.Background color := colorize Section.Foreground +end + +namespace Colorized + + /-- Constant string representing the beginning of an ANSI escape sequence. -/ private def const := "\x1b[" /-- Constant string for resetting text formatting. -/ private def reset := "\x1b[0m" -instance : Colorized String where - colorize sec col str := - let sectionNum := - match sec with - | Section.Foreground => "9" - | Section.Background => "4" - s!"{const}{sectionNum}{repr col}m{str}{reset}" +/-- Applies a section/color to a string. -/ +@[inline] +public def colorizeString (sec : Section) (col : Color) (str : String) : String := + let secNum := + match sec with + | .Foreground => "9" + | .Background => "4" + s!"{const}{secNum}{repr col}m{str}{reset}" + +/-- Applies a style to a string. -/ +@[inline] +public def stylizeString (sty : Style) (str : String) : String := + s!"{const}{repr sty}m{str}{reset}" + +end Colorized - style sty str := - s!"{const}{repr sty}m{str}{reset}" +public instance : Colorized String where + colorize := Colorized.colorizeString + style := Colorized.stylizeString diff --git a/Example.lean b/Example.lean index 09024c1..92dc5f2 100644 --- a/Example.lean +++ b/Example.lean @@ -1,7 +1,9 @@ +module + import «Colorized» open Colorized -def main : IO Unit := do +public def main : IO Unit := do -- | Simple style IO.println (Colorized.style Style.Underline "Hello, world!") From b59df24859e41dc1aecb46c004d8295e0bb3e2c1 Mon Sep 17 00:00:00 2001 From: Adrien Champion Date: Mon, 9 Mar 2026 10:12:46 +0100 Subject: [PATCH 2/2] chore: closer to original API --- Colorized.lean | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Colorized.lean b/Colorized.lean index 2435ebb..bcc1f05 100644 --- a/Colorized.lean +++ b/Colorized.lean @@ -70,9 +70,6 @@ class Colorized (α : Type) where end -namespace Colorized - - /-- Constant string representing the beginning of an ANSI escape sequence. -/ private def const := "\x1b[" @@ -93,8 +90,6 @@ public def colorizeString (sec : Section) (col : Color) (str : String) : String public def stylizeString (sty : Style) (str : String) : String := s!"{const}{repr sty}m{str}{reset}" -end Colorized - public instance : Colorized String where colorize := Colorized.colorizeString style := Colorized.stylizeString