Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Menu
Projects
Groups
Snippets
Sign up now
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ryan Frazier
elm-calculator
Compare Revisions
v0.6...v0.7
Commits (1)
Allow overwrite of old value
· 37cc4046
Ryan Frazier
authored
Oct 08, 2019
Add dirty state to operator input Show empty stack cells
37cc4046
Hide whitespace changes
Inline
Side-by-side
src/Main.elm
View file @
37cc4046
...
...
@@ -14,6 +14,7 @@ type alias Model =
{
stack
:
List
Float
,
currentNum
:
String
,
error
:
Maybe
String
,
dirty
:
Bool
}
...
...
@@ -22,6 +23,7 @@ initialModel =
{
stack
=
[]
,
currentNum
=
"
0"
,
error
=
Nothing
,
dirty
=
False
}
...
...
@@ -103,7 +105,7 @@ update msg model =
initialModel
Clear
->
{
model
|
currentNum
=
"
0"
}
{
model
|
currentNum
=
"
0"
,
dirty
=
False
}
Back
->
let
...
...
@@ -129,7 +131,7 @@ update msg model =
{
model
|
error
=
Just
"
PARSE ERR"
}
Just
num
->
{
model
|
stack
=
num
::
model
.
stack
,
currentNum
=
"
0"
}
{
model
|
stack
=
num
::
model
.
stack
,
dirty
=
True
}
InputOperator
operator
->
case
model
.
stack
of
...
...
@@ -156,12 +158,16 @@ update msg model =
{
model
|
stack
=
xs
,
currentNum
=
String
.
fromFloat
newNum
,
dirty
=
True
}
InputNumber
num
->
if
model
.
currentNum
==
"
0"
then
{
model
|
currentNum
=
String
.
fromFloat
num
}
else
if
model
.
dirty
then
{
model
|
currentNum
=
String
.
fromFloat
num
,
dirty
=
False
}
else
{
model
|
currentNum
=
model
.
currentNum
++
String
.
fromFloat
num
}
...
...
@@ -241,7 +247,16 @@ section =
,
cell
(
onClick
<|
InputNumber
0
)
Single
White
"
0"
,
cell
(
onClick
SetDecimal
)
Single
White
"
."
,
cell
(
onClick
SetSign
)
Single
White
"
+/-"
,
cell
(
onClick
<|
Enter
)
Single
Yellow
"
Enter"
,
cell
(
onClick
<|
Enter
)
Single
Yellow
"
↵"
]
emptyBox
:
Html
Msg
emptyBox
=
div
[
class
"
input-box"
]
[
span
[
class
"
empty"
]
[
text
"
empty"
]
]
...
...
@@ -269,7 +284,8 @@ view model =
[
h1
[
class
"
h1"
]
[
text
"
RPN Calculator"
]
,
div
[
class
"
calculator"
]
(
List
.
map
stackBox
(
List
.
reverse
model
.
stack
)
(
List
.
repeat
(
3
-
List
.
length
model
.
stack
)
emptyBox
++
List
.
map
stackBox
(
List
.
reverse
<|
List
.
take
3
model
.
stack
)
++
[
inputBox
<|
case
model
.
error
of
Nothing
->
...
...
@@ -280,7 +296,8 @@ view model =
,
section
]
)
,
div
[]
[
text
<|
Debug
.
toString
model
]
-- , div [] [ text <| Debug.toString model ]
]
...
...
style.css
View file @
37cc4046
...
...
@@ -26,6 +26,10 @@ body {
margin
:
auto
;
}
.empty
{
opacity
:
0
;
}
.input-box
{
text-align
:
right
;
padding
:
12px
;
...
...