Skip to content

Commit

Permalink
HTerm support
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Sep 8, 2012
1 parent 8b4898a commit de40694
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 9 deletions.
4 changes: 3 additions & 1 deletion ghcjs.cabal
Expand Up @@ -11,6 +11,7 @@ Build-Type: Custom
Cabal-Version: >= 1.10 Cabal-Version: >= 1.10
data-dir: . data-dir: .
data-files: rts/*.js data-files: rts/*.js
rts/*.html


source-repository head source-repository head
type: git type: git
Expand All @@ -33,6 +34,7 @@ Library
containers, containers,
process, process,
ghcjs-closure, ghcjs-closure,
ghcjs-hterm,
monads-tf, monads-tf,
ghc-paths, ghc-paths,
source-map >= 0.1.0 && < 0.2, source-map >= 0.1.0 && < 0.2,
Expand Down Expand Up @@ -140,7 +142,7 @@ Executable ghcjs-boot
bytestring >= 0.9 && < 0.10, bytestring >= 0.9 && < 0.10,
system-filepath >= 0.4 && < 0.5, system-filepath >= 0.4 && < 0.5,
shelly >= 0.14 && < 0.15, shelly >= 0.14 && < 0.15,
http-conduit >= 1.5 && < 1.6, http-conduit >= 1.6 && < 1.7,
bzlib-conduit >= 0.2 && < 0.3, bzlib-conduit >= 0.2 && < 0.3,
conduit >= 0.5 && < 0.6, conduit >= 0.5 && < 0.6,
tar >= 0.4 && < 0.5 tar >= 0.4 && < 0.5
Expand Down
22 changes: 22 additions & 0 deletions rts/console.html
@@ -0,0 +1,22 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../closure-library/closure/goog/base.js"></script>
<script type="text/javascript">
goog.require('goog.math.Long');
goog.require('goog.math.Integer');
goog.require('goog.debug.Logger');
goog.require('goog.debug.Console');
</script>

<script type="text/javascript" src="../rts/rts-options.js"></script>
<script type="text/javascript" src="../rts/rts-common.js"></script>
<script type="text/javascript" src="../rts/rts-trampoline.js"></script>
<script type="text/javascript" src="hsloader.js"></script>
<script type="text/javascript" src="console.js"></script>
<title>Haskell Application</title>
</head>
<body>
</body>
</html>
9 changes: 9 additions & 0 deletions rts/console.js
@@ -0,0 +1,9 @@
window.onload = function(){
goog.debug.Console.autoInstall();
$hs_loadPath = "./";

// Must be called first
$hs_init();
$hs_consoleInitAndRunIO([$$$Main_main]);
}

61 changes: 61 additions & 0 deletions rts/hterm.html
@@ -0,0 +1,61 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../closure-library/closure/goog/base.js"></script>
<script type="text/javascript">
goog.require('goog.math.Long');
goog.require('goog.math.Integer');
goog.require('goog.debug.Logger');
goog.require('goog.debug.Console');
</script>

<script type="text/javascript" src='../hterm/js/lib.js'></script>
<script type="text/javascript" src='../hterm/js/lib_colors.js'></script>
<script type="text/javascript" src='../hterm/js/lib_f.js'></script>
<script type="text/javascript" src='../hterm/js/lib_fs.js'></script>
<script type="text/javascript" src='../hterm/js/lib_preference_manager.js'></script>
<script type="text/javascript" src='../hterm/js/lib_utf8.js'></script>

<script type="text/javascript" src='../hterm/js/hterm.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_frame.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_keyboard.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_keyboard_keymap.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_options.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_pubsub.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_screen.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_scrollport.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_terminal.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_terminal_io.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_text_attributes.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_vt.js'></script>
<script type="text/javascript" src='../hterm/js/hterm_vt_character_map.js'></script>

<script type="text/javascript" src="../rts/rts-options.js"></script>
<script type="text/javascript" src="../rts/rts-common.js"></script>
<script type="text/javascript" src="../rts/rts-trampoline.js"></script>
<script type="text/javascript" src="hsloader.js"></script>
<script type="text/javascript" src="hterm.js"></script>
<title>Haskell Application</title>
<style>
body {
position: absolute;
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}

#terminal {
display: block;
position: relative;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id='terminal'></div>
</body>
</html>
9 changes: 9 additions & 0 deletions rts/hterm.js
@@ -0,0 +1,9 @@
window.onload = function(){
goog.debug.Console.autoInstall();
$hs_loadPath = "./";

// Must be called first
$hs_init();
$hs_htermInitAndRunIO([$$$Main_main]);
}

29 changes: 29 additions & 0 deletions rts/index.html
@@ -0,0 +1,29 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="rts.js"></script>
<script type="text/javascript" src="main.js"></script>
<title>Haskell Application</title>
<style>
body {
position: absolute;
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}

#terminal {
display: block;
position: relative;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id='terminal'></div>
</body>
</html>
36 changes: 28 additions & 8 deletions src/Generator/Minify.hs
Expand Up @@ -11,14 +11,15 @@ import System.Process (system)
import System.Exit (ExitCode, ExitCode(..)) import System.Exit (ExitCode, ExitCode(..))


import Closure.Paths import Closure.Paths
import qualified Paths_ghcjs_hterm as HT (getDataFileName)
import Compiler.Variants import Compiler.Variants
import RTS.Dependencies import RTS.Dependencies
import System.Directory (setCurrentDirectory) import System.Directory (setCurrentDirectory, doesFileExist, copyFile)
import qualified Data.ByteString.Lazy as B (readFile, writeFile) import qualified Data.ByteString.Lazy as B (readFile, writeFile)
import Paths_ghcjs import Paths_ghcjs
import Data.SourceMap import Data.SourceMap
import Data.Attoparsec.ByteString.Lazy (many1, parse, Result(..)) import Data.Attoparsec.ByteString.Lazy (many1, parse, Result(..))
import Control.Monad (forM_) import Control.Monad (forM_, unless)
import Data.Aeson (json, fromJSON, Result(..), encode) import Data.Aeson (json, fromJSON, Result(..), encode)


data MinifyOptions = MinifyOptions { data MinifyOptions = MinifyOptions {
Expand All @@ -34,6 +35,26 @@ defaultMinify = MinifyOptions {


minify :: FilePath -> [FilePath] -> MinifyOptions -> [String] -> IO ExitCode minify :: FilePath -> [FilePath] -> MinifyOptions -> [String] -> IO ExitCode
minify jsexe mainFiles options args = do minify jsexe mainFiles options args = do
closurePath <- closureLibraryPath
htermPath <- HT.getDataFileName "js/"
rtsPath <- getDataFileName "rts/"

let copyIfNotThere f = do
exists <- doesFileExist (jsexe </> f)
unless exists $ copyFile (rtsPath </> f) (jsexe </> f)

copyIfNotThere "hterm.html"
copyIfNotThere "hterm.js"

copyIfNotThere "console.html"
copyIfNotThere "console.js"

copyIfNotThere "index.html"

let mainFiles' = case mainFiles of
[] -> [jsexe </> "hterm.js"]
_ -> mainFiles

firstLine <- head . lines <$> (readFile $ jsexe </> "hsloader.js") firstLine <- head . lines <$> (readFile $ jsexe </> "hsloader.js")
let bundleCount = case stripPrefix "// Bundle Count " firstLine of let bundleCount = case stripPrefix "// Bundle Count " firstLine of
Just n -> read n Just n -> read n
Expand All @@ -54,20 +75,19 @@ minify jsexe mainFiles options args = do
mod "rts" "" (length deps + 1) ++ mod "rts" "" (length deps + 1) ++
bundleMods bundleCount ++ bundleMods bundleCount ++
js (jsexe </> "hsloader.js") ++ js (jsexe </> "hsloader.js") ++
jss mainFiles ++ jss mainFiles' ++
mod "main" "rts" (length mainFiles + 1) ++ mod "main" "rts" (length mainFiles' + 1) ++
[ "--module_output_path_prefix", jsexe ++ "/" [ "--module_output_path_prefix", jsexe ++ "/"
, "--compilation_level", "ADVANCED_OPTIMIZATIONS" , "--compilation_level", "ADVANCED_OPTIMIZATIONS"
, "--create_source_map", jsexe </> "hsmin.js.allmaps" , "--create_source_map", jsexe </> "hsmin.js.allmaps"
, "--source_map_format", "V3" , "--source_map_format", "V3"
] ++ args ] ++ args


-- Make paths in the source map relative and split it up -- Make paths in the source map relative and split it up
closurePath <- closureLibraryPath
rtsPath <- getDataFileName "rts/"
let fixMap sm@SourceMap{sources = s} = sm {sources = map fixPath s} let fixMap sm@SourceMap{sources = s} = sm {sources = map fixPath s}
fixPath = replacePrefix closurePath ("../closure-library"</>) fixPath = replacePrefix closurePath ("../closure-library"</>)
. replacePrefix rtsPath ("../rts"</>) . replacePrefix htermPath ("../hterm/js"</>)
. replacePrefix rtsPath ("../rts"</>)
. replacePrefix (jsexe++"/") id . replacePrefix (jsexe++"/") id
replacePrefix a with p = maybe p with (stripPrefix a p) replacePrefix a with p = maybe p with (stripPrefix a p)
case ec of case ec of
Expand Down
29 changes: 29 additions & 0 deletions src/RTS/Dependencies.hs
Expand Up @@ -8,13 +8,16 @@ import System.FilePath ((</>))
import Compiler.Variants import Compiler.Variants
import Closure.Paths import Closure.Paths
import Paths_ghcjs import Paths_ghcjs
import qualified Paths_ghcjs_hterm as HT (getDataFileName)


-- | the absolute filepaths of the dependencies for the RTS -- | the absolute filepaths of the dependencies for the RTS
rtsDeps :: Variant -> IO [FilePath] rtsDeps :: Variant -> IO [FilePath]
rtsDeps v = do rtsDeps v = do
rtsPath <- getDataFileName "rts" rtsPath <- getDataFileName "rts"
closurePath <- closureLibraryPath closurePath <- closureLibraryPath
htermPath <- HT.getDataFileName "js"
return $ map (closurePath </>) closureDeps return $ map (closurePath </>) closureDeps
++ map (htermPath </>) htermDeps
++ map (rtsPath </>) (rtsSrcs v) ++ map (rtsPath </>) (rtsSrcs v)


-- | the file that defines the default options for the RTS -- | the file that defines the default options for the RTS
Expand Down Expand Up @@ -53,3 +56,29 @@ closureDeps =
, "closure/goog/crypt/hash.js" , "closure/goog/crypt/hash.js"
, "closure/goog/crypt/md5.js" , "closure/goog/crypt/md5.js"
] ]

htermDeps :: [FilePath]
htermDeps =
[ "lib.js"
, "lib_f.js"
, "lib_colors.js"
, "lib_fs.js"
, "lib_message_manager.js"
, "lib_preference_manager.js"
, "lib_test_manager.js"
, "lib_utf8.js"
, "hterm_frame.js"
, "hterm.js"
, "hterm_keyboard.js"
, "hterm_keyboard_keymap.js"
, "hterm_mock_row_provider.js"
, "hterm_options.js"
, "hterm_pubsub.js"
, "hterm_screen.js"
, "hterm_scrollport.js"
, "hterm_terminal_io.js"
, "hterm_terminal.js"
, "hterm_text_attributes.js"
, "hterm_vt_character_map.js"
, "hterm_vt.js"
]

0 comments on commit de40694

Please sign in to comment.