Skip to content

Commit

Permalink
Roc format all of src dir
Browse files Browse the repository at this point in the history
  • Loading branch information
imclerran committed Jun 5, 2024
1 parent 9241e0e commit f5e4338
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 97 deletions.
8 changes: 4 additions & 4 deletions src/ArgParser.roc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cliParser =
appName: <- Param.maybeStr { name: "app-name", help: "Name your new roc app." },
platform: <- Param.maybeStr { name: "platform", help: "The platform to use." },
packages: <- Param.strList { name: "packages", help: "Any packages to use." },

}
|> Cli.finish {
name: "roc-start",
Expand All @@ -27,10 +27,10 @@ cliParser =
}
|> Cli.assertValid

tuiSubcommand =
tuiSubcommand =
Cli.weave {}
|> Subcommand.finish {
|> Subcommand.finish {
name: "tui",
description: "Use the TUI app to browse and search for platforms and packages.",
mapper: Tui,
}
}
30 changes: 22 additions & 8 deletions src/Controller.roc
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,34 @@ getActions = \model ->
when model.state is
PlatformSelect _ ->
[Exit, SingleSelect, CursorUp, CursorDown]
|> \actions -> if List.len model.fullMenu < List.len model.platformList
then List.append actions ClearFilter else List.append actions Search
|> \actions -> if
List.len model.fullMenu < List.len model.platformList
then
List.append actions ClearFilter
else
List.append actions Search
|> List.append GoBack
|> \actions -> if Model.isNotFirstPage model then List.append actions PrevPage else actions
|> \actions -> if Model.isNotLastPage model then List.append actions NextPage else actions

PackageSelect _ ->
[Exit, MultiSelect, MultiConfirm, CursorUp, CursorDown]
|> \actions -> if List.len model.fullMenu < List.len model.packageList
then List.append actions ClearFilter else List.append actions Search
|> \actions -> if
List.len model.fullMenu < List.len model.packageList
then
List.append actions ClearFilter
else
List.append actions Search
|> List.append GoBack
|> \actions -> if Model.isNotFirstPage model then List.append actions PrevPage else actions
|> \actions -> if Model.isNotLastPage model then List.append actions NextPage else actions

Confirmation _ -> [Exit, Finish, GoBack]
InputAppName _ -> [Exit, TextConfirm, TextInput, TextBackspace]
Search _ -> [Exit, SearchGo, Cancel, TextInput, TextBackspace]
_ -> [Exit]

applyAction : { model: Model, action: UserAction, keyPress ? [KeyPress Key, None] } -> [Step Model, Done Model]
applyAction : { model : Model, action : UserAction, keyPress ? [KeyPress Key, None] } -> [Step Model, Done Model]
applyAction = \{ model, action, keyPress ? None } ->
if actionIsAvailable model action then
when model.state is
Expand Down Expand Up @@ -91,26 +101,29 @@ packageSelect = \model, action ->
PrevPage -> Step (Model.prevPage model)
_ -> Step model

searchActionHandler : Model, UserAction, { sender: [Platform, Package], keyPress ? [KeyPress Key, None] } -> [Step Model, Done Model]
searchActionHandler : Model, UserAction, { sender : [Platform, Package], keyPress ? [KeyPress Key, None] } -> [Step Model, Done Model]
searchActionHandler = \model, action, { sender, keyPress ? None } ->
when action is
Exit -> Done (Model.toUserExitedState model)
SearchGo ->
when sender is
Platform -> Step (Model.toPlatformSelectState model)
Package -> Step (Model.toPackageSelectState model)

TextBackspace -> Step (Model.backspaceBuffer model)
TextInput ->
when keyPress is
KeyPress key -> Step (Model.appendToBuffer model key)
None -> Step model
Cancel ->

Cancel ->
when sender is
Platform -> Step (model |> Model.clearSearchBuffer |> Model.toPlatformSelectState)
Package -> Step (model |> Model.clearSearchBuffer |> Model.toPackageSelectState)

_ -> Step model

inputAppName : Model, UserAction, { keyPress ? [KeyPress Key, None]} -> [Step Model, Done Model]
inputAppName : Model, UserAction, { keyPress ? [KeyPress Key, None] } -> [Step Model, Done Model]
inputAppName = \model, action, { keyPress ? None } ->
when action is
Exit -> Done (Model.toUserExitedState model)
Expand All @@ -119,6 +132,7 @@ inputAppName = \model, action, { keyPress ? None } ->
when keyPress is
KeyPress key -> Step (Model.appendToBuffer model key)
None -> Step model

TextBackspace -> Step (Model.backspaceBuffer model)
_ -> Step model

Expand Down
64 changes: 41 additions & 23 deletions src/Model.roc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Model : {
screen : Core.ScreenSize,
cursor : Core.Position,
menuRow : I32,
pageFirstItem: U64,
pageFirstItem : U64,
menu : List Str,
fullMenu : List Str,
selected : List Str,
Expand Down Expand Up @@ -70,10 +70,10 @@ init = \platformList, packageList -> {
packageList,
selected: [],
inputs: List.withCapacity 1000,
state: InputAppName { nameBuffer: [], config: emptyConfig }
state: InputAppName { nameBuffer: [], config: emptyConfig },
}

paginate: Model -> Model
paginate : Model -> Model
paginate = \model ->
maxItems = model.screen.height - (model.menuRow + 1) |> Num.toU64
pageFirstItem =
Expand All @@ -91,7 +91,7 @@ paginate = \model ->
cursor = { row: curRow, col: model.cursor.col }
{ model & menu, pageFirstItem, cursor }

nextPage: Model -> Model
nextPage : Model -> Model
nextPage = \model ->
maxItems = model.screen.height - (model.menuRow + 1) |> Num.toU64
if isNotLastPage model then
Expand All @@ -102,7 +102,7 @@ nextPage = \model ->
else
model

prevPage: Model -> Model
prevPage : Model -> Model
prevPage = \model ->
maxItems = model.screen.height - (model.menuRow + 1) |> Num.toU64
if isNotFirstPage model then
Expand All @@ -121,7 +121,6 @@ isNotLastPage = \model ->
maxItems = model.screen.height - (model.menuRow + 1) |> Num.toU64
model.pageFirstItem + maxItems < List.len model.fullMenu


moveCursor : Model, [Up, Down] -> Model
moveCursor = \model, direction ->
if List.len model.menu > 0 then
Expand Down Expand Up @@ -151,6 +150,7 @@ toInputAppNameState = \model ->
cursor: { row: 2, col: 2 },
state: InputAppName { config, nameBuffer: config.appName |> Str.toUtf8 },
}

_ -> model

toPlatformSelectState : Model -> Model
Expand All @@ -162,29 +162,37 @@ toPlatformSelectState = \model ->
{ model &
cursor: { row: 2, col: 2 },
state: PlatformSelect { config: newConfig },
} |> paginate
}
|> paginate

Search { config, searchBuffer } ->
{ model &
fullMenu: model.platformList |> List.keepIf \item -> Str.contains item (searchBuffer |> Str.fromUtf8 |> Result.withDefault ""),
cursor: { row: 2, col: 2 },
state: PlatformSelect { config },
} |> paginate
}
|> paginate

PackageSelect { config } ->
configWithPackages = when (addSelectedPackagesToConfig model).state is
PackageSelect data -> data.config
_ -> config
configWithPackages =
when (addSelectedPackagesToConfig model).state is
PackageSelect data -> data.config
_ -> config
{ model &
pageFirstItem: 0,
fullMenu: model.platformList,
cursor: { row: 2, col: 2 },
state: PlatformSelect { config: configWithPackages }
} |> paginate
state: PlatformSelect { config: configWithPackages },
}
|> paginate

_ ->
{ model &
menu: model.platformList,
cursor: { row: 2, col: 2 },
state: PlatformSelect { config: { platform: "", appName: "", packages: [] } },
} |> paginate
}
|> paginate

toPackageSelectState : Model -> Model
toPackageSelectState = \model ->
Expand All @@ -197,7 +205,8 @@ toPackageSelectState = \model ->
cursor: { row: 2, col: 2 },
selected: config.packages,
state: PackageSelect { config: { config & platform } },
} |> paginate
}
|> paginate

Search { config, searchBuffer } ->
{ model &
Expand All @@ -206,7 +215,8 @@ toPackageSelectState = \model ->
cursor: { row: 2, col: 2 },
selected: config.packages,
state: PackageSelect { config },
} |> paginate
}
|> paginate

Confirmation { config } ->
{ model &
Expand All @@ -215,15 +225,17 @@ toPackageSelectState = \model ->
selected: config.packages,
cursor: { row: 2, col: 2 },
state: PackageSelect { config },
} |> paginate
}
|> paginate

_ ->
{ model &
pageFirstItem: 0,
fullMenu: model.packageList,
cursor: { row: 2, col: 2 },
state: PackageSelect { config: { platform: "", appName: "", packages: [] } },
} |> paginate
}
|> paginate

toFinishedState : Model -> Model
toFinishedState = \model ->
Expand Down Expand Up @@ -266,13 +278,17 @@ clearSearchFilter = \model ->
PackageSelect _ ->
{ model &
fullMenu: model.packageList,
#cursor: { row: model.menuRow, col: 2 },
} |> paginate
# cursor: { row: model.menuRow, col: 2 },
}
|> paginate

PlatformSelect _ ->
{ model &
fullMenu: model.platformList,
#cursor: { row: model.menuRow, col: 2 },
} |> paginate
# cursor: { row: model.menuRow, col: 2 },
}
|> paginate

_ -> model

appendToBuffer : Model, Key -> Model
Expand All @@ -281,6 +297,7 @@ appendToBuffer = \model, key ->
Search { searchBuffer, config, sender } ->
newBuffer = List.concat searchBuffer (Keys.keyToSlugStr key |> Str.toUtf8)
{ model & state: Search { config, sender, searchBuffer: newBuffer } }

InputAppName { nameBuffer, config } ->
newBuffer = List.concat nameBuffer (Keys.keyToSlugStr key |> Str.toUtf8)
{ model & state: InputAppName { config, nameBuffer: newBuffer } }
Expand All @@ -293,6 +310,7 @@ backspaceBuffer = \model ->
Search { searchBuffer, config, sender } ->
newBuffer = List.dropLast searchBuffer 1
{ model & state: Search { config, sender, searchBuffer: newBuffer } }

InputAppName { nameBuffer, config } ->
newBuffer = List.dropLast nameBuffer 1
{ model & state: InputAppName { config, nameBuffer: newBuffer } }
Expand All @@ -313,7 +331,7 @@ toggleSelected = \model ->
if List.contains model.selected item then
{ model & selected: List.dropIf model.selected \i -> i == item }
else
{ model & selected: List.append model.selected item }
{ model & selected: List.append model.selected item }

addSelectedPackagesToConfig : Model -> Model
addSelectedPackagesToConfig = \model ->
Expand Down
4 changes: 2 additions & 2 deletions src/Repo.roc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module [RepositoryEntry, RemoteRepoEntry, CacheRepoEntry]

RepositoryEntry : { alias : Str, version : Str, url : Str }
RemoteRepoEntry : { repo: Str, owner: Str, alias: Str, platform: Bool }
CacheRepoEntry : { repo: Str, owner: Str, alias: Str, version: Str, url: Str, platform: Bool }
RemoteRepoEntry : { repo : Str, owner : Str, alias : Str, platform : Bool }
CacheRepoEntry : { repo : Str, owner : Str, alias : Str, version : Str, url : Str, platform : Bool }
Loading

0 comments on commit f5e4338

Please sign in to comment.