Search the Community
Showing results for tags 'Tail'.
-
Hi all, I'm trying to make an AutoIt version of BareTail to monitor my logs in real-time, but I can't quite get it working properly. I want to be able to go into the hilight menu, select a string and color and have the lines that have that string show with the color I chose. For some reason, all my hilights are gone after the first scroll through. I don't know why. It also takes a while to display all the hilights. What am I missing? Is there a better/faster way to accomplish this? I'm using Randallcs wonderful APITailRW.au3 for this, which I've attached. Thanks for the help! #include "C:Documents and SettingstestuserDesktopBaretailAPITailRW.au3" #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiRichEdit.au3> #include <ScrollBarConstants.au3> #include <Array.au3> #include <GuiButton.au3> #include <GuiImageList.au3> #include <GuiComboBoxEx.au3> #include <Misc.au3> OnAutoItExitRegister("_Exit") $copyLog = "Testlog2.txt" $var1 = 0 $var2 = 0 Global $sTailReg = "HKCUSoftwareOptumAutoTail" Global $iSelectFlag = False Global $sFile = "" Global $aRestore[100][4] GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Create image lists for the buttons $hImage1 = _GUIImageList_Create(16, 16, 5, 3, 6) _GUIImageList_AddIcon($hImage1, "C:Documents and SettingsjdubarMy DocumentsScriptsWonderTool_Iconsfolder_open.ico") $hImage2 = _GUIImageList_Create(16, 16, 5, 3, 6) _GUIImageList_AddIcon($hImage2, "C:Documents and SettingsjdubarMy DocumentsScripts_AllIconssrchui_23.ico") $Form1 = GUICreate("Advanced Log Viewer", 500, 500, -1, -1) $hOpen = GUICtrlCreateButton("Open", 0, 0, 70, 20) _GUICtrlButton_SetImageList($hOpen, $hImage1) $hHilite = GUICtrlCreateButton("Highlight", 71, 0, 70, 20) _GUICtrlButton_SetImageList($hHilite, $hImage2) ;~ $hEdit1 = _GUICtrlRichEdit_Create($Form1, FileRead($log), 1, 21, 498, 478, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) $hEdit1 = _GUICtrlRichEdit_Create($Form1, "", 1, 21, 498, 478, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) GUICtrlSetBkColor($hEdit1, 0xFFFFFF) ;~ ; Highlight the text ;~ $iStart = 0 ;~ Do ;~ $aResults = _GUICtrlRichEdit_FindTextInRange($hEdit1, $text, $iStart) ;~ If $aResults[0] <> -1 Then ;~ $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($hEdit1, $aResults[0]) ;~ $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $iLine) ;~ $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $iLine) ;~ _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen) ;~ _GUICtrlRichEdit_SetCharBkColor($hEdit1, "304050") ;~ $iStart = $aResults[1] ;~ EndIf ;~ Until $aResults[0] = -1 GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hEdit1) Exit Case $nMsg = $hHilite _HiLiteGUI() _GUICtrlRichEdit_SetText($hEdit1, "") _OpenFile($hEdit1, $sFile) Case $nMsg = $hOpen $aFile = _WinAPI_GetOpenFileName("Open File Dialog", _ "Text File (*.txt;*.log)", ".", "", "", 1, _ $OFN_EXPLORER, 0, $Form1) If $aFile[0] = 0 Then $sError = _WinAPI_CommDlgExtendedError() MsgBox(0, "Error", $sError) ElseIf $aFile[1] <> "" Then $sFile = $aFile[1]&""&$aFile[2] _GUICtrlRichEdit_SetText($hEdit1, ""); Clear the screen before displaying a new log _OpenFile($hEdit1, $sFile) EndIf EndSelect $var2 = FileGetSize($sFile) If $var2 <> $var1 Then ConsoleWrite("Read in " & $var2 - $var1 & " bytes" & @CRLF) ConsoleWrite("New data" & @CRLF) $file = _FileOpenAPI($sFile) $read = _FileReadAPI($file, $var2 - $var1, $var1) _FileCloseAPI($file) ConsoleWrite($read & @CRLF) FileWrite($copyLog, $read) $iAllLen = _GUICtrlRichEdit_GetTextLength($hEdit1, True) $iLineLen = StringLen($read) $iNewStart = $iAllLen - $iLineLen ;_GUICtrlRichEdit_SetText($hEdit1, FileRead($sFile)) _GUICtrlRichEdit_AppendText($hEdit1, $read) ; Was trying to hilight new text, but it doesn't seem to be working quite right ;~ For $s = 0 To UBound($aRestore) - 1 ;~ If $aRestore[$s][3] = 1 Then $fCase = True ;~ If $aRestore[$s][3] = 0 Then $fCase = False ;~ If StringInStr($read, $aRestore[$s][0], $fCase) <> 0 Then ;~ $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($hEdit1, $iAllLen+1) ;~ $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $iLine) ;~ $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $iLine) ;~ _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen) ;~ _GUICtrlRichEdit_SetCharBkColor($hEdit1, $aRestore[$s][1]) ;~ ExitLoop; After finding one string, exit the loop and search for more - no multiple strings per line ;~ EndIf ;~ Next _GUICtrlRichEdit_ScrollToCaret($hEdit1) $var1 = $var2 EndIf WEnd Func _OpenFile($edit, $sPath) Local $iStart = 0, $oCount = 0, $fCase = False _GUICtrlRichEdit_SetText($edit, FileRead($sPath)) ; Add in the extra colors to the image list that were previously saved to the registry ; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1 For $i = 1 To 100 $var = RegEnumVal($sTailReg, $i) If @error <> 0 Then ExitLoop ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then $aData = StringSplit(RegRead($sTailReg, $var), "|") $sHexColor = Hex($aData[2], 6) $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2) $aRestore[$oCount][0] = $aData[1] ; Text $aRestore[$oCount][1] = $aData[2] ; COLORREF $aRestore[$oCount][2] = $sHexColor; Hex Color $aRestore[$oCount][3] = $aData[3] ; Match Case (0/1) $oCount += 1 EndIf Next If $oCount > 0 Then ReDim $aRestore[$oCount][4] ; Highlight the text If IsArray($aRestore) And $aRestore[0][0] <> "" Then For $s = 0 To UBound($aRestore) - 1 Do If $aRestore[$s][3] = 1 Then $fCase = True If $aRestore[$s][3] = 0 Then $fCase = False $aResults = _GUICtrlRichEdit_FindTextInRange($edit, $aRestore[$s][0], $iStart, -1, $fCase) ConsoleWrite($aRestore[$s][0]&@CRLF) If $aResults[0] <> -1 Then $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($edit, $aResults[0]) $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($edit, $iLine) $iLen = _GUICtrlRichEdit_GetLineLength($edit, $iLine) _GUICtrlRichEdit_SetSel($edit, $iFirst, $iFirst+$iLen) _GUICtrlRichEdit_SetCharBkColor($edit, $aRestore[$s][1]) $iStart = $aResults[1] ;ExitLoop; After finding one string, exit the loop and search for more - no multiple strings per line EndIf Until $aResults[0] = -1 $iStart = 0 Next EndIf EndFunc Func _HiLiteGUI() Local $Form2, $hImage3, $sCase, $xCount = 0 Local $aColors[5][2] = [["Red",255],["Green",65280],["Blue",16711680],["Yellow",65535],["Custom",16777215]]; Array containing colors and COLORREF numbers ; Create the Form $Form2 = GUICreate("Highlighting", 335, 380, Default, Default, BitOr($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), -1, $Form1) $hList = GUICtrlCreateListView("String", 12, 12, 306, 206) _GUICtrlListView_SetColumnWidth($hList, 0, 280) $hAdd = GUICtrlCreateButton("Add", 10, 222, 70, 25) $hDel = GUICtrlCreateButton("Delete", 90, 222, 70, 25) GUICtrlCreateLabel("Background Color:", 170, 222, 150, 20) $hCombo = _GUICtrlComboBoxEx_Create($Form2, "", 170, 242, 128, 120, $CBS_DROPDOWNLIST) $hCustom = GUICtrlCreateButton("", 299, 242, 22, 22, $BS_ICON) GUICtrlSetImage($hCustom, "C:Documents and SettingsjdubarMy DocumentsScripts_AllIconsmfc90u_17105.ico", -1) GUICtrlCreateLabel("String:", 10, 269, 150, 20) $hString = GUICtrlCreateInput("", 10, 289, 310, 20) $hCase = GUICtrlCreateCheckbox("Match Case", 10, 315, 80, 20) $hOk = GUICtrlCreateButton("Ok", 240, 345, 80, 25) ; Create the image list with the default colors and grab the custom color from the default reg key $hImage3 = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 16, 16)); Red _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x00FF00, 16, 16)); Green _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 16, 16)); Blue _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFF00, 16, 16)); Yellow If RegRead($sTailReg, "") = "" Then _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFFFF, 16, 16)); White Else _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, RegRead($sTailReg, ""), 16, 16)); Custom EndIf ; Add in the extra colors to the image list that were previously saved to the registry ; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1 For $i = 1 To 100 $var = RegEnumVal($sTailReg, $i) If @error <> 0 Then ExitLoop ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then $aData = StringSplit(RegRead($sTailReg, $var), "|") $sHexColor = Hex($aData[2], 6) $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2) _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16)) $aRestore[$xCount][0] = $aData[1] $aRestore[$xCount][1] = $aData[2] $aRestore[$xCount][2] = $sHexColor $aRestore[$xCount][3] = $aData[3] $xCount += 1 EndIf Next If $xCount > 0 Then ReDim $aRestore[$xCount][4] ;_ArrayDisplay($aRestore) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3) _GUICtrlListView_SetImageList($hList, $hImage3, 1) ; Add the colors For $y = 0 To 4 _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03s", $aColors[$y][0]), $y, $y) Next _GUICtrlComboBoxEx_SetCurSel($hCombo, 0); Set the default color selection - otherwise, it shows a blank entry ; Add the listview items If $xCount > 0 Then For $i = 0 To UBound($aRestore)-1 _GUICtrlListView_AddItem($hList, $aRestore[$i][0], $i+5) Next EndIf GUISetState(@SW_SHOW, $Form2) While 1 If $iSelectFlag Then $iSelectFlag = False $aItem = _GUICtrlListView_GetSelectedIndices($hList, True) If $aItem[0] > 0 Then ; Display the string GUICtrlSetData($hString, _GUICtrlListView_GetItemText($hList, $aItem[1])) ; Display the color Select Case $aRestore[$aItem[1]][2] = 0xFF0000; Red _GUICtrlComboBoxEx_SetCurSel($hCombo, 0) Case $aRestore[$aItem[1]][2] = 0x00FF00; Green _GUICtrlComboBoxEx_SetCurSel($hCombo, 1) Case $aRestore[$aItem[1]][2] = 0x0000FF; Blue _GUICtrlComboBoxEx_SetCurSel($hCombo, 2) Case $aRestore[$aItem[1]][2] = 0xFFFF00; Yellow _GUICtrlComboBoxEx_SetCurSel($hCombo, 3) Case Else _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $aRestore[$aItem[1]][2], 16, 16)) _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4) _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3) _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen ;_GUICtrlListView_SetImageList($hList, $hImage3, 1) _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4) RegWrite($sTailReg, "", "REG_SZ", $aRestore[$aItem[1]][2]) _GUICtrlComboBoxEx_SetCurSel($hCombo, 4) EndSelect ; Display the case check Select Case $aRestore[$aItem[1]][3] = 1 GUICtrlSetState($hCase, $GUI_CHECKED) Case $aRestore[$aItem[1]][3] = 0 GUICtrlSetState($hCase, $GUI_UNCHECKED) EndSelect Else GUICtrlSetData($hString, "") GUICtrlSetState($hCase, $GUI_UNCHECKED) _GUICtrlComboBoxEx_SetCurSel($hCombo, 0) EndIf EndIf ; If the combo box is clicked, check if the color has changed If _GUICtrlComboBoxEx_GetDroppedState($hCombo) Then $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True) If $aItemC[0] > 0 Then Do Sleep(100) Until _GUICtrlComboBoxEx_GetDroppedState($hCombo) = False If $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1] <> $aRestore[$aItemC[1]][1] Then ConsoleWrite($aItemC[1]&@CRLF&RegRead($sTailReg, $aItemC[1])&@CRLF&$aRestore[$aItemC[1]][1]&@CRLF&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&@CRLF) RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo)); Update the listview $aRestore[$aItemC[1]][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]; Update the array $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6) $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2) $aRestore[$aItemC[1]][2] = $sHexColor EndIf EndIf EndIf $hMsg = GUIGetMsg() Select Case $hMsg = $GUI_EVENT_CLOSE Or $hMsg = $hOk ExitLoop Case $hMsg = $hCase ; If the case box has been changed, edit the registry, too $aItemB = _GUICtrlListView_GetSelectedIndices($hList, True) If IsArray($aItemB) Then If $aItemB[0] > 0 Then If $aRestore[$aItemB[1]][3] = 1 And GUICtrlRead($hCase) = $GUI_UNCHECKED Then $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1) $sTmp &= 0 RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp) $aRestore[$aItemB[1]][3] = 0 EndIf If $aRestore[$aItemB[1]][3] = 0 And GUICtrlRead($hCase) = $GUI_CHECKED Then $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1) $sTmp &= 1 RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp) $aRestore[$aItemB[1]][3] = 1 EndIf EndIf EndIf Case $hMsg = $hDel $aSel = _GUICtrlListView_GetSelectedIndices($hList, True) If $aSel[0] > 0 Then _ArrayDelete($aRestore, $aSel[1]) $xCount -= 1 ReDim $aRestore[$xCount][4] $sText = _GUICtrlListView_GetItemText($hList, $aSel[1]) $iCount = 0 RegDelete($sTailReg) For $i = 0 To $xCount-1 If RegRead($sTailReg, $i) <> "" Then RegDelete($sTailReg, $i) RegWrite($sTailReg, $i, "REG_SZ", $aRestore[$i][0]&"|"&$aRestore[$i][1]&"|"&$aRestore[$i][3]) Next _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($hList)) EndIf Case $hMsg = $hAdd $dupeFlag = False If GUICtrlRead($hString) <> "" Then For $y = 0 To _GUICtrlListView_GetItemCount($hList)-1 If StringInStr(_GUICtrlListView_GetItemText($hList, $y), GUICtrlRead($hString)) <> 0 Then $dupeFlag = True ExitLoop EndIf Next If $dupeFlag Then MsgBox(64, "Duplicate", "This search criteria already exists.") Else $iIndex = _GUICtrlListView_AddItem($hList, GUICtrlRead($hString), _GUICtrlComboBoxEx_GetCurSel($hCombo)) If GUICtrlRead($hCase) = $GUI_CHECKED Then $sCase = 1 If GUICtrlRead($hCase) = $GUI_UNCHECKED Then $sCase = 0 RegWrite($sTailReg, $iIndex, "REG_SZ", GUICtrlRead($hString)&"|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|"&$sCase) $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6) $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2) $xCount += 1 ReDim $aRestore[$xCount][4] $aRestore[$xCount-1][0] = GUICtrlRead($hString) $aRestore[$xCount-1][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1] $aRestore[$xCount-1][2] = $sHexColor $aRestore[$xCount-1][3] = $sCase ;_ArrayDisplay($aRestore, $xCount) EndIf Else MsgBox(64, "Error", "No string was entered. Please enter a string to highlight.") EndIf Case $hMsg = $hCustom $sColorRef = _ChooseColor(0, 255, 0, $Form1) If $sColorRef <> -1 Then $aColors[4][1] = $sColorRef $sHexColor = Hex($sColorRef, 6) $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2) ;MsgBox(0, "", [email="$sColorRef&@CRLF&$sHexColor"]$sColorRef&@CRLF&$sHexColor[/email]) _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16)) _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4) _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3) _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen ;_GUICtrlListView_SetImageList($hList, $hImage3, 1) _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4) RegWrite($sTailReg, "", "REG_SZ", $sHexColor) $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True) If $aItemC[0] > 0 Then _GUICtrlListView_ClickItem($hList, $aItemC[1]) _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo)) RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry $aRestore[$aItemC[1]][2] = $sHexColor EndIf EndIf EndSelect WEnd GUIDelete($Form2) EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK $iSelectFlag = True EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _Exit() _GUICtrlRichEdit_Destroy($hEdit1) EndFuncAPITailRW.zip