fixed :info, closes #119

This commit is contained in:
Andrew Gibiansky 2014-01-08 23:28:03 -05:00
parent f7410e6dbe
commit 63ef0a8da6
2 changed files with 29 additions and 22 deletions

View File

@ -126,9 +126,7 @@ var concealExtension = (function() {
/**
* Activate conceal in CodeMirror options, don't overwrite other settings
*/
function concealCell(cell) {
var editor = cell.code_mirror;
function concealCell(editor) {
// Initialize all tokens. Just look at the token at every character.
editor.eachLine(function (handle) {
var l = editor.getLineNumber(handle);
@ -152,7 +150,8 @@ var concealExtension = (function() {
createCell = function (event,nbcell,nbindex) {
var cell = nbcell.cell;
if ((cell instanceof IPython.CodeCell)) {
concealCell(cell)
var editor = cell.code_mirror;
concealCell(editor)
}
};
@ -164,12 +163,15 @@ var concealExtension = (function() {
for(var i in cells){
var cell = cells[i];
if ((cell instanceof IPython.CodeCell)) {
concealCell(cell);
var editor = cell.code_mirror;
concealCell(editor);
}
}
$([IPython.events]).on('create.Cell',createCell);
}
IPython.concealCell = concealCell;
require([], initExtension);
})();

View File

@ -277,18 +277,18 @@ safely state = ghandle handler . ghandle sourceErrorHandler
evalPager = ""
}
doc :: GhcMonad m => SDoc -> m String
doc sdoc = do
flags <- getSessionDynFlags
let cols = pprCols flags
d = runSDoc sdoc (initSDocContext flags defaultUserStyle)
return $ Pretty.fullRender Pretty.PageMode cols 1.5 string_txt "" d
where
string_txt :: Pretty.TextDetails -> String -> String
string_txt (Pretty.Chr c) s = c:s
string_txt (Pretty.Str s1) s2 = s1 ++ s2
string_txt (Pretty.PStr s1) s2 = unpackFS s1 ++ s2
string_txt (Pretty.LStr s1 _) s2 = unpackLitString s1 ++ s2
doc :: GhcMonad m => SDoc -> m String
doc sdoc = do
flags <- getSessionDynFlags
let cols = pprCols flags
d = runSDoc sdoc (initSDocContext flags defaultUserStyle)
return $ Pretty.fullRender Pretty.PageMode cols 1.5 string_txt "" d
where
string_txt :: Pretty.TextDetails -> String -> String
string_txt (Pretty.Chr c) s = c:s
string_txt (Pretty.Str s1) s2 = s1 ++ s2
string_txt (Pretty.PStr s1) s2 = unpackFS s1 ++ s2
string_txt (Pretty.LStr s1 _) s2 = unpackLitString s1 ++ s2
wrapExecution :: KernelState
@ -571,18 +571,23 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do
if fixity == GHC.defaultFixity
then empty
else ppr fixity <+> pprInfixName (getName thing)
outs = map printInfo filteredOutput
-- Print nicely.
unqual <- getPrintUnqual
flags <- getSessionDynFlags
let strings = map (showSDocForUser flags unqual) outs
strings <- mapM (doc . printInfo) filteredOutput
let output = case getFrontend state of
IPythonConsole -> unlines strings
IPythonNotebook -> unlines (map htmlify strings)
htmlify str =
printf "<div style='background: rgb(247, 247, 247);'><form><textarea id='code'>%s</textarea></form></div>" str
++ script
script =
"<script>CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'haskell', readOnly: 'nocursor'});</script>"
return EvalOut {
evalStatus = Success,
evalResult = [],
evalState = state,
evalPager = unlines strings
evalPager = output
}
evalCommand _ (Directive SearchHoogle query) state = safely state $ do