|
@@ -2,12 +2,25 @@
|
|
|
Namespace ted2go
|
|
|
|
|
|
|
|
|
-#if __TARGET__<>"emscripten"
|
|
|
-
|
|
|
#rem monkeydoc The Console class.
|
|
|
#end
|
|
|
Class ConsoleExt Extends TextView
|
|
|
-
|
|
|
+
|
|
|
+ Struct StdoutResult
|
|
|
+
|
|
|
+ Field stdout:String
|
|
|
+ Field error:ErrorInfo
|
|
|
+
|
|
|
+ Method New( stdout:String,error:ErrorInfo )
|
|
|
+
|
|
|
+ Self.stdout=stdout
|
|
|
+ Self.error=error
|
|
|
+ End
|
|
|
+
|
|
|
+ End
|
|
|
+
|
|
|
+ Field RequestJumpToFile:Void( path:String,line:Int )
|
|
|
+
|
|
|
#rem monkeydoc Invoked when the console finishes executing a process.
|
|
|
#end
|
|
|
Field Finished:Void( exitCode:Int )
|
|
@@ -64,7 +77,8 @@ Class ConsoleExt Extends TextView
|
|
|
|
|
|
Repeat
|
|
|
|
|
|
- Local stdout:=ReadStdout()
|
|
|
+ Local result:=ReadStdoutWithErrors()
|
|
|
+ Local stdout:=result.stdout
|
|
|
If Not stdout Exit
|
|
|
|
|
|
Write( stdout )
|
|
@@ -93,10 +107,6 @@ Class ConsoleExt Extends TextView
|
|
|
|
|
|
Local stdout:=process.ReadStdout()
|
|
|
|
|
|
-' Print "**** CONSOLE STDOUT *****"
|
|
|
-' Print stdout
|
|
|
-' Print "***** END STDOUT *****"
|
|
|
-
|
|
|
If Not stdout
|
|
|
If _stdout _stdoutBuf.Add( _stdout )
|
|
|
_stdoutOpen=False
|
|
@@ -132,6 +142,8 @@ Class ConsoleExt Extends TextView
|
|
|
_stdout=""
|
|
|
_stdoutBuf.Clear()
|
|
|
_stdoutWaiting=Null
|
|
|
+ _errors.Clear()
|
|
|
+ _linesRead=0
|
|
|
|
|
|
Return True
|
|
|
End
|
|
@@ -161,7 +173,33 @@ Class ConsoleExt Extends TextView
|
|
|
_stdoutWaiting=Null
|
|
|
Wend
|
|
|
|
|
|
- Return _stdoutBuf.RemoveFirst()
|
|
|
+ Local out:=_stdoutBuf.RemoveFirst()
|
|
|
+ _linesRead+=1
|
|
|
+ Return out
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ReadStdoutWithErrors:StdoutResult()
|
|
|
+
|
|
|
+ While _stdoutBuf.Empty
|
|
|
+
|
|
|
+ If Not _stdoutOpen
|
|
|
+ If _procOpen
|
|
|
+ _stdoutWaiting=New Future<Bool>
|
|
|
+ _stdoutWaiting.Get()
|
|
|
+ _stdoutWaiting=Null
|
|
|
+ Endif
|
|
|
+ Return New StdoutResult( "",Null )
|
|
|
+ Endif
|
|
|
+
|
|
|
+ _stdoutWaiting=New Future<Bool>
|
|
|
+ _stdoutWaiting.Get()
|
|
|
+ _stdoutWaiting=Null
|
|
|
+ Wend
|
|
|
+
|
|
|
+ Local out:=_stdoutBuf.RemoveFirst()
|
|
|
+ Local err:=ProcessErrors( out )
|
|
|
+ _linesRead+=1
|
|
|
+ Return New StdoutResult( out,err )
|
|
|
End
|
|
|
|
|
|
#rem monkeydoc Writes to process stdin.
|
|
@@ -244,17 +282,62 @@ Class ConsoleExt Extends TextView
|
|
|
'Super.OnKeyEvent( event )
|
|
|
End
|
|
|
|
|
|
-' Method OnContentMouseEvent( event:MouseEvent ) Override
|
|
|
-'
|
|
|
-' 'select whole line by double click
|
|
|
-' If event.Type = EventType.MouseDoubleClick
|
|
|
-' Local line:=Document.FindLine( Cursor )
|
|
|
-' SelectText( Document.StartOfLine( line ),Document.EndOfLine( line ) )
|
|
|
-' Return
|
|
|
-' Endif
|
|
|
-'
|
|
|
-' Super.OnContentMouseEvent( event )
|
|
|
-' End
|
|
|
+ Method OnContentMouseEvent( event:MouseEvent ) Override
|
|
|
+
|
|
|
+ Select event.Type
|
|
|
+
|
|
|
+ Case EventType.MouseClick
|
|
|
+
|
|
|
+ If Not _errors.Empty
|
|
|
+ Local err:=ErrorAt( CharAtPoint( event.Location ) )
|
|
|
+ If err
|
|
|
+ RequestJumpToFile( err.path,err.line )
|
|
|
+ Return
|
|
|
+ Endif
|
|
|
+ Endif
|
|
|
+
|
|
|
+ Case EventType.MouseMove
|
|
|
+
|
|
|
+ If Not _errors.Empty
|
|
|
+ Local err:=ErrorAt( CharAtPoint( event.Location ) )
|
|
|
+ Mouse.Cursor=err ? MouseCursor.Hand Else MouseCursor.IBeam
|
|
|
+ Endif
|
|
|
+
|
|
|
+ Case EventType.MouseEnter
|
|
|
+
|
|
|
+ Mouse.Cursor=MouseCursor.IBeam
|
|
|
+
|
|
|
+ Case EventType.MouseLeave
|
|
|
+
|
|
|
+ Mouse.Cursor=MouseCursor.Arrow
|
|
|
+
|
|
|
+ End
|
|
|
+
|
|
|
+ Super.OnContentMouseEvent( event )
|
|
|
+
|
|
|
+ End
|
|
|
+
|
|
|
+ Method OnRenderLine( canvas:Canvas,line:Int ) Override
|
|
|
+
|
|
|
+ Super.OnRenderLine( canvas,line )
|
|
|
+
|
|
|
+ If _errors.Empty Return
|
|
|
+
|
|
|
+ Local err:=_errors[line]
|
|
|
+ If Not err Return
|
|
|
+
|
|
|
+ Local text:=Document.Text
|
|
|
+
|
|
|
+ For Local word:=Eachin WordIterator.ForLine( Self,line )
|
|
|
+
|
|
|
+ If err.CheckRange( word.Index )
|
|
|
+ Local txt:=text.Slice( word.Index,word.Index+word.Length )
|
|
|
+ Local rect:=word.Rect
|
|
|
+ Local w:=RenderStyle.Font.TextWidth( txt )
|
|
|
+ canvas.DrawLine( rect.Left,rect.Bottom,rect.Left+w,rect.Bottom )
|
|
|
+ Endif
|
|
|
+ Next
|
|
|
+ End
|
|
|
|
|
|
|
|
|
Private
|
|
@@ -272,6 +355,9 @@ Class ConsoleExt Extends TextView
|
|
|
Field _stdoutBuf:=New StringList
|
|
|
Field _stdoutWaiting:Future<Bool>
|
|
|
|
|
|
+ Field _errors:=New IntMap<ErrorInfo>
|
|
|
+ Field _linesRead:Int
|
|
|
+
|
|
|
Method UpdateRunning()
|
|
|
|
|
|
If Not _running Or _procOpen Or _stdoutOpen Return
|
|
@@ -300,6 +386,61 @@ Class ConsoleExt Extends TextView
|
|
|
Endif
|
|
|
End
|
|
|
|
|
|
+ Method ProcessErrors:ErrorInfo( stdout:String )
|
|
|
+
|
|
|
+ Local i:=stdout.Find( "] : Error : " )
|
|
|
+ If i<>-1
|
|
|
+ Local j:=stdout.Find( " [" )
|
|
|
+ If j<>-1
|
|
|
+ Local path:=stdout.Slice( 0,j )
|
|
|
+ Local line:=Int( stdout.Slice( j+2,i ) )-1
|
|
|
+ Local msg:=stdout.Slice( i+12 )
|
|
|
+ Local range:=New Vec2i( j+2+Text.Length,i+Text.Length )
|
|
|
+
|
|
|
+ Local error:=New ErrorInfo( path,line,msg,range )
|
|
|
+ _errors[_linesRead]=error
|
|
|
+
|
|
|
+ Return error
|
|
|
+ Endif
|
|
|
+ Endif
|
|
|
+
|
|
|
+ Return Null
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ErrorAt:ErrorInfo( charPosition:Int )
|
|
|
+
|
|
|
+ Local line:=Document.FindLine( charPosition )
|
|
|
+ Local err:=_errors[line]
|
|
|
+ If err And charPosition>=err.clickRange.x And charPosition<=err.clickRange.y
|
|
|
+ Return err
|
|
|
+ Endif
|
|
|
+
|
|
|
+ Return Null
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
-#Endif
|
|
|
+
|
|
|
+Private
|
|
|
+
|
|
|
+Struct ErrorInfo
|
|
|
+
|
|
|
+ Field path:String
|
|
|
+ Field line:Int
|
|
|
+ Field message:String
|
|
|
+ Field clickRange:Vec2i
|
|
|
+
|
|
|
+ Method New( path:String,line:Int,msg:String,clickRange:Vec2i )
|
|
|
+
|
|
|
+ Self.path=path
|
|
|
+ Self.line=line
|
|
|
+ Self.message=msg
|
|
|
+ Self.clickRange=clickRange
|
|
|
+ End
|
|
|
+
|
|
|
+ Method CheckRange:Bool( pos:Int )
|
|
|
+
|
|
|
+ Return pos>=clickRange.x And pos<clickRange.y
|
|
|
+ End
|
|
|
+
|
|
|
+End
|