import Layoutz
demo = layout
[ center $ row
[ withStyle StyleBold $ text "Layoutz"
, underlineColored "^" ColorCyan $ text "DEMO"
]
, br
, row
[ statusCard "Users" "1.2K"
, withBorder BorderDouble $ statusCard "API" "UP"
, withColor ColorRed $ withBorder BorderThick $
statusCard "CPU" "23%"
, withStyle StyleReverse $ withBorder BorderRound $
table ["Name", "Role", "Skills"]
[ [text "Gegard", text "Pugilist",
ul [text "Armenian",
ul [text "bad", ul [text "man"]]]]
, [text "Eve", text "QA", text "Testing"]
]
]
]
main = putStrLn $ render demo
open Layoutz
let demo =
layout
[ center
(row
[ s "Layoutz" |> styleBold
; underlineColored ~char:"^" ~color:Color.cyan (s "DEMO")
])
; br
; row
[ statusCard ~label:(s "Users") ~content:(s "1.2K")
; statusCard ~label:(s "API") ~content:(s "UP") |> borderDouble
; statusCard ~label:(s "CPU") ~content:(s "23%")
|> borderThick |> colorRed
; table
~headers:[ s "Name"; s "Role"; s "Skills" ]
[ [ s "Gegard"; s "Pugilist"
; ul [ li ~c:[ li ~c:[ li (s "man") ]
(s "bad") ] (s "Armenian") ] ]
; [ s "Eve"; s "QA"; s "Testing" ] ]
|> borderRound |> styleReverse
]
]
let () = print demo
import layoutz._
case class St(progress: Double, done: Int)
case object Tick
object Loader extends LayoutzApp[St, Tick.type] {
def init = (St(0, 0), Cmd.none)
def update(msg: Tick.type, s: St) = {
if (s.done > 30) (s, Cmd.exit)
else if (s.progress >= 1.0) (s.copy(done = s.done + 1), Cmd.none)
else (s.copy(progress = math.min(1.0, s.progress + 0.008)), Cmd.none)
}
def subscriptions(s: St) = Sub.time.everyMs(16, Tick)
def view(s: St) = {
val w = 40; val filled = (s.progress * w).toInt
val bar = (0 until w).map { i =>
if (i < filled) { val r = i.toDouble / w
"█".color(Color.True((r*180).toInt+50, ((1-r)*200).toInt+55, 255))
} else "░".color(Color.BrightBlack)
}
layout(rowTight(bar: _*),
s"Linking... ${(s.progress*100).toInt}%%".color(Color.BrightCyan))
}
}
println("hello from a normal process")
println("doing some work...")
println("now watch this:")
Loader.run(clearOnStart = false, clearOnExit = false)
println("back to normal output")
import Layoutz
data St = St { progress :: Double, done :: Int }
data Msg = Tick
app :: LayoutzApp St Msg
app = LayoutzApp
{ appInit = (St 0.0 0, CmdNone)
, appUpdate = \Tick st ->
if done st > 30 then (st, CmdExit)
else if progress st >= 1.0
then (st { done = done st + 1 }, CmdNone)
else (st { progress = min 1.0 (progress st + 0.008) }, CmdNone)
, appSubscriptions = \_ -> subEveryMs 16 Tick
, appView = \st ->
let w = 40
f = floor (progress st * fromIntegral w)
bar = map (\i ->
let r = fromIntegral i / fromIntegral w
in withColor (ColorTrue (floor(r*180)+50)
(floor((1-r)*200)+55) 255) $ text "█") [0..f-1]
emp = replicate (w-f) (withColor ColorBrightBlack $ text "░")
pct = show (floor (progress st * 100)) ++ "%"
in layout [ tightRow (bar ++ emp)
, withColor ColorBrightCyan $ text $ "Linking... " <> pct ]
}
main = do
putStrLn "hello from a normal process"
putStrLn "doing some work..."
putStrLn "now watch this:"
runApp app
putStrLn "back to normal output"
open Layoutz
type st = { progress : float; done_ticks : int }
type msg = Tick
let loader =
{ init = ({ progress = 0.0; done_ticks = 0 }, CmdNone);
update = (fun Tick st ->
if st.done_ticks > 30 then (st, CmdExit)
else if st.progress >= 1.0
then ({ st with done_ticks = st.done_ticks + 1 }, CmdNone)
else ({ st with progress = min 1.0 (st.progress +. 0.008) }, CmdNone));
subscriptions = (fun _ -> sub_every_ms 16 Tick);
view = (fun st ->
let w = 40 in
let filled = int_of_float (st.progress *. float_of_int w) in
let bar = List.init w (fun i ->
if i < filled then
let r = float_of_int i /. float_of_int w in
s "█" |> colorRGB (int_of_float (r *. 180.) + 50)
(int_of_float ((1. -. r) *. 200.) + 55) 255
else s "░" |> colorBrightBlack) in
let pct = Printf.sprintf "%d%%" (int_of_float (st.progress *. 100.)) in
layout [ tightRow bar; s ("Linking... " ^ pct) |> colorBrightCyan ]);
}
let () =
let opts = { default_options with
clear_on_start = false; clear_on_exit = false } in
print_endline "hello from a normal process";
print_endline "doing some work...";
print_endline "now watch this:";
run_app ~options:opts loader;
print_endline "back to normal output"