From d3f34ac13c01d9e26ccccd539a2854b1170855b7 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 28 May 2019 22:12:36 -0700 Subject: [PATCH] Implement reading from input. --- src/CacheSim/Model.elm | 2 ++ src/CacheSim/View.elm | 16 +++++++++++++--- src/Main.elm | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/CacheSim/Model.elm b/src/CacheSim/Model.elm index efb6a4b..1bf47a8 100644 --- a/src/CacheSim/Model.elm +++ b/src/CacheSim/Model.elm @@ -7,6 +7,7 @@ type alias Model = { rawHierarchy : RawCacheModelHierarchy , hierarchy : Maybe CacheHierarchy , accessView : Maybe AccessView + , accessInput : String } type alias Flags = () type Msg @@ -15,5 +16,6 @@ type Msg | DeleteRawModel Int | UseHierarchy (Maybe CacheModelHierarchy) | Access Int + | ChangeAccessInput String | AccessViewForward | AccessViewBack diff --git a/src/CacheSim/View.elm b/src/CacheSim/View.elm index 71fd3a5..2e93718 100644 --- a/src/CacheSim/View.elm +++ b/src/CacheSim/View.elm @@ -140,8 +140,18 @@ viewAccessView m av = , viewCacheHierarchy <| effectiveCacheHierarchy currentCache av ] -viewAccessInput : Html Msg -viewAccessInput = input [ type_ "button", onClick (Access 128), value "Access me" ] [] +viewAccessInput : Model -> Html Msg +viewAccessInput m = + let + accessButton = + case String.toInt m.accessInput of + Just i -> optionalButton True "Access address" (Access i) + Nothing -> optionalButton False "Access address" (Access -1) + in + div [] + [ labeledInput "Access address" m.accessInput ChangeAccessInput + , accessButton + ] viewError : Bool -> String -> Html Msg viewError hide e = span [ classList [ ("hidden", hide) ] ] [ text e ] @@ -153,4 +163,4 @@ viewBase m = cacheView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| m.accessView in - div [] <| [ rawView, viewAccessInput] ++ cacheView ++ accessView + div [] <| [ rawView, viewAccessInput m] ++ cacheView ++ accessView diff --git a/src/Main.elm b/src/Main.elm index 8f3f694..8e8bea1 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -19,6 +19,7 @@ init f = { rawHierarchy = testCacheModelHierarchy , hierarchy = Nothing , accessView = Nothing + , accessInput = "" } in (initialModel, Cmd.none) @@ -37,6 +38,7 @@ update msg m = DeleteRawModel i -> updateDeleteRawModel i m UseHierarchy cmh -> updateUseHierarchy cmh m Access i -> updateAccess i m + ChangeAccessInput s -> ({ m | accessInput = s }, Cmd.none) AccessViewForward -> updateAccessViewForward m AccessViewBack -> updateAccessViewBack m