1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
module Struct.UI exposing (..)
-- Elm -------------------------------------------------------------------------
import List
import Html
-- Local Module ----------------------------------------------------------------
import Struct.Event
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type InputType =
NoInput
| FloatInput
| IntegerInput
| StringInput
| CommandInput
type alias Type =
{
displayed_texts : (List (Html.Html Struct.Event.Type)),
displayed_errors : (List (Html.Html Struct.Event.Type)),
displayed_choices : (List (Int, (Html.Html Struct.Event.Type))),
min : Int,
max : Int,
min_float : Float,
max_float : Float,
input : InputType,
field_content : String
}
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
new : Type
new =
{
displayed_texts = [],
displayed_errors = [],
displayed_choices = [],
min = -1,
max = -1,
min_float = -1.0,
max_float = -1.0,
input = NoInput,
field_content = ""
}
display_text : (Html.Html Struct.Event.Type) -> Type -> Type
display_text html ui =
{ui | displayed_texts = (List.append ui.displayed_texts [html])}
display_error : (Html.Html Struct.Event.Type) -> Type -> Type
display_error html ui =
{ui | displayed_errors = (List.append ui.displayed_errors [html])}
display_string_error : String -> Type -> Type
display_string_error string ui =
{ui |
displayed_errors = (List.append ui.displayed_errors [(Html.text string)])
}
display_choice : Int -> (Html.Html Struct.Event.Type) -> Type -> Type
display_choice ix html ui =
{ui | displayed_choices = (List.append ui.displayed_choices [(ix, html)])}
prompt_string : Int -> Int -> Type -> Type
prompt_string min max ui = {ui | min = min, max = max, input = StringInput}
prompt_float : Float -> Float -> Type -> Type
prompt_float min max ui =
{ui | min_float = min, max_float = max, input = FloatInput}
prompt_integer : Int -> Int -> Type -> Type
prompt_integer min max ui = {ui | min = min, max = max, input = IntegerInput}
prompt_command : Int -> Int -> Type -> Type
prompt_command min max ui = {ui | min = min, max = max, input = CommandInput}
clear_prompt : Type -> Type
clear_prompt ui =
{ui |
min = -1,
min_float = -1.0,
max = -1,
max_float = -1.0,
input = NoInput,
displayed_choices = [],
field_content = ""
}
display_prompt_content : Type -> Type
display_prompt_content ui =
(display_text (Html.br [] [])
(display_text
(Html.text ("> " ++ ui.field_content))
(display_text (Html.br [] []) ui)
)
)
display_chosen_option_label : Int -> Type -> Type
display_chosen_option_label id ui =
case
(List.filter
(\(index, label) -> (index == id))
ui.displayed_choices
)
of
[] -> ui
((index, label) :: []) ->
(display_text (Html.br [] [])
(display_text
label
(display_text
(Html.text "> ")
(display_text (Html.br [] []) ui)
)
)
)
_ -> ui
clear_displayed_texts : Type -> Type
clear_displayed_texts ui = {ui | displayed_texts = []}
clear_displayed_errors : Type -> Type
clear_displayed_errors ui = {ui | displayed_errors = []}
clear_displayed_choices : Type -> Type
clear_displayed_choices ui = {ui | displayed_choices = []}
set_field_content : String -> Type -> Type
set_field_content value ui = {ui | field_content = value}
get_field_content : Type -> String
get_field_content ui = ui.field_content
|