Skip to content

Commit

Permalink
Merge pull request #99 from mdibaiee/trailing-character
Browse files Browse the repository at this point in the history
(80) fix: use System.FilePath's functions to take filename and dirname
  • Loading branch information
NickSeagull authored Jun 17, 2017
2 parents 28c1527 + c044ed0 commit 6d7f7fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
20 changes: 6 additions & 14 deletions src/common/HaskellDo/Compilation/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import qualified System.Process as System
import qualified System.Exit as System
import qualified Data.Text as Text
import System.Directory
import System.FilePath ((</>), takeDirectory, takeFileName, dropTrailingPathSeparator)

import Transient.Move

Expand All @@ -32,7 +33,7 @@ initialState = State
{ compiledOutput = ""
, compilationError = "No project has been loaded yet, try opening one?"
, projectPath = ""
, workingFile = "/src/Main.hs"
, workingFile = "src/Main.hs"
}

lastProjectFile :: FilePath
Expand All @@ -51,7 +52,7 @@ update Compile state = do

writeWorkingFile :: String -> State -> IO ()
writeWorkingFile content state = do
let fullPath = projectPath state ++ workingFile state
let fullPath = projectPath state </> workingFile state
fileExists <- doesFileExist fullPath
when fileExists (writeCode fullPath content)

Expand Down Expand Up @@ -108,23 +109,14 @@ preprocessOutput out =

makeNewProject :: String -> IO ()
makeNewProject path = do
let projectName = dirname path
let parentDir = parent path
let p = dropTrailingPathSeparator path
let projectName = takeFileName p
let parentDir = takeDirectory p
putStrLn path
putStrLn projectName
putStrLn parentDir
_ <- runCommand ("new " ++ projectName ++ " " ++ templateURL) parentDir
return ()
where
dirname p = init p
|> reverse
|> takeWhile (/= '/')
|> reverse
parent p = init p
|> reverse
|> dropWhile (/= '/')
|> tail
|> reverse

runCommand :: String -> FilePath -> IO (System.ExitCode, String, String)
runCommand command projPath = do
Expand Down
2 changes: 1 addition & 1 deletion src/common/HaskellDo/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ update (ToolbarAction Toolbar.LoadProject) appState = do
let filePath = Compilation.workingFile (compilationState appState)
atRemote $ localIO $
when (Toolbar.createProject tbState) (Compilation.makeNewProject projectPath)
readAtRemote (projectPath ++ filePath) >>= \case
readAtRemote (projectPath </> filePath) >>= \case
Left _ -> do
let newTbState = tbState { Toolbar.projectOpened = False }
let newCmpState = cmpState
Expand Down

0 comments on commit 6d7f7fc

Please sign in to comment.