diff --git a/comp/src/gb.highlight/.src/Main.module b/comp/src/gb.highlight/.src/Main.module index f1541c5c3..a9c83cf72 100644 --- a/comp/src/gb.highlight/.src/Main.module +++ b/comp/src/gb.highlight/.src/Main.module @@ -13,12 +13,14 @@ Public Sub Main() TextHighlighter.CanRewrite = True 'TextHighlighter["gambas"].Run(" \"CTRL+A\": \"SelectAll\",\n", aState) 'File.Save("~/test.html", TextHighlighter["html"].ToHTML(File.Load("test/page.html"))) - File.Save("~/test.html", TextHighlighter["c"].ToHTML(File.Load("~/gambas/main/share/gambas.h"))) + 'File.Save("~/test.html", TextHighlighter["c"].ToHTML(File.Load("~/gambas/main/share/gambas.h"))) 'File.Save("~/test.html", TextHighlighter["diff"].ToHTML(File.Load(Application.Path &/ ".hidden/test/diff.txt"))) 'TextHighlighter.Register("~/gambas/git/master/app/src/gambas3/highlight/conflict.highlight") 'File.Save("~/test.html", TextHighlighter["conflict"].ToHTML(File.Load("test/conflict.txt"))) - File.Save("~/test.html", TextHighlighter["javascript"].ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js"))) + 'File.Save("~/test.html", TextHighlighter["javascript"].ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js"))) 'File.Save("~/test.html", TextHighlighter["webpage"].ToHTML(File.Load(Application.Path &/ ".hidden/test/Webpage1.webpage"))) 'File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/acinclude.m4"))) + + Print TextHighlighter["javascript"].ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js")) End diff --git a/comp/src/gb.highlight/.src/TextHighlighter.class b/comp/src/gb.highlight/.src/TextHighlighter.class index 9f6115752..8c8177493 100644 --- a/comp/src/gb.highlight/.src/TextHighlighter.class +++ b/comp/src/gb.highlight/.src/TextHighlighter.class @@ -444,8 +444,6 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str sLineHtml = "" - If Y And If Me.Limit Then sLineHtml &= "
" - While Not HighlightToken() sHtml = Replace(Html($sToken), " ", " ") @@ -460,7 +458,6 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str sStyle = "" If $iLevel Then sStyle &= "background-color:" & Color.ToHTML($iBackground) & ";" - 'If bAlt Then sStyle &= "background:#" & Hex$(aStyles[GetAlternate()].Color, 6) & ";" If $hStyle.Color Then sStyle &= "color:" & Color.ToHTML($hStyle.Color) & ";" If $hStyle.Dotted Then sStyle &= "text-decoration:underline dotted;" @@ -476,7 +473,7 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str sLineHtml &= Html($sToken) - ' If TextHighlighter.Limit Then + ' If Me.Limit Then ' If Y And If Not Trim(aResult[aResult.Max]) Then ' aResult.Add("
") ' Else @@ -492,7 +489,7 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str End -Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Variant, Optional Pos As Integer) +Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As TextHighlighterTheme, Optional Pos As Integer) Dim aText As String[] Dim P As Integer @@ -519,8 +516,6 @@ Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Varia For iLine = 0 To aText.Max HighlightLine(aText[iLine]) - 'If Y = 0 Then TextHighlighter.Limit = False - 'If Me.TextAfter Then sLine = TextHighlighter.TextAfter Do @@ -569,3 +564,71 @@ Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Varia Next End + +Static Private Sub ColorToConsole(iColor As Integer) As String + + With Color[iColor] + Return .Red & ";" & .Green & ";" & .Blue + End With + +End + +Public Sub ToANSI(Text As String, Optional Theme As TextHighlighterTheme) As String + + Dim aResult As New String[] + Dim Y As Integer + Dim sANSI As String + Dim aText As String[] + Dim sLineANSI As String + Dim iColor As Integer + Dim iBackground As Integer + + iColor = Color.Default + iBackground = Color.Default + + HighlightStart(Theme) + + aText = Split(Text, "\n") + For Y = 0 To aText.Max + + HighlightLine(aText[Y]) + + sLineANSI = "" + + 'If Limit And If Y And If Me.Limit Then aResult.Add(String(80, "─") & "\r\n") + + While Not HighlightToken() + + sANSI = $sToken + + If $hStyle.Bold Then sANSI = "\e[1m" & sANSI & "\e[21m\e[22m" ' "\e[21m" some terminal don't regognize this + If $hStyle.Underline Then sANSI = "\e[4m" & sANSI & "\e[24m" + ' TODO: Implement strikeout + + If $iBackground <> iBackground Then + iBackground = $iBackground + If iBackground = Color.Default Then + sANSI = "\e[49m" & sANSI + Else + sANSI = "\e[48;2;" & ColorToConsole(iBackground) & "m" & sANSI + Endif + Endif + + If $hStyle.Color <> iColor Then + iColor = $hStyle.Color + sANSI = "\e[38;2;" & ColorToConsole(iColor) & "m" & sANSI + Endif + + sLineANSI &= sANSI + + Wend + + aResult.Add(sLineANSI & "\r\n") + + Next + + aResult.Add("\e[0m") + Return aResult.Join("") + + End + diff --git a/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class b/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class index afa8682c9..158010454 100644 --- a/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class +++ b/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class @@ -40,25 +40,25 @@ Private Sub Keywords_Read() As String[] End -Private Sub IsProc() As Boolean - - Dim aSym As String[] - Dim I As Integer - Dim sSym As String - - aSym = Highlight.Symbols - - For I = 0 To aSym.Max - sSym = aSym[I] - If sSym == "PRIVATE" Or If sSym == "PUBLIC" Or If sSym == "STATIC" Or If sSym == "FAST" Then Continue - If sSym == "SUB" Or If sSym == "PROCEDURE" Or If sSym == "FUNCTION" Then - Return True - Else - Return False - Endif - Next - -End +' Private Sub IsProc() As Boolean +' +' Dim aSym As String[] +' Dim I As Integer +' Dim sSym As String +' +' aSym = Highlight.Symbols +' +' For I = 0 To aSym.Max +' sSym = aSym[I] +' If sSym == "PRIVATE" Or If sSym == "PUBLIC" Or If sSym == "STATIC" Or If sSym == "FAST" Then Continue +' If sSym == "SUB" Or If sSym == "PROCEDURE" Or If sSym == "FUNCTION" Then +' Return True +' Else +' Return False +' Endif +' Next +' +' End Public Sub _Analyze(Text As String, (State) As Byte[], Optional (MatchLimit) As Boolean, Limit As String, ByRef Pos As Integer) As Byte[] diff --git a/comp/src/gb.highlight/highlight/javascript.highlight b/comp/src/gb.highlight/highlight/javascript.highlight index a0ce6f0d5..ff9a83bcd 100644 --- a/comp/src/gb.highlight/highlight/javascript.highlight +++ b/comp/src/gb.highlight/highlight/javascript.highlight @@ -27,7 +27,7 @@ regexp{Datatype}: regexp.escape{Escape}: match /\\./ number: - match /[+-]?[0-9.]+([Ee][+-]?[0-9]+)?/ + match /[+-]?[0-9]*(\.[0-9]+)?([Ee][+-]?[0-9]+)?/ match /0x[0-9a-fA-F]*/ keyword: keyword @javascript.keyword diff --git a/comp/src/gb.highlight/highlight/sql.highlight b/comp/src/gb.highlight/highlight/sql.highlight index 6ff80dbe0..1326fd902 100644 --- a/comp/src/gb.highlight/highlight/sql.highlight +++ b/comp/src/gb.highlight/highlight/sql.highlight @@ -14,8 +14,8 @@ string: match /\\u[0-9a-fA-F]{4}/ match /\\u{[0-9a-fA-F]+}/ number: - match /[+-]?[0-9.]+([Ee][+-]?[0-9]+)?/ - #match 0x[0-9a-fA-F]* + match /[+-]?[0-9]*(\.[0-9]+)?([Ee][+-]?[0-9]+)?/ + #match /0x[0-9a-fA-F]*/ operator.between{Operator}: match /(?i:(NOT)?\sBETWEEN\s(SYMMETRIC)?)/ operator.like{Operator}: diff --git a/comp/src/gb.highlight/highlight/webpage_javascript.highlight b/comp/src/gb.highlight/highlight/webpage_javascript.highlight index bae0001ff..be0010dc1 100644 --- a/comp/src/gb.highlight/highlight/webpage_javascript.highlight +++ b/comp/src/gb.highlight/highlight/webpage_javascript.highlight @@ -30,7 +30,7 @@ regexp{Datatype}: regexp.escape{Escape}: match /\\./ number: - match /[+-]?[0-9.]+/ + match /[+-]?[0-9]*(\.[0-9]+)?([Ee][+-]?[0-9]+)?/ match /0x[0-9a-fA-F]*/ keyword: keyword @javascript.keyword