Skip to content
Snippets Groups Projects
Commit ff14d685 authored by Bas Lijnse's avatar Bas Lijnse
Browse files

Completed a minimal viable version of the "Try iTasks application"

parent 29ca3293
No related branches found
No related tags found
No related merge requests found
module TryiTasks
import iTasks
import iTasks, Text
from StdFunc import o
/**
* This application let's you play with small iTask programs. It a sort of very minimal 'IDE'.
* You can choose example programs, modify them and build/run them
*/
startCode :== "start :: Task String\nstart = updateInformation () [] \"Hello World\"\n"
//Code examples: Should be read from
examples :==
[("Hello World",join "\n"
["main :: Task String"
,"main = viewInformation () [] \"Hello World\""
])
,("Sum",join "\n"
["main :: Task Int"
,"main = enterInformation \"Enter a number\" [] >>= \\num1 ->"
," enterInformation \"Enter a second number\" [] >>= \\num2 ->"
," viewInformation \"The sum is: \" [] (num1 + num2)"
])
]
startCode :== snd (hd (examples)) //Code of the first example
//Paths to the required Clean and iTasks tools for building
cpmBin :== "/Users/bas/Clean/bin/cpm"
tryiTasks :: Task ()
tryiTasks =
......@@ -13,10 +31,17 @@ tryiTasks =
\scode ->
(loadExample scode -&&- modifyCode scode) @ snd
) >^* [OnAction (Action "Build and Run" []) (hasValue buildAndRun)]
@! ()
@! ()
loadExample :: (Shared String) -> Task ()
loadExample scode = viewInformation "Load example" [] "Here you will be able to select an example code fragment and load it to the shared state" @! ()
/*
loadExample scode = (forever (
enterChoice "Load example" [ChooseWith (ChooseFromComboBox fst)] examples @ snd
>>* [OnAction (Action "Load" []) (hasValue (\example -> set example scode))]
) @! ()) <<@ ForceLayout
*/
loadExample scode = viewInformation "Load example" [] "Here should be the selection of examples but it messes up the buttons somehow :(" @! ()
modifyCode :: (Shared String) -> Task String
modifyCode scode = updateSharedInformation "Edit code" [UpdateWith toView fromView] scode
......@@ -31,13 +56,40 @@ buildAndRun fragment = withTemporaryDirectory
>>| createCleanProject buildDir
>>| buildCleanProject buildDir
>>| runExecutable buildDir
>>| return ()
>>* [OnAction ActionClose (always (return ()))]
where
createCleanModule fragment buildDir = viewInformation "Create module" [] "Here a clean module will be created from the fragment"
createCleanProject buildDir = viewInformation "Create project" [] "Here a Clean project will be created to build the module"
buildCleanProject buildDir = viewInformation "Build project" [] "Here the Clean project will be build to create the executable"
runExecutable buildDir = viewInformation "Run executable" [] "Here the generated executable will be run to test"
//Create a clean module from the fragment
createCleanModule fragment buildDir = exportTextFile (buildDir </> "test.icl") content
where
content = join "\n"
["module test"
,"import iTasks"
,fragment
,"Start w = startEngine main w"
]
//Create a Clean project build the module"
createCleanProject buildDir
= callProcess "Create project" [] cpmBin ["project","test","create"] (Just buildDir)
>>| setProjectOptions buildDir //Should be possible to do with command line options in cpm
where
setProjectOptions buildDir
= importTextFile projectFile
>>- \content -> exportTextFile projectFile (setOptions content)
where
projectFile = buildDir </> "test.prj"
setOptions s = ( replaceSubString "Target:\tStdEnv" "Target:\tiTasks"
o replaceSubString "HeapSize:\t2097152" "HeapSize:\t20971520") s
//Build the Clean project will be build to create the executable
buildCleanProject buildDir
= callProcess "Building project" [] cpmBin ["test.prj"] (Just buildDir)
//"Here the generated executable will be run to test"
runExecutable buildDir
= callProcess "Your code is running" [ViewWith toView] (buildDir </> "test.exe") ["-port","8088"] (Just buildDir)
where
toView _ = ATag [HrefAttr "http://localhost:8088/",TargetAttr "_blank"] [Text "View the code at: http://localhost:8088"]
Start w = startEngine tryiTasks w
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment