[GB.TERM.FORM]

* BUG: Optimize a lot rendering by using String stream and limiting calls to attr class.
* BUG: Use term.makeraw function.


git-svn-id: svn://localhost/gambas/trunk@8083 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Fabien Bodard 2017-02-03 22:43:12 +00:00
parent fa2b72cf76
commit bb294b9830
6 changed files with 157 additions and 174 deletions

View file

@ -76,73 +76,6 @@ Fill
C
i
5
#Attr
C
Modified
r
b
ColorMode
p
i
Foreground
p
i
Background
p
i
Bold
p
b
Dim
p
b
Underline
p
b
Reverse
p
b
Blink
p
b
_new
m
Send
m
_GetString
m
s
[(Force)b]
FillFrom
m
(iAttr)i
Reset
m
IsVoid
m
b
GetInteger
m
i
#Border
C

View file

@ -1,6 +1,5 @@
Align!
Arrange!
Attr!
Border!
Char!
Desktop!

View file

@ -1,6 +1,8 @@
# Gambas Project File 3.0
# Compiled with Gambas 3.9.90
Startup=trfTest
UseTerminal=1
RedirectStderr=1
Version=3.9.90
VersionFile=1
Component=gb.image

View file

@ -1,19 +1,16 @@
' Gambas class file
Export
Private CSI As String = Chr(27) & "["
Private Const CSI As String = "\e["
Property Read Modified As Boolean
Property ColorMode As Integer
Property ColorMode As Integer
Property Foreground As Integer
Property Background As Integer
Property Background As Integer
Property Bold As Boolean
Property Dim As Boolean
Property Underline As Boolean
Property Reverse As Boolean
Property Blink As Boolean
Property Dim As Boolean
Property Underline As Boolean
Property Reverse As Boolean
Property Blink As Boolean
Private Enum FLAG_BG, FLAG_FG, FLAG_BOLD, FLAG_DIM, FLAG_REV, FLAG_UND, FLAG_BLK
'Private Enum FLAG_BOLD, FLAG_DIM, FLAG_UND, FLAG_REV, FLAG_BLK, FLAG_FG, FLAG_BG
@ -29,16 +26,12 @@ Private $bReverse As Boolean
Private $bUnderline As Boolean
Private $bBlink As Boolean
Public Sub _new()
$iForeground = TermColor.Black
$iBackGround = TermColor.White
End
End
Private Function Modified_Read() As Boolean
@ -50,8 +43,6 @@ Private Function Modified_Read() As Boolean
End
Private Function Foreground_Read() As Integer
Return $iForeground
@ -75,6 +66,7 @@ Private Sub Background_Write(Value As Integer)
If $iBackGround <> Value Then $aModified[FLAG_BG] = True
$iBackGround = Value
End
Private Function Bold_Read() As Boolean
@ -85,7 +77,7 @@ End
Private Sub Bold_Write(Value As Boolean)
If $bBold <> Value Then
If $bBold <> Value Then
$aModified[FLAG_BOLD] = True
Endif
$bBold = Value
@ -144,9 +136,6 @@ Private Sub Blink_Write(Value As Boolean)
End
Private Function ColorMode_Read() As Integer
Return $iColorMode
@ -163,75 +152,131 @@ End
Public Sub Send()
Print Me._GetString();
End
Public Function _GetString(Optional Force As Boolean) As String
Dim sValue As String
Dim sValue As String
If $aModified[FLAG_BOLD] Then sValue &= IIf($bBold, "1;", "22;")
If $aModified[FLAG_DIM] Then sValue &= IIf($bDim, "8;", "28;")
If $aModified[FLAG_BLK] Then sValue &= IIf($bBlink, "5;", "25;")
If $aModified[FLAG_UND] Then sValue &= IIf($bUnderline, "4;", "24;")
If $aModified[FLAG_REV] Then sValue &= IIf($bReverse, "7;", "27;")
If $aModified[FLAG_FG] Or Force Then
Select Case $iColorMode
Case TermColor.Default
sValue &= (30 + Max(Min($iForeground, 8), 0)) & ";"
Case TermColor.Mode256
sValue &= "38;5;" & Max(Min($iForeground, 255), 0) & ";"
sValue &= "38;5;" & Max(Min($iForeground, 255), 0) & ";"
Case TermColor.ModeRGB
sValue &= "38;2;" & Subst("&1;&2;&3;", GetRed($iForeGround), GetGreen($iForeground), GetBlue($iForeground))
End Select
Endif
If $aModified[FLAG_BG] Or Force Then
Select Case $iColorMode
Case TermColor.Default
sValue &= (40 + Max(Min($iBackGround, 8), 0)) & ";"
Case TermColor.Mode256
sValue &= "48;5;" & Max(Min($iBackGround, 255), 0) & ";"
sValue &= "48;5;" & Max(Min($iBackGround, 255), 0) & ";"
Case TermColor.ModeRGB
sValue &= "48;2;" & Subst("&1;&2;&3;", GetRed($iBackGround), GetGreen($iBackGround), GetBlue($iBackGround))
End Select
Endif
If Not sValue Then Return
If sValue Ends ";" Then sValue = Left(sValue, -1)
sValue = CSI & sValue & "m"
$aModified = New Boolean[8]
'Debug sValue
Return sValue
End
Public Function WriteToStream(hStream As Stream)
Dim bFirst As Boolean
Dim iFlag As Integer
For iFlag = 0 To 6
If $aModified[iFlag] Then
If Not bFirst Then
Write #hStream, CSI
bFirst = True
Else
Write #hStream, ";"
Endif
Select Case iFlag
Case FLAG_BOLD
Write #hStream, IIf($bBold, "1", "22")
Case FLAG_DIM
Write #hStream, IIf($bDim, "8", "28")
Case FLAG_BLK
Write #hStream, IIf($bBlink, "5", "25")
Case FLAG_UND
Write #hStream, IIf($bUnderline, "4", "24")
Case FLAG_REV
Write #hStream, IIf($bReverse, "7", "27")
Case FLAG_FG
Select Case $iColorMode
Case TermColor.Default
Write #hStream, Str((30 + Max(Min($iForeground, 8), 0)))
Case TermColor.Mode256
Write #hStream, ("38;5;" & Max(Min($iForeground, 255), 0))
Case TermColor.ModeRGB
Write #hStream, ("38;2;" & Subst("&1;&2;&3", GetRed($iForeGround), GetGreen($iForeground), GetBlue($iForeground)))
End Select
Case FLAG_BG
Select Case $iColorMode
Case TermColor.Default
Write #hStream, Str((40 + Max(Min($iBackGround, 8), 0)))
Case TermColor.Mode256
Write #hStream, ("48;5;" & Max(Min($iBackGround, 255), 0))
Case TermColor.ModeRGB
Write #hStream, ("48;2;" & Subst("&1;&2;&3", GetRed($iBackGround), GetGreen($iBackGround), GetBlue($iBackGround)))
End Select
End Select
Endif
Next
If bFirst Then
Write #hStream, "m"
Endif
$aModified = New Boolean[8]
End
Private Function GetRed(iValue As Integer) As Integer
Return Lsr(iValue, 16) And 255
End
Private Function GetGreen(iValue As Integer) As Integer
Return Lsr(iValue, 8) And 255
End
Private Function GetBlue(iValue As Integer) As Integer
Return iValue And 255
End
Return iValue And 255
End
Public Sub FillFrom(iAttr As Integer)
@ -246,18 +291,17 @@ Public Sub FillFrom(iAttr As Integer)
Else
Me.Foreground = 0
Endif
Me.Bold = BTst(iAttr, FLAG_BOLD)
Me.Dim = BTst(iAttr, FLAG_DIM)
Me.Reverse = BTst(iAttr, FLAG_REV)
Me.Underline = BTst(iAttr, FLAG_UND)
Me.Blink = BTst(iAttr, FLAG_BLK)
End
Public Sub Reset()
$iForeground = -1
$iBackGround = -1
$bBold = False
@ -267,33 +311,31 @@ Public Sub Reset()
$bBlink = False
$aModified = New Boolean[8]
Print CSI & "0m";
End
Public Sub IsVoid() As Boolean
If $iForeground >= 0 Then Return
If $iBackground >= 0 Then Return
If $bBold Or If $bDim Or If $bUnderline Or If $bReverse Or If $bBlink Then Return
Return True
End
Public Function GetInteger() As Integer
Dim iAttr As Integer
Dim iAttr As Integer
If Me.Background <> -1 Then iAttr = BSet(iAttr, FLAG_BG) + Lsl(Me.Background And 255, 16)
If Me.Foreground <> -1 Then iAttr = BSet(iAttr, FLAG_FG) + Lsl(Me.Foreground And 255, 24)
If Me.Bold Then iAttr = BSet(iAttr, FLAG_BOLD)
If Me.Dim Then iAttr = BSet(iAttr, FLAG_DIM)
If Me.Reverse Then iAttr = BSet(iAttr, FLAG_REV)
If Me.Underline Then iAttr = BSet(iAttr, FLAG_UND)
If Me.Blink Then iAttr = BSet(iAttr, FLAG_BLK)
Return iAttr
End
Return iAttr
End

View file

@ -17,6 +17,7 @@ Static Private $bInRender As Boolean
Static Private $hCurControl As TermControl
Static Private $iActiveWindow As Integer
Static Public bLock As Boolean
Static Private $hStream As File
Static Public Sub _init()
@ -27,15 +28,15 @@ Static Public Sub _init()
hRect = New Rect(0, 0, 3, 3)
$hFile = Open File.In.Term.Name For Read Watch
obs = New Observer(File.In) As "Terminal"
hSetting = File.In.Term.GetAttr()
hSetting.ICANON = False
hSetting.ECHO = False
'hSetting.ICANON = False
'hSetting.ECHO = False
hSetting.MakeRaw
File.In.Term.SetAttr(Term.TCSANOW, hSetting)
'saveSetting(hSetting)
Print "\e[?1002h\e[?1006h\e[?1049h\e[?25l\e[?2h";
Print "\e[8;30;200";
ResizeScreen(File.Out.Term.Width, File.Out.Term.Height)
@ -137,44 +138,44 @@ Static Private Sub RefreshChild(hChild As Object, hRect As Rect)
RefreshChild(hObj, rectUpdate)
Next
Endif
End
' Static Private Sub RefreshChild(hChild As Object, hRect As Rect)
'
'
' Dim iLeft, iRight, iTop, iBottom As Integer
'
'
' Dim L As Integer
' Dim C As Integer
' Dim hObj As Object
' Dim rectUpdate As Rect
' Dim iMove, iResize As Integer
' 'If hChild Is Window Then Stop
'
'
' rectUpdate = hRect.Intersection(hChild._GetScreenRect())
' If hChild.Visible = False Then Return
' If Not rectUpdate Then Return
'
'
' For L = rectUpdate.Top To rectUpdate.Bottom - 1
' For C = rectUpdate.Left To rectUpdate.Right - 1
' $aScreen[l, C] = hChild.Id
' Next
' Next
'
'
'
'
' If hChild Is TermContainer Then
' imove = If(hChild.Border > 0, 1, 0) + hChild.Padding
' iResize = iMove * 2 + If(hChild._Shadow, 1, 0)
' rectUpdate.Move(rectUpdate.Left + iMove, rectUpdate.Top + imove, rectUpdate.Width - iResize, rectUpdate.Height - iResize)
' For Each hObj In hChild.Children
'
'
' RefreshChild(hObj, rectUpdate)
' Next
'
'
' Endif
'
'
' End
Static Public Sub Terminal_Resize()
@ -270,6 +271,7 @@ Static Public Sub File_Read()
Endif
i = 10
ipos2 = 10
If String.InStr(S, "B") Then Stop
For Each ss In ["~", "A", "B", "C", "D", "H", "F", "P", "Q", "R", "S", "M", "Z"]
i = InStr(s, ss, ipos)
If i = 0 Then Continue
@ -435,7 +437,7 @@ Static Public Sub File_Read()
Key._SetKey(ss, Key.Return, bAlt, bControl, bShift)
Case "\t"
Key._SetKey(ss, Key.Tab, bAlt, bControl, bShift)
Case Chr(8)
Case Chr(8), Chr(127)
Key._SetKey(ss, Key.BackSpace, bAlt, bControl, bShift)
Case Else
Key._SetKey(ss, 0, bAlt, bControl, bShift)
@ -484,7 +486,7 @@ Static Private Sub RaiseMouseEvent(hControl As TermControl, sEvent As String, Co
End
Static Private Sub RaiseKeyEvent()
Select Case Key.Code
Case Key.Menu
If Key.Alt Then
@ -557,66 +559,70 @@ Static Public Sub _Render()
Dim sAttr As String
Dim sDisplay As String
Dim hOldCont As Object
Dim iOldAttr As Integer
If bLock Then Stop
If $bInRender Then Return
$hStream = Open String For Write
$bInRender = True
DoRefreshArea()
RenderAll
If Not IsNull($RectRenderArea) Then hRect = $hRect.Intersection($RectRenderArea)
If hRect = Null Then
$bInRender = False
Return
Endif
sAttr = hAttr._GetString(True)
Print sAttr;
Write #$hStream, sAttr
For l = hRect.Y To hRect.Bottom - 1
'Debug "ligne " & l
sDisplay &= "\e[" & (l + 1) & ";" & (hRect.X + 1) & "H"
'If l = 9 Then Stop
Write #$hStream, "\e[" & (l + 1) & ";" & (hRect.X + 1) & "H"
iOldAttr = 0
For c = hRect.X To hRect.Right - 1
' hAttr.Background = $aScreen[l, c]
' hAttr.Send
hCont = TermControl._IdToControl[$aScreen[l, c]]
If hOldCont <> hCont Then
If hCont Then
If hOldCont <> hCont Then
hAttr.Reset
hAttr.ColorMode = hCont._ColorMode
Endif
hOldCont = hCont
'If hCont Is TermLabel Then Stop
'If $aScreen[l, c] = 3 And If l > 2 Then Stop
If hCont Then
hChar = hCont._GetChar(c, l)
hAttr.FillFrom(hChar.Attr)
hAttr.ColorMode = hCont._ColorMode
'Debug hAttr.Foreground
sAttr = hAttr._GetString()
sDisplay &= sAttr
sDisplay &= String.Chr(hChar.c)
'sDisplay &= Str($aScreen[l, c])
' If Str($aScreen[l, c]) = "37" Then
' Debug Str($aScreen[l, c]), l
' Endif
If hChar.Attr <> iOldAttr Then
hAttr.FillFrom(hChar.Attr)
hAttr.WriteToStream($hStream)
'sAttr = hAttr._GetString()
iOldAttr = hChar.Attr
Endif
'Write #$hStream, sAttr
Write #$hStream, String.Chr(hChar.c)
Else
hAttr.FillFrom(Desktop.BackGround.Attr)
'hAttr.Background = 240
sAttr = hAttr._GetString()
sDisplay &= sAttr
sDisplay &= String.Chr(Desktop.BackGround.c)
'sAttr = hAttr._GetString()
'Write #$hStream, sAttr
hAttr.WriteToStream($hStream)
Write #$hStream, String.Chr(Desktop.BackGround.c)
Endif
Next
Next
sDisplay = Close #$hStream
Print sDisplay;
Flush
' If Me.Debug = True Then
' Debug Replace(sDisplay, "\e", "&")
' Endif
$RectRenderArea = Null
'Catch
$bInRender = False
End
Static Private Sub RenderAll()

View file

@ -30,7 +30,7 @@ Public Sub _New()
hText = New TermTextBox(hBox) As "TextBox"
hText.Text = "test"
hText.Expand = True
hText.SetFocus
hbox = New TermHBox(Me)
hlab = New TermLabel(hbox)
@ -47,6 +47,7 @@ Public Sub _New()
$hlab2.Background = TermColor.green
$hlab2.Show
End