[GB.FORM.TERMINAL]
* NEW: Support for XTERM "set window title" sequence. * NEW: Rename "Underline" attribute as "Underscore". * NEW: Support for "set attribute" escape sequences. * BUG: TerminalView: Fix selection behaviour. git-svn-id: svn://localhost/gambas/trunk@7668 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
0e52f6d63b
commit
159f039e02
5 changed files with 105 additions and 30 deletions
|
@ -18,7 +18,7 @@ Public Sub GetAttr(hAttr As TerminalAttr, X As Integer)
|
|||
hAttr.Bright = iAttr And &H200
|
||||
hAttr.Dim = iAttr And &H400
|
||||
hAttr.Reverse = iAttr And &H800
|
||||
hAttr.Underline = iAttr And &H1000
|
||||
hAttr.Underscore = iAttr And &H1000
|
||||
hAttr.Blink = iAttr And &H2000
|
||||
|
||||
End
|
||||
|
@ -32,7 +32,7 @@ Public Sub SetAttr(hAttr As TerminalAttr, X As Integer, Optional L As Integer =
|
|||
If hAttr.Bright Then iAttr += &H200
|
||||
If hAttr.Dim Then iAttr += &H400
|
||||
If hAttr.Reverse Then iAttr += &H800
|
||||
If hAttr.Underline Then iAttr += &H1000
|
||||
If hAttr.Underscore Then iAttr += &H1000
|
||||
If hAttr.Blink Then iAttr += &H2000
|
||||
|
||||
If iAttr = 0 And X + L >= Attr.Count Then
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
Public Sub TextBox1_Activate()
|
||||
|
||||
TerminalView1.Exec(Split(TextBox1.Text, " ", Chr$(34)))
|
||||
Try TerminalView1.Exec(Split(TextBox1.Text, " ", Chr$(34)))
|
||||
If Error Then Debug Error.Text
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Public Background As Integer = -1
|
|||
Public Bold As Boolean
|
||||
Public Bright As Boolean
|
||||
Public Dim As Boolean
|
||||
Public Underline As Boolean
|
||||
Public Underscore As Boolean
|
||||
Public Reverse As Boolean
|
||||
Public Blink As Boolean
|
||||
|
||||
|
@ -18,7 +18,7 @@ Public Sub Reset()
|
|||
Bold = False
|
||||
Bright = False
|
||||
{Dim} = False
|
||||
Underline = False
|
||||
Underscore = False
|
||||
Reverse = False
|
||||
Blink = False
|
||||
|
||||
|
|
|
@ -6,11 +6,14 @@ Private $sLeft As String
|
|||
Private $X As Integer
|
||||
Private $Y As Integer
|
||||
|
||||
Private Enum MODE_NORMAL, MODE_TITLE
|
||||
|
||||
Public Sub OutputTo(hView As TerminalView, sData As String)
|
||||
|
||||
Dim iPos As Integer
|
||||
Dim iPos2 As Integer
|
||||
Dim iCode As Integer
|
||||
Dim iMode As Integer
|
||||
|
||||
If $sLeft Then sData = $sLeft & sData
|
||||
|
||||
|
@ -18,6 +21,18 @@ Public Sub OutputTo(hView As TerminalView, sData As String)
|
|||
|
||||
Inc iPos
|
||||
|
||||
If iMode = MODE_TITLE Then
|
||||
iPos2 = InStr(sData, Chr$(7), iPos)
|
||||
If iPos2 = 0 Then
|
||||
$sLeft = Mid$(sData, iPos)
|
||||
Return
|
||||
Endif
|
||||
Debug Mid$(sData, iPos, iPos2 - iPos)
|
||||
iMode = MODE_NORMAL
|
||||
iPos = iPos2
|
||||
Continue
|
||||
Endif
|
||||
|
||||
iPos2 = InStr(sData, Chr$(27), iPos)
|
||||
If iPos2 = 0 Then
|
||||
hView.Print(Mid$(sData, iPos))
|
||||
|
@ -46,7 +61,7 @@ Public Sub OutputTo(hView As TerminalView, sData As String)
|
|||
|
||||
Loop
|
||||
|
||||
Escape(hView, Mid$(sData, iPos2 + 1, iPos - iPos2))
|
||||
iMode = Escape(hView, sData, iPos2 + 1, iPos - iPos2)
|
||||
|
||||
Loop
|
||||
|
||||
|
@ -54,11 +69,17 @@ End
|
|||
|
||||
' Escape sequence without the initial 27 character.
|
||||
|
||||
Private Sub Escape(hView As TerminalView, sStr As String)
|
||||
Private Sub Escape(hView As TerminalView, sData As String, iPos As Integer, iLen As Integer) As Integer
|
||||
|
||||
Dim Y As Integer
|
||||
Dim X As Integer
|
||||
Dim aArg As String[]
|
||||
Dim sArg As String
|
||||
Dim iArg As Integer
|
||||
Dim sStr As String
|
||||
Dim iMode As Integer
|
||||
|
||||
sStr = Mid$(sData, iPos, iLen)
|
||||
|
||||
Select Case Left(sStr)
|
||||
|
||||
|
@ -71,6 +92,10 @@ Private Sub Escape(hView As TerminalView, sStr As String)
|
|||
|
||||
hView.CursorGoto($X, $Y)
|
||||
|
||||
Case "]"
|
||||
|
||||
iMode = MODE_TITLE
|
||||
|
||||
Case "["
|
||||
|
||||
Select Case Right(sStr)
|
||||
|
@ -89,6 +114,46 @@ Private Sub Escape(hView As TerminalView, sStr As String)
|
|||
|
||||
hView.EraseEndOfLine
|
||||
|
||||
Case "m" ' Set attribute
|
||||
|
||||
GoSub GET_ARGS
|
||||
For Each sArg In aArg
|
||||
|
||||
Try iArg = CInt(sArg)
|
||||
If Error Then Continue
|
||||
|
||||
Select Case iArg
|
||||
|
||||
Case 0
|
||||
hView.Attr.Reset()
|
||||
Case 1
|
||||
hView.Attr.Bright = True
|
||||
Case 2
|
||||
hView.Attr.Dim = True
|
||||
Case 4
|
||||
hView.Attr.Underline = True
|
||||
Case 7
|
||||
hView.Attr.Reverse = True
|
||||
Case 21
|
||||
hView.Attr.Bright = False
|
||||
Case 22
|
||||
hView.Attr.Dim = False
|
||||
Case 24
|
||||
hView.Attr.Underline = False
|
||||
Case 27
|
||||
hView.Attr.Reverse = False
|
||||
Case 30 To 37
|
||||
hView.Attr.Background = iArg - 30
|
||||
Case 39
|
||||
hView.Attr.Background = -1
|
||||
Case 40 To 47
|
||||
hView.Attr.Foreground = iArg - 30
|
||||
Case 49
|
||||
hView.Attr.Foreground = -1
|
||||
|
||||
End Select
|
||||
Next
|
||||
|
||||
Case "s" ' Save cursor
|
||||
|
||||
$X = hView.Column
|
||||
|
@ -102,7 +167,7 @@ Private Sub Escape(hView As TerminalView, sStr As String)
|
|||
|
||||
End Select
|
||||
|
||||
Return
|
||||
Return iMode
|
||||
|
||||
GET_ARGS:
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ DRAW_TEXT:
|
|||
Paint.DrawText(sText, X + 1, Y + $iAscent)
|
||||
If hAttr.Bold Then Paint.DrawText(sText, X + 2, Y + $iAscent)
|
||||
Endif
|
||||
If hAttr.Underline Then Paint.FillRect(X, Y + $LH - 1, iLen * $CW, 1, Paint.Background)
|
||||
If hAttr.Underscore Then Paint.FillRect(X, Y + $LH - 1, iLen * $CW, 1, Paint.Background)
|
||||
X += iLen * $CW
|
||||
P = I
|
||||
Return
|
||||
|
@ -391,6 +391,7 @@ Public Sub Print(sText As String)
|
|||
If iLen >= Len(sText) Then Break
|
||||
iCode = Asc(sText, iLen + 1)
|
||||
Select Case iCode
|
||||
Case 7
|
||||
Case 8
|
||||
If $X Then
|
||||
Dec $X
|
||||
|
@ -475,10 +476,17 @@ Private Function Attr_Read() As TerminalAttr
|
|||
|
||||
End
|
||||
|
||||
Public Sub EnsureVisible()
|
||||
Private Sub EnsureVisibleAt(X As Integer, Y As Integer)
|
||||
|
||||
GetLine($Y)
|
||||
$hView.EnsureVisible($X * $CW, $Y * $LH, $CW, $LH)
|
||||
GetLine(Y)
|
||||
$hView.EnsureVisible(X * $CW, Y * $LH, $CW, $LH)
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub EnsureVisible()
|
||||
|
||||
EnsureVisibleAt($X, $Y)
|
||||
|
||||
End
|
||||
|
||||
|
@ -495,7 +503,7 @@ Private Sub Foreground_Write(Value As Integer)
|
|||
|
||||
End
|
||||
|
||||
Private Sub GotoMouse()
|
||||
Private Sub GotoMouse(bStart As Boolean)
|
||||
|
||||
Dim X As Integer
|
||||
Dim Y As Integer
|
||||
|
@ -503,20 +511,26 @@ Private Sub GotoMouse()
|
|||
X = (Mouse.ScreenX - $hView.ScreenX) \ $CW
|
||||
Y = (Mouse.ScreenY - $hView.ScreenY + $hView.ScrollY) \ $LH
|
||||
|
||||
Goto(Max(0, Min($W - 1, X)), Max(0, Min(Max($aLine.Max, $hView.ClientH \ $LH - 1), Y)))
|
||||
EnsureVisible
|
||||
X = Max(0, Min($W - 1, X))
|
||||
Y = Max(0, Min(Max($aLine.Max, $hView.ClientH \ $LH - 1), Y))
|
||||
|
||||
If bStart Then
|
||||
$X1 = X
|
||||
$Y1 = Y
|
||||
Endif
|
||||
$X2 = X
|
||||
$Y2 = Y
|
||||
|
||||
Refresh
|
||||
|
||||
EnsureVisibleAt(X, Y)
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_MouseDown()
|
||||
|
||||
$bMouseDown = True
|
||||
GotoMouse
|
||||
$X1 = $X
|
||||
$Y1 = $Y
|
||||
$X2 = $X
|
||||
$Y2 = $Y
|
||||
|
||||
GotoMouse(True)
|
||||
$hMouseTimer = New Timer(50) As "MouseTimer"
|
||||
|
||||
End
|
||||
|
@ -524,9 +538,7 @@ End
|
|||
Public Sub View_MouseMove()
|
||||
|
||||
If $bMouseDown Then
|
||||
GotoMouse
|
||||
$X2 = $X
|
||||
$Y2 = $Y
|
||||
GotoMouse(False)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
@ -605,10 +617,7 @@ End
|
|||
|
||||
Public Sub MouseTimer_Timer()
|
||||
|
||||
GotoMouse
|
||||
$X2 = $X
|
||||
$Y2 = $Y
|
||||
EnsureVisible
|
||||
GotoMouse(False)
|
||||
|
||||
End
|
||||
|
||||
|
@ -766,7 +775,7 @@ Public Sub Exec(aCommand As String[]) As Process
|
|||
|
||||
If $hProcess Then Return
|
||||
|
||||
$hProcess = Exec aCommand For Input Output As "Process"
|
||||
$hProcess = Exec aCommand With ["TERM=xterm"] For Input Output As "Process"
|
||||
|
||||
End
|
||||
|
||||
|
@ -774,7 +783,7 @@ Public Sub Shell(sCommand As String) As Process
|
|||
|
||||
If $hProcess Then Return
|
||||
|
||||
$hProcess = Shell sCommand For Input Output As "Process"
|
||||
$hProcess = Shell sCommand With ["TERM=xterm"] For Input Output As "Process"
|
||||
|
||||
End
|
||||
|
||||
|
|
Loading…
Reference in a new issue