@@ -682,7 +682,11 @@ function SourceInfo(body) {
682
682
683
683
if ( body . script ) {
684
684
if ( body . script . name ) {
685
- result += ', ' + body . script . name ;
685
+ var name = body . script . name ;
686
+
687
+ // TODO Change path to relative, if possible
688
+
689
+ result += ', ' + name ;
686
690
} else {
687
691
result += ', [unnamed]' ;
688
692
}
@@ -718,7 +722,8 @@ function Interface() {
718
722
var proto = Interface . prototype ,
719
723
ignored = [ 'pause' , 'resume' , 'exitRepl' , 'handleBreak' ,
720
724
'requireConnection' , 'killChild' , 'trySpawn' ,
721
- 'controlEval' , 'debugEval' , 'print' , 'childPrint' ] ,
725
+ 'controlEval' , 'debugEval' , 'print' , 'childPrint' ,
726
+ 'clearline' ] ,
722
727
shortcut = {
723
728
'run' : 'r' ,
724
729
'cont' : 'c' ,
@@ -762,7 +767,16 @@ function Interface() {
762
767
this . breakpoints = [ ] ;
763
768
764
769
// Run script automatically
765
- this . run ( ) ;
770
+ this . clearline ( ) ;
771
+ this . pause ( ) ;
772
+
773
+ // XXX Need to figure out why we need this delay
774
+ setTimeout ( function ( ) {
775
+
776
+ self . run ( function ( ) {
777
+ self . resume ( ) ;
778
+ } ) ;
779
+ } , 10 ) ;
766
780
} ;
767
781
768
782
@@ -790,15 +804,24 @@ Interface.prototype.resume = function(silent) {
790
804
} ;
791
805
792
806
793
- // Print text to output stream
794
- Interface . prototype . print = function ( text ) {
795
- if ( this . killed ) return ;
807
+ // Clear current line
808
+ Interface . prototype . clearline = function ( ) {
796
809
if ( process . stdout . isTTY ) {
797
810
process . stdout . cursorTo ( 0 ) ;
798
811
process . stdout . clearLine ( 1 ) ;
799
812
}
813
+ } ;
814
+
815
+ // Print text to output stream
816
+ Interface . prototype . print = function ( text , oneline ) {
817
+ if ( this . killed ) return ;
818
+ this . clearline ( ) ;
819
+
800
820
process . stdout . write ( typeof text === 'string' ? text : util . inspect ( text ) ) ;
801
- process . stdout . write ( '\n' ) ;
821
+
822
+ if ( oneline !== true ) {
823
+ process . stdout . write ( '\n' ) ;
824
+ }
802
825
} ;
803
826
804
827
// Format and print text from child process
@@ -956,10 +979,13 @@ Interface.prototype.help = function() {
956
979
957
980
// Run script
958
981
Interface . prototype . run = function ( ) {
982
+ var callback = arguments [ 0 ] ;
983
+
959
984
if ( this . child ) {
960
985
this . error ( 'App is already running... Try `restart` instead' ) ;
986
+ callback && callback ( true ) ;
961
987
} else {
962
- this . trySpawn ( ) ;
988
+ this . trySpawn ( callback ) ;
963
989
}
964
990
} ;
965
991
@@ -1015,22 +1041,28 @@ Interface.prototype.list = function() {
1015
1041
var lineno = res . fromLine + i + 1 ;
1016
1042
if ( lineno < from || lineno > to ) continue ;
1017
1043
1044
+ var current = lineno == 1 + client . currentSourceLine ,
1045
+ breakpoint = client . breakpoints . some ( function ( bp ) {
1046
+ return bp . script === client . currentScript &&
1047
+ bp . line == lineno ;
1048
+ } ) ;
1049
+
1018
1050
if ( lineno == 1 ) {
1019
1051
// The first line needs to have the module wrapper filtered out of
1020
1052
// it.
1021
1053
var wrapper = require ( 'module' ) . wrapper [ 0 ] ;
1022
1054
lines [ i ] = lines [ i ] . slice ( wrapper . length ) ;
1055
+
1056
+ client . currentSourceColumn -= wrapper . length ;
1023
1057
}
1024
1058
1025
- var current = lineno == 1 + client . currentSourceLine ,
1026
- breakpoint = client . breakpoints . some ( function ( bp ) {
1027
- return bp . script === client . currentScript &&
1028
- bp . line == lineno ;
1029
- } ) ,
1030
- line = current ?
1031
- SourceUnderline ( lines [ i ] , client . currentSourceColumn )
1032
- :
1033
- lines [ i ] ;
1059
+ // Highlight executing statement
1060
+ var line ;
1061
+ if ( current ) {
1062
+ line = SourceUnderline ( lines [ i ] , client . currentSourceColumn )
1063
+ } else {
1064
+ line = lines [ i ] ;
1065
+ }
1034
1066
1035
1067
self . print ( leftPad ( lineno , breakpoint && '*' ) + ' ' + line ) ;
1036
1068
}
@@ -1412,7 +1444,7 @@ Interface.prototype.trySpawn = function(cb) {
1412
1444
}
1413
1445
1414
1446
setTimeout ( function ( ) {
1415
- process . stdout . write ( 'connecting..' ) ;
1447
+ self . print ( 'connecting..' , true ) ;
1416
1448
attemptConnect ( ) ;
1417
1449
} , 50 ) ;
1418
1450
} ;
0 commit comments