Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows compatibility #47

Merged
merged 4 commits into from
Feb 19, 2018
Merged

Conversation

puhlenbruck
Copy link
Contributor

Crazies like me like to work on windows sometimes. This pr introduces a few changes to help improve the windows compatibility.

  • Added a powershell install script and windows install instruction to README

  • Replaced unicode chatacter → in prompt as it causes problems in
    standard windows terminals

  • created putStrFlush to be used instead of T.putStr, ensure content is
    flushed to the console and prompts are displayed in the correct order

  • replaced use of "rm" with System.Directory removeFile. Wrapped in a
    function deleteFile to continue on error

  • modify setScriptCommand to do nothing on windows systems


These changes should provide a basic level of support for windows platforms. There are still some outstanding issues which are not addressed by this change:

  • The build script feature still only produces a bash script. It could potentially produce a powershell script as well for windows.

  • The default background for the powershell console is blue, the prompt arrow colour is also blue here making it a bit hard to read, perhaps the colour scheme could be adjusted.

  • The tool still relies on curl to be installed for some functions. Systems are not guaranteed to have this installed (this potentially affects linux systems as well). For now I've added it to the prerequisite listing in the README.md, but maybe this download function could be done from the haskell code without requiring an external tool.

- Replaced unicode chatacter → in prompt as it causes problems in
standard windows terminals

- created putStrFlush to be used instead of T.putStr, ensure content is
flushed to the console and prompts are displayed in the correct order

- replaced use of "rm" with System.Directory removeFile.  Wrapped in a
function deleteFile to continue on error

- modify setScriptCommand to do nothing on windows systems
@vrom911
Copy link
Member

vrom911 commented Feb 5, 2018

Wow! @puhlenbruck thanks for contributing to hs-init 🎉
I haven't looked through the code yet, but I hope to do it as soon as possible.. Anyway, the idea is great, I would like to see this support in the project!

@puhlenbruck
Copy link
Contributor Author

@vrom911 Thanks! Please do let me know if there are any suggestions or changes you would like to see before merging.

Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! That's really cool work done here! Sorry I couldn't test it with windows, but I'm sure you did it 🙂 Still I checked it on my machine and everything seems good!
That's a pity that unicode symbols cause fails on windows, but there is nothing that can be done with that.. I am thinking to improve --help section as it uses a looot of unicode symbols.
Also thanks for another thoughts you added, I will create few issues on that to think about more about. Though there is already one about the colors : #28 . When it implemented it will help a lot, but anyway I will add comment there.
Again, thanks a lot for your time!

hs-init.hs Outdated

deleteFile :: FilePath -> IO ()
deleteFile file = catch (removeFile file) printError
where printError (e :: SomeException) = errorMessage $ "Could not delete file `" <> T.pack file <> "'. " <> T.pack (displayException e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that back-ticks are mismatching in here.

hs-init.hs Outdated
@@ -442,14 +448,14 @@ reset = setSGR [Reset]
prompt :: IO Text
prompt = do
setColor Blue
T.putStr " "
putStrFlush " -> "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask you to make here 2 spaces before the arrow, I think it adds a little bit more readability 🙂

hs-init.hs Outdated
fromString cmd args = callProcess cmd (map T.unpack args)

deleteFile :: FilePath -> IO ()
deleteFile file = catch (removeFile file) printError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution! Great! I think we can continue and this trash file that didn't removed is not the reason to stop the process

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there is confusion, this function does allow the process to continue simply printing a message if the delete fails, but not stopping the process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly what is needed! 👍

hs-init.hs Outdated
@@ -430,6 +431,11 @@ falseMessage target = False <$ warningMessage (T.toTitle target <> " won't be ad
-- Ansi-terminal
----------------------------------------------------------------------------

putStrFlush :: Text -> IO()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to add space before (

@@ -508,7 +514,11 @@ customizeLicense l t nm year
-- This is needed to be able to call commands by writing strings.
instance (a ~ Text, b ~ ()) => IsString ([a] -> IO b) where
fromString "cd" [arg] = setCurrentDirectory $ T.unpack arg
fromString cmd args = callCommand $ showCommandForUser cmd (map T.unpack args)
fromString cmd args = callProcess cmd (map T.unpack args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify the reason for changing callCommand showCommandForUser with callProcess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite the docs claiming otherwise, showCommandForUser doesn't actually produce a string that works on windows. The problem seems similar to haskell/process#51

@chshersh
Copy link
Contributor

chshersh commented Feb 7, 2018

@puhlenbruck Regarding other issues you shared:

The build script feature still only produces a bash script.

Well, I guess we don't need to create b script for GHC-8.2.2+, because script doesn't work for this GHC. And this version of GHC already has coloring and can strip folders from output. See relevant issue #27.

@chshersh
Copy link
Contributor

chshersh commented Feb 7, 2018

Ahh, also about this PR: I think you should also add information to changelog regarding your changes 👍 Because your changes are great 🙂

@puhlenbruck
Copy link
Contributor Author

Thank you for the feedback, I'll look to make these changes.

@vrom911 Yes it's unfortunate about unicode. There seem to be some potential solutions I might look into in the future but for now I'm working as if it's not possible. With this PR I'm just looking to get to a minimal working state. Not too concerned with the help page yet, it still works and shows the important information, just the graphics are a bit mangled.

@chshersh If b script is going the way of the dodo then I guess that's a non-issue.

Corrected typos

Added CHANGELOG.md entry

install.ps1 now checks to see if the install directory is already on the path before adding it

added explicit flush to ansi-terminal reset

added comment string on new functions.
hs-init.hs Outdated
fromString cmd args = callProcess cmd (map T.unpack args)

deleteFile :: FilePath -> IO ()
deleteFile file = catch (removeFile file) printError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly what is needed! 👍

@vrom911 vrom911 merged commit 529e47e into kowainik:master Feb 19, 2018
@vrom911
Copy link
Member

vrom911 commented Feb 19, 2018

@puhlenbruck Thanks again for your wonderful contribution! This makes me so happy that hs-init becomes better! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants