Skip to content

Commit

Permalink
Merge pull request #2 from ricardo-valero/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
lukewilliamboswell authored Feb 17, 2024
2 parents 6b6b997 + 5f44673 commit 10aae3f
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 96 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
examples/colors
examples/styles
examples/animals
examples/tui-menu

generated-docs/

format.sh
format.sh
19 changes: 19 additions & 0 deletions examples/styles.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
app "styles"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
ansi: "../package/main.roc",
}
imports [cli.Stdout, ansi.Core]
provides [main] to cli

main =
[
"Bold On" |> Core.withStyle [Bold On] |> Core.withStyle [Default],
"Italicized On" |> Core.withStyle [Italicized On] |> Core.withStyle [Default],
"Strikethrough On" |> Core.withStyle [Strikethrough On] |> Core.withStyle [Default],
"Underlined On" |> Core.withStyle [Underlined On] |> Core.withStyle [Default],
"Combination" |> Core.withStyle [Bold On, Italicized On, Strikethrough On, Underlined On],
"This should have the last style",
]
|> Str.joinWith "\n"
|> Stdout.line
18 changes: 9 additions & 9 deletions examples/tui-menu.roc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
app "tui-menu"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
ansi: "../package/main.roc",
}
imports [
pf.Stdout,
pf.Stdin,
pf.Tty,
pf.Task.{ Task },
ansi.Core.{ Color, Input, ScreenSize, Position, DrawFn },
ansi.Core.{ Control, Color, Input, ScreenSize, Position, DrawFn },
pf.Utc.{ Utc },
]
provides [main] to pf
Expand Down Expand Up @@ -151,7 +151,7 @@ getTerminalSize : Task ScreenSize []
getTerminalSize =

# Move the cursor to bottom right corner of terminal
cmd = [SetCursor { row: 999, col: 999 }, GetCursor] |> List.map Core.toStr |> Str.joinWith ""
cmd = [MoveCursor (To { row: 999, col: 999 }), GetCursor] |> List.map Control |> List.map Core.toStr |> Str.joinWith ""
{} <- Stdout.write cmd |> Task.await

# Read the cursor position
Expand All @@ -167,7 +167,7 @@ homeScreen = \model ->
Core.drawText " Choose your Thing" { r: 1, c: 1, fg: Green },
Core.drawText "RUN" { r: 2, c: 11, fg: Blue },
Core.drawText "QUIT" { r: 2, c: 26, fg: Red },
Core.drawText " ENTER TO RUN, ESCAPE TO QUIT" { r: 2, c: 1, fg: Gray },
Core.drawText " ENTER TO RUN, ESCAPE TO QUIT" { r: 2, c: 1, fg: White },
Core.drawBox { r: 0, c: 0, w: model.screen.width, h: model.screen.height },
],
{ selected, s, row } <- model |> mapSelected |> List.map
Expand All @@ -185,7 +185,7 @@ confirmScreen = \state -> [
Core.drawText " Would you like to do something?" { r: 1, c: 1, fg: Yellow },
Core.drawText "CONFIRM" { r: 2, c: 11, fg: Blue },
Core.drawText "RETURN" { r: 2, c: 30, fg: Red },
Core.drawText " ENTER TO CONFIRM, ESCAPE TO RETURN" { r: 2, c: 1, fg: Gray },
Core.drawText " ENTER TO CONFIRM, ESCAPE TO RETURN" { r: 2, c: 1, fg: White },
Core.drawText " count: TBC" { r: 3, c: 1 },
Core.drawText " speed: TBC" { r: 4, c: 1 },
Core.drawText " size: TBC" { r: 5, c: 1 },
Expand All @@ -196,7 +196,7 @@ debugScreen : Model -> List DrawFn
debugScreen = \state ->
cursorStr = "CURSOR R$(Num.toStr state.cursor.row), C$(Num.toStr state.cursor.col)"
screenStr = "SCREEN H$(Num.toStr state.screen.height), W$(Num.toStr state.screen.width)"
inputDelatStr = "DELTA $(Num.toStr (Utc.deltaAsMillis state.prevDraw state.currDraw)) millis"
inputDeltaStr = "DELTA $(Num.toStr (Utc.deltaAsMillis state.prevDraw state.currDraw)) millis"
lastInput =
state.inputs
|> List.last
Expand All @@ -206,9 +206,9 @@ debugScreen = \state ->

[
Core.drawText lastInput { r: state.screen.height - 5, c: 1, fg: Magenta },
Core.drawText inputDelatStr { r: state.screen.height - 4, c: 1, fg: Magenta },
Core.drawText inputDeltaStr { r: state.screen.height - 4, c: 1, fg: Magenta },
Core.drawText cursorStr { r: state.screen.height - 3, c: 1, fg: Magenta },
Core.drawText screenStr { r: state.screen.height - 2, c: 1, fg: Magenta },
Core.drawVLine { r: 1, c: state.screen.width // 2, len: state.screen.height, fg: Gray },
Core.drawHLine { c: 1, r: state.screen.height // 2, len: state.screen.width, fg: Gray },
Core.drawVLine { r: 1, c: state.screen.width // 2, len: state.screen.height, fg: White },
Core.drawHLine { c: 1, r: state.screen.height // 2, len: state.screen.width, fg: White },
]
Loading

0 comments on commit 10aae3f

Please sign in to comment.