mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
MemLogger
This commit is contained in:
parent
96f8b1426d
commit
119da8dada
14 changed files with 377 additions and 34 deletions
|
@ -31,6 +31,9 @@ namespace LogViewer
|
|||
public List<Match> mNewMatches ~ delete _;
|
||||
public bool mRefreshing;
|
||||
|
||||
public String mFilePath ~ delete _;
|
||||
public String mMemLogName ~ delete _;
|
||||
|
||||
public uint32[] mColors = new .(
|
||||
0xFFFFFFFF,
|
||||
0xFFFC5858,
|
||||
|
@ -54,6 +57,7 @@ namespace LogViewer
|
|||
ewc.mFont = gApp.mFont;
|
||||
ewc.mWordWrap = false;
|
||||
ewc.mTextColors = mColors;
|
||||
ewc.mIsReadOnly = true;
|
||||
mDocEdit.InitScrollbars(true, true);
|
||||
AddWidget(mDocEdit);
|
||||
|
||||
|
@ -79,6 +83,12 @@ namespace LogViewer
|
|||
|
||||
public void Load(StringView filePath)
|
||||
{
|
||||
DeleteAndNullify!(mFilePath);
|
||||
DeleteAndNullify!(mMemLogName);
|
||||
mFilePath = new .(filePath);
|
||||
|
||||
mWidgetWindow.SetTitle(scope $"LogViewer - {mFilePath}");
|
||||
|
||||
scope AutoBeefPerf("Board.Load");
|
||||
|
||||
delete mContent;
|
||||
|
@ -89,9 +99,45 @@ namespace LogViewer
|
|||
{
|
||||
gApp.Fail("Failed to open file '{0}'", filePath);
|
||||
}
|
||||
|
||||
mFilterDirtyCountdown = 1;
|
||||
//Refresh();
|
||||
//mDocEdit.SetText(mContent);
|
||||
}
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern char8* MemLogger_Get(char8* name);
|
||||
|
||||
public void LoadMemLog(StringView name)
|
||||
{
|
||||
DeleteAndNullify!(mFilePath);
|
||||
DeleteAndNullify!(mMemLogName);
|
||||
mMemLogName = new .(name);
|
||||
|
||||
mWidgetWindow.SetTitle(scope $"LogViewer - {mMemLogName}");
|
||||
|
||||
var result = MemLogger_Get(name.ToScopeCStr!());
|
||||
if (result == null)
|
||||
{
|
||||
gApp.Fail("Failed to open MemLog '{0}'", name);
|
||||
return;
|
||||
}
|
||||
|
||||
delete mContent;
|
||||
mContent = new String();
|
||||
mContent.Append(result);
|
||||
|
||||
mFilterDirtyCountdown = 1;
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if (mFilePath != null)
|
||||
Load(mFilePath);
|
||||
if (mMemLogName != null)
|
||||
LoadMemLog(mMemLogName);
|
||||
}
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
scope AutoBeefPerf("Board.Refresh");
|
||||
|
@ -105,37 +151,40 @@ namespace LogViewer
|
|||
|
||||
let filters = mFilter.Split!('\n');
|
||||
|
||||
for (var line in mContent.Split('\n'))
|
||||
if (mContent != null)
|
||||
{
|
||||
bool hadMatch = false;
|
||||
bool hadFilter = false;
|
||||
|
||||
for (var filter in filters)
|
||||
for (var line in mContent.Split('\n'))
|
||||
{
|
||||
if (filter.Length == 0)
|
||||
continue;
|
||||
hadFilter = true;
|
||||
int lastIdx = -1;
|
||||
while (true)
|
||||
bool hadMatch = false;
|
||||
bool hadFilter = false;
|
||||
|
||||
for (var filter in filters)
|
||||
{
|
||||
int findIdx = line.IndexOf(filter, lastIdx + 1);
|
||||
if (findIdx == -1)
|
||||
break;
|
||||
if (filter.Length == 0)
|
||||
continue;
|
||||
hadFilter = true;
|
||||
int lastIdx = -1;
|
||||
while (true)
|
||||
{
|
||||
int findIdx = line.IndexOf(filter, lastIdx + 1);
|
||||
if (findIdx == -1)
|
||||
break;
|
||||
|
||||
hadMatch = true;
|
||||
lastIdx = findIdx + filter.Length - 1;
|
||||
hadMatch = true;
|
||||
lastIdx = findIdx + filter.Length - 1;
|
||||
|
||||
Match match;
|
||||
match.mFilterIdx = (.)@filter;
|
||||
match.mTextIdx = (.)(mNewContent.Length + findIdx);
|
||||
mNewMatches.Add(match);
|
||||
Match match;
|
||||
match.mFilterIdx = (.)@filter;
|
||||
match.mTextIdx = (.)(mNewContent.Length + findIdx);
|
||||
mNewMatches.Add(match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((hadMatch) || (!hadFilter))
|
||||
{
|
||||
mNewContent.Append(line);
|
||||
mNewContent.Append('\n');
|
||||
if ((hadMatch) || (!hadFilter))
|
||||
{
|
||||
mNewContent.Append(line);
|
||||
mNewContent.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using Beefy.utils;
|
|||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Beefy.sys;
|
||||
|
||||
namespace LogViewer
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ namespace LogViewer
|
|||
{
|
||||
base.Init();
|
||||
|
||||
var dialog = scope OpenFileDialog();
|
||||
/*var dialog = scope OpenFileDialog();
|
||||
dialog.SetFilter("All files (*.*)|*.*");
|
||||
dialog.InitialDirectory = mInstallDir;
|
||||
dialog.Title = "Open Log";
|
||||
|
@ -35,7 +36,7 @@ namespace LogViewer
|
|||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
BeefPerf.Init("127.0.0.1", "LogViewer");
|
||||
|
||||
|
@ -45,7 +46,7 @@ namespace LogViewer
|
|||
|
||||
BFWindow.Flags windowFlags = BFWindow.Flags.Border | //BFWindow.Flags.SysMenu | //| BFWindow.Flags.CaptureMediaKeys |
|
||||
BFWindow.Flags.Caption | BFWindow.Flags.Minimize | BFWindow.Flags.QuitOnClose | BFWindowBase.Flags.Resizable |
|
||||
BFWindow.Flags.SysMenu;
|
||||
BFWindow.Flags.SysMenu | .Menu;
|
||||
|
||||
mFont = new Font();
|
||||
float fontSize = 12;
|
||||
|
@ -55,17 +56,43 @@ namespace LogViewer
|
|||
mFont.AddAlternate("Segoe UI Emoji", fontSize);
|
||||
|
||||
mBoard = new Board();
|
||||
mBoard.Load(dialog.FileNames[0]);
|
||||
mMainWindow = new WidgetWindow(null, "LogViewer", 0, 0, 1600, 1200, windowFlags, mBoard);
|
||||
//mBoard.Load(dialog.FileNames[0]);
|
||||
mMainWindow = new WidgetWindow(null, "LogViewer", 20, 20, 1600, 1200, windowFlags, mBoard);
|
||||
//mMainWindow.mWindowKeyDownDelegate.Add(new => SysKeyDown);
|
||||
mMainWindow.SetMinimumSize(480, 360);
|
||||
mMainWindow.mIsMainWindow = true;
|
||||
|
||||
SysMenu root = mMainWindow.mSysMenu;
|
||||
var subMenu = root.AddMenuItem("&File");
|
||||
subMenu.AddMenuItem("&Open", "Ctrl+O", new (menu) =>
|
||||
{
|
||||
var dialog = scope OpenFileDialog();
|
||||
dialog.SetFilter("All files (*.*)|*.*");
|
||||
dialog.InitialDirectory = mInstallDir;
|
||||
dialog.Title = "Open Log";
|
||||
let result = dialog.ShowDialog();
|
||||
if ((result case .Err) || (dialog.FileNames.Count == 0))
|
||||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
mBoard.Load(dialog.FileNames[0]);
|
||||
});
|
||||
subMenu.AddMenuItem("Read &MemLog", "Ctrl+M", new (menu) =>
|
||||
{
|
||||
var dialog = new MemLogDialog();
|
||||
dialog.PopupWindow(mMainWindow);
|
||||
});
|
||||
subMenu.AddMenuItem("&Reload", "Ctrl+R", new (menu) =>
|
||||
{
|
||||
mBoard.Reload();
|
||||
});
|
||||
}
|
||||
|
||||
public void Fail(String str, params Object[] paramVals)
|
||||
{
|
||||
var errStr = scope String();
|
||||
errStr.AppendF(str, paramVals);
|
||||
errStr.AppendF(str, params paramVals);
|
||||
Fail(errStr);
|
||||
}
|
||||
|
||||
|
|
21
BeefTools/LogViewer/src/MemLogDialog.bf
Normal file
21
BeefTools/LogViewer/src/MemLogDialog.bf
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Beefy.theme.dark;
|
||||
using Beefy.widgets;
|
||||
|
||||
namespace LogViewer;
|
||||
|
||||
class MemLogDialog : DarkDialog
|
||||
{
|
||||
EditWidget mEditWidget;
|
||||
|
||||
public this() : base("Open MemLog", "MemLog Name")
|
||||
{
|
||||
|
||||
mDefaultButton = AddButton("OK", new (evt) =>
|
||||
{
|
||||
var name = mEditWidget.GetText(.. scope .());
|
||||
gApp.mBoard.LoadMemLog(name);
|
||||
});
|
||||
mEscButton = AddButton("Cancel", new (evt) => Close());
|
||||
mEditWidget = AddEdit("");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue