Superls.StrFmt (superls v1.2.3)
View Sourceiex> Superls.StrFmt.to_string [{12000, :sizeb, [:bright]}]
"[1m 11.7K[0m"
or composable form :
iex> [ [str_fmt1, str_fmt2],
str_fmt3
] |> Superls.StrFmt.to_string()
str_fmt_unit | output for a 8 columns terminal |
---|---|
"abc" | "abc" |
[{"abc", :str, [:blue]}] | "[34mabc[0m" |
[{123, :str, [:blue]}] | "[34m123[0m" |
[{12000, :sizeb, []}] | " 11.7K" # could be B, K, M and G. |
[{1696153262, :date, [:blue]}] | "[34m2023-10-01[0m" |
[{1696153262, :datetime, []}] | "23-10-01 09:41:02" |
[{"9char-str", {:scr,50}, []}] | "9..r" # 50% of 9 chars screen |
[{"9char-str", :scr, []}] | "9ch..str" # equiv. of {:scr, 100} |
[{"foo_", :padr, []}] | "foo_____" |
[{"_", :padl, [:red]}] | "[31m_____[0m" |
Summary
Functions
Returns the terminal number of columns.
puts(fmt) convenience for to_string(fmt) |> IO.puts()
Format the str_fmt
into a string.
Types
@type str_fmt_unit() :: String.t() | {String.t() | :atom | charlist() | number(), :str, IO.ANSI.ansidata()} | {integer(), :sizeb, IO.ANSI.ansidata()} | {posix_time :: integer(), :date, IO.ANSI.ansidata()} | {posix_time :: integer(), :datetime, IO.ANSI.ansidata()} | {String.t(), :scr, IO.ANSI.ansidata()} | {String.t(), {:scr, number()}, IO.ANSI.ansidata()} | {String.t(), :padl, IO.ANSI.ansidata()} | {String.t(), :padr, IO.ANSI.ansidata()} | [str_fmt_unit()]
@type t() :: [str_fmt_unit()]
Functions
@spec ncols() :: integer()
Returns the terminal number of columns.
@spec puts(str_fmt :: t()) :: :ok
puts(fmt) convenience for to_string(fmt) |> IO.puts()
Format the str_fmt
into a string.
iex> StrFmt.to_string [{12000, :sizeb, [:bright]}]
"[1m 11.7K[0m"
The transformations are :
colors
see
IO.ANSI
.padding to a ncols terminal
padr
padl
human readable bytes B, K, M, G
sizeb
shorten txt, may add ellipsis if txt length > ncols
scr
shorten percent txt, may add ellipsis if txt length > 44% of ncols
{scr, 44}
human readable date, datetime (posix)
date
datetime
basic types interpolation
str
newline
" "