1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

Initial console support

This commit is contained in:
Brian Fiete 2024-07-19 10:31:33 +02:00
parent 45a5978611
commit 186c2125fa
21 changed files with 1244 additions and 29 deletions

View file

@ -7,10 +7,14 @@ namespace Beefy.widgets
{
public enum KeyFlags
{
None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4
case None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4,
CapsLock = 8,
NumLock = 0x10;
public KeyFlags HeldKeys => this & ~(CapsLock | NumLock);
}
}

View file

@ -691,6 +691,8 @@ namespace Beefy.gfx
public float GetWidth(char32 theChar)
{
CharData charData = GetCharData(theChar);
if (charData == null)
return 0;
return charData.mXAdvance;
}

View file

@ -2304,7 +2304,7 @@ namespace Beefy.widgets
int prevCursorPos;
bool gotCursorPos = TryGetCursorTextPos(out prevCursorPos);
if (mWidgetWindow.GetKeyFlags() == .Ctrl)
if (mWidgetWindow.GetKeyFlags(true) == .Ctrl)
{
switch (keyCode)
{
@ -2330,7 +2330,7 @@ namespace Beefy.widgets
}
}
if (mWidgetWindow.GetKeyFlags() == .Ctrl | .Shift)
if (mWidgetWindow.GetKeyFlags(true) == .Ctrl | .Shift)
{
switch (keyCode)
{

View file

@ -910,7 +910,7 @@ namespace Beefy.widgets
switch (keyCode)
{
case (KeyCode)'A':
if ((mAllowMultiSelect) && (mWidgetWindow.GetKeyFlags() == KeyFlags.Ctrl))
if ((mAllowMultiSelect) && (mWidgetWindow.GetKeyFlags(true) == KeyFlags.Ctrl))
{
mRoot.WithItems(scope (listViewItem) =>
{

View file

@ -747,18 +747,32 @@ namespace Beefy.widgets
}
}
public virtual void MouseWheel(MouseEvent evt)
{
if (!evt.mHandled)
{
MouseWheel(evt.mX, evt.mY, evt.mWheelDeltaX, evt.mWheelDeltaY);
MarkDirty();
if (mParent != null)
{
MouseEvent parentEvt = scope .();
parentEvt.mWheelDeltaX = evt.mWheelDeltaX;
parentEvt.mWheelDeltaY = evt.mWheelDeltaY;
parentEvt.mSender = evt.mSender;
// Keep passing it up until some is interested in using it...
SelfToParentTranslate(evt.mX, evt.mY, out parentEvt.mX, out parentEvt.mY);
mParent.MouseWheel(parentEvt);
}
}
}
public virtual void MouseWheel(float x, float y, float deltaX, float deltaY)
{
MarkDirty();
if (mParent != null)
{
// Keep passing it up until some is interested in using it...
float aX;
float aY;
SelfToParentTranslate(x, y, out aX, out aY);
mParent.MouseWheel(aX, aY, deltaX, deltaY);
}
}
public virtual void MouseUp(float x, float y, int32 btn)

View file

@ -17,6 +17,7 @@ namespace Beefy.widgets
public delegate void WindowMovedHandler(BFWindow window);
public delegate void MouseWheelHandler(MouseEvent mouseEvent);
public delegate void KeyDownHandler(KeyDownEvent keyboardEvent);
public delegate void KeyUpHandler(KeyCode keyCode);
//public delegate void CloseTemporaryHandler(WidgetWindow window);
public delegate void DragDropFileHandler(StringView filePath);
@ -33,6 +34,7 @@ namespace Beefy.widgets
public Event<MouseWheelHandler> mOnMouseWheel ~ _.Dispose();
public Event<MenuItemSelectedHandler> mOnMenuItemSelected ~ _.Dispose();
public Event<KeyDownHandler> mOnWindowKeyDown ~ _.Dispose();
public Event<KeyUpHandler> mOnWindowKeyUp ~ _.Dispose();
public Event<delegate HitTestResult(int32, int32)> mOnHitTest ~ _.Dispose();
public Event<DragDropFileHandler> mOnDragDropFile ~ _.Dispose();
@ -122,7 +124,12 @@ namespace Beefy.widgets
}
}
public KeyFlags GetKeyFlags()
#if BF_PLATFORM_WINDOWS
[CLink, CallingConvention(.Stdcall)]
static extern int16 GetKeyState(int nVirtKey);
#endif
public KeyFlags GetKeyFlags(bool onlyHeldKeys)
{
KeyFlags keyFlags = default;
if (IsKeyDown(KeyCode.Shift))
@ -131,6 +138,17 @@ namespace Beefy.widgets
keyFlags |= KeyFlags.Ctrl;
if (IsKeyDown(KeyCode.Menu))
keyFlags |= KeyFlags.Alt;
#if BF_PLATFORM_WINDOWS
if (!onlyHeldKeys)
{
if (GetKeyState((.)KeyCode.CapsLock) != 0)
keyFlags |= .CapsLock;
if (GetKeyState((.)KeyCode.Numlock) != 0)
keyFlags |= .NumLock;
}
#endif
return keyFlags;
}
@ -414,7 +432,7 @@ namespace Beefy.widgets
KeyDownEvent e = scope KeyDownEvent();
e.mSender = this;
e.mKeyFlags = GetKeyFlags();
e.mKeyFlags = GetKeyFlags(false);
e.mKeyCode = (KeyCode)keyCode;
e.mIsRepeat = isRepeat != 0;
@ -450,6 +468,8 @@ namespace Beefy.widgets
var fakeFocusWindow = GetFakeFocusWindow();
if (fakeFocusWindow != null)
fakeFocusWindow.KeyUp(keyCode);
mOnWindowKeyUp((.)keyCode);
}
public override HitTestResult HitTest(int32 x, int32 y)
@ -650,7 +670,7 @@ namespace Beefy.widgets
let oldFlags = mMouseFlags;
if (mMouseFlags == 0)
mMouseDownKeyFlags = GetKeyFlags();
mMouseDownKeyFlags = GetKeyFlags(true);
mMouseFlags |= (MouseFlag)(1 << btn);
if ((!mHasFocus) && (mParent == null))
@ -802,7 +822,14 @@ namespace Beefy.widgets
float childX;
float childY;
aWidget.RootToSelfTranslate(mMouseX, mMouseY, out childX, out childY);
aWidget.MouseWheel(childX, childY, deltaX, deltaY);
MouseEvent anEvent = scope MouseEvent();
anEvent.mX = childX;
anEvent.mY = childY;
anEvent.mWheelDeltaX = deltaX;
anEvent.mWheelDeltaY = deltaY;
anEvent.mSender = this;
aWidget.MouseWheel(anEvent);
}
}

View file

@ -35,6 +35,16 @@ namespace System.Diagnostics
}
}
public int ProcessId
{
get
{
if (mSpawn == null)
return -1;
return Platform.BfpSpawn_GetProcessId(mSpawn);
}
}
public this()
{
mSpawn = null;

View file

@ -243,6 +243,8 @@ namespace System
public static void BfpProcess_GetProcessName(BfpProcess* process, char8* outName, int32* inOutNameSize, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static int32 BfpProcess_GetProcessId(BfpProcess* process) => Runtime.NotImplemented();
public static int BfpSpawn_GetProcessId(BfpSpawn* spawn) => Runtime.NotImplemented();;
#endif
public enum BfpSpawnFlags : int32
@ -286,6 +288,8 @@ namespace System
public static extern bool BfpSpawn_WaitFor(BfpSpawn* spawn, int waitMS, int* outExitCode, BfpSpawnResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr);
[CallingConvention(.Stdcall), CLink]
public static extern int BfpSpawn_GetProcessId(BfpSpawn* spawn);
[CallingConvention(.Stdcall), CLink]
public static extern int BfpProcess_GetCurrentId();

View file

@ -101,6 +101,12 @@ namespace System
public function int WndProc(HWnd hWnd, int32 msg, int wParam, int lParam);
public delegate IntBool EnumThreadWindowsCallback(HWnd hWnd, void* extraParameter);
public struct Rect : this(int32 left, int32 top, int32 right, int32 bottom)
{
public int32 Width => right - left;
public int32 Height => bottom - top;
}
[CRepr]
public struct OpenFileName
{
@ -1737,6 +1743,9 @@ namespace System
public static extern int SetWindowLongPtrW(int hWnd, int32 nIndex, int value);
#endif
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool SetWindowPos(HWnd hWnd, HWnd hWndAfter, int x, int y, int cx, int cy, int flags);
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool PostMessageW(HWnd hWnd, int32 msg, int wParam, int lParam);
@ -1773,6 +1782,9 @@ namespace System
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern int32 GetWindowTextA(HWnd hWnd, char8* ptr, int32 length);
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool AdjustWindowRectEx(ref Rect rect, uint32 style, IntBool menu, uint32 exStyle);
[CLink, CallingConvention(.Stdcall)]
public static extern int32 GetWindowThreadProcessId(HWnd handle, out int32 processId);

View file

@ -217,6 +217,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpSpawn_Release(BfpSpawn* spawn);
BFP_EXPORT void BFP_CALLTYPE BfpSpawn_Kill(BfpSpawn* spawn, int exitCode, BfpKillFlags killFlags, BfpSpawnResult* outResult);
BFP_EXPORT bool BFP_CALLTYPE BfpSpawn_WaitFor(BfpSpawn* spawn, int waitMS, int* outExitCode, BfpSpawnResult* outResult);
BFP_EXPORT void BFP_CALLTYPE BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr); // Caller must release the files
BFP_EXPORT int BFP_CALLTYPE BfpSpawn_GetProcessId(BfpSpawn* spawn);
enum BfpThreadCreateFlags
{

View file

@ -1241,6 +1241,11 @@ BFP_EXPORT void BFP_CALLTYPE BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** o
}
}
BFP_EXPORT int BFP_CALLTYPE BfpSpawn_GetProcessId(BfpSpawn* spawn);
{
return spawn->mPid;
}
bool BfpSpawn_WaitFor(BfpSpawn* spawn, int waitMS, int* outExitCode, BfpSpawnResult* outResult)
{
OUTRESULT(BfpSpawnResult_Ok);

View file

@ -2098,6 +2098,11 @@ BFP_EXPORT void BFP_CALLTYPE BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** o
}
}
BFP_EXPORT int BFP_CALLTYPE BfpSpawn_GetProcessId(BfpSpawn* spawn)
{
return spawn->mProcessId;
}
/// BfpThread
BFP_EXPORT BfpThread* BFP_CALLTYPE BfpThread_Create(BfpThreadStartProc startProc, void* threadParam, intptr stackSize, BfpThreadCreateFlags flags, BfpThreadId* outThreadId)

View file

@ -309,6 +309,8 @@ namespace IDE
Add("Show File Externally", new => gApp.Cmd_ShowFileExternally);
Add("Show Find Results", new => gApp.ShowFindResults);
Add("Show Fixit", new => gApp.Cmd_ShowFixit);
Add("Show Terminal", new => gApp.ShowTerminal);
Add("Show Console", new => gApp.ShowConsole);
Add("Show Immediate", new => gApp.ShowImmediatePanel);
Add("Show Memory", new => gApp.ShowMemory);
Add("Show Modules", new => gApp.ShowModules);

View file

@ -160,6 +160,7 @@ namespace IDE
public PropertiesPanel mPropertiesPanel;
public Font mTinyCodeFont ~ delete _;
public Font mCodeFont ~ delete _;
public Font mTermFont ~ delete _;
protected bool mInitialized;
public bool mConfig_NoIR;
public bool mFailed;
@ -196,6 +197,8 @@ namespace IDE
public bool mWantShowOutput;
public OutputPanel mOutputPanel;
public TerminalPanel mTerminalPanel;
public ConsolePanel mConsolePanel;
public ImmediatePanel mImmediatePanel;
public FindResultsPanel mFindResultsPanel;
public WatchPanel mAutoWatchPanel;
@ -711,6 +714,8 @@ namespace IDE
RemoveAndDelete!(mProjectPanel);
RemoveAndDelete!(mClassViewPanel);
RemoveAndDelete!(mOutputPanel);
RemoveAndDelete!(mTerminalPanel);
RemoveAndDelete!(mConsolePanel);
RemoveAndDelete!(mImmediatePanel);
RemoveAndDelete!(mFindResultsPanel);
RemoveAndDelete!(mAutoWatchPanel);
@ -815,6 +820,8 @@ namespace IDE
dlg(mProjectPanel);
dlg(mClassViewPanel);
dlg(mOutputPanel);
dlg(mTerminalPanel);
dlg(mConsolePanel);
dlg(mImmediatePanel);
dlg(mFindResultsPanel);
dlg(mAutoWatchPanel);
@ -5152,6 +5159,18 @@ namespace IDE
ShowPanel(mAutoWatchPanel, "Auto Watches");
}
[IDECommand]
public void ShowTerminal()
{
ShowPanel(mTerminalPanel, "Terminal");
}
[IDECommand]
public void ShowConsole()
{
ShowPanel(mConsolePanel, "Console");
}
[IDECommand]
public void ShowImmediatePanel()
{
@ -5924,12 +5943,14 @@ namespace IDE
AddMenuItem(subMenu, "&Diagnostics", "Show Diagnostics");
AddMenuItem(subMenu, "E&rrors", "Show Errors");
AddMenuItem(subMenu, "&Find Results", "Show Find Results");
AddMenuItem(subMenu, "&Terminal", "Show Terminal");
AddMenuItem(subMenu, "Co&nsole", "Show Console");
AddMenuItem(subMenu, "&Immediate Window", "Show Immediate");
AddMenuItem(subMenu, "&Memory", "Show Memory");
AddMenuItem(subMenu, "Mod&ules", "Show Modules");
AddMenuItem(subMenu, "&Output", "Show Output");
AddMenuItem(subMenu, "&Profiler", "Show Profiler");
AddMenuItem(subMenu, "&Threads", "Show Threads");
AddMenuItem(subMenu, "T&hreads", "Show Threads");
AddMenuItem(subMenu, "&Watches", "Show Watches");
AddMenuItem(subMenu, "Work&space Explorer", "Show Workspace Explorer");
subMenu.AddMenuItem(null);
@ -6076,6 +6097,7 @@ namespace IDE
public void SetupNewWindow(WidgetWindow window, bool isMainWindow)
{
window.mOnWindowKeyDown.Add(new => SysKeyDown);
window.mOnWindowKeyUp.Add(new => SysKeyUp);
window.mOnMouseUp.Add(new => MouseUp);
if (isMainWindow)
window.mOnWindowCloseQuery.Add(new => SecondaryAllowClose);
@ -8228,6 +8250,9 @@ namespace IDE
NOP!();
}
mConsolePanel.SysKeyDown(evt);
//mTerminalPanel.SysKeyDown(evt);
if (evt.mHandled)
return;
@ -8276,7 +8301,7 @@ namespace IDE
{
var keyState = scope KeyState();
keyState.mKeyCode = evt.mKeyCode;
keyState.mKeyFlags = evt.mKeyFlags;
keyState.mKeyFlags = evt.mKeyFlags.HeldKeys;
var curKeyMap = mCommands.mKeyMap;
@ -8377,7 +8402,7 @@ namespace IDE
//if (focusWidget is DisassemblyPanel)
//break;
if (evt.mKeyFlags == 0) // No ctrl/shift/alt
if (evt.mKeyFlags.HeldKeys == 0) // No ctrl/shift/alt
{
switch (evt.mKeyCode)
{
@ -8398,6 +8423,12 @@ namespace IDE
}
}
}
void SysKeyUp(KeyCode keyCode)
{
//mTerminalPanel.SysKeyUp(keyCode);
mConsolePanel.SysKeyUp(keyCode);
}
void ShowOpenFileInSolutionDialog()
{
@ -12242,6 +12273,7 @@ namespace IDE
mTinyCodeFont = new Font();
mCodeFont = new Font();
mTermFont = new Font();
//mCodeFont = Font.LoadFromFile(BFApp.sApp.mInstallDir + "fonts/SourceCodePro32.fnt");
@ -12268,6 +12300,10 @@ namespace IDE
mClassViewPanel.mAutoDelete = false;
mOutputPanel = new OutputPanel(true);
mOutputPanel.mAutoDelete = false;
mTerminalPanel = new TerminalPanel();
mTerminalPanel.mAutoDelete = false;
mConsolePanel = new ConsolePanel();
mConsolePanel.mAutoDelete = false;
mImmediatePanel = new ImmediatePanel();
mImmediatePanel.mAutoDelete = false;
mFindResultsPanel = new FindResultsPanel();
@ -12395,6 +12431,7 @@ namespace IDE
mMainWindow.mIsMainWindow = true;
mMainWindow.mOnMouseUp.Add(new => MouseUp);
mMainWindow.mOnWindowKeyDown.Add(new => SysKeyDown);
mMainWindow.mOnWindowKeyUp.Add(new => SysKeyUp);
mMainWindow.mOnWindowCloseQuery.Add(new => AllowClose);
mMainWindow.mOnDragDropFile.Add(new => DragDropFile);
CreateMenu();
@ -12619,6 +12656,8 @@ namespace IDE
mTinyCodeFont.AddAlternate(new String("fonts/seguihis.ttf"), tinyFontSize);*/
}
mTermFont.Load("Cascadia Mono Regular", fontSize);
if (!err.IsEmpty)
{
OutputErrorLine(err);

View file

@ -242,7 +242,7 @@ namespace IDE.ui
{
base.KeyDown(keyCode, isRepeat);
if ((keyCode == (.)'C') && (mWidgetWindow.GetKeyFlags() == .Ctrl))
if ((keyCode == (.)'C') && (mWidgetWindow.GetKeyFlags(true) == .Ctrl))
{
String versionInfo = scope String();
versionInfo.AppendF("Beef IDE Version {}", gApp.mVersionInfo.FileVersion);

1031
IDE/src/ui/ConsolePanel.bf Normal file

File diff suppressed because it is too large Load diff

View file

@ -83,6 +83,9 @@ namespace IDE.ui
data.GetString("Type", type);
Panel panel = null;
if (type == "")
return gApp.mTerminalPanel;
if (type == "CallStackPanel")
panel = gApp.mCallStackPanel;
else if (type == "BreakpointPanel")
@ -93,6 +96,10 @@ namespace IDE.ui
{
panel = gApp.mOutputPanel;
}
else if (type == "TerminalPanel")
{
panel = gApp.mTerminalPanel;
}
else if (type == "ImmediatePanel")
{
panel = gApp.mImmediatePanel;
@ -159,6 +166,14 @@ namespace IDE.ui
{
panel = gApp.mBookmarksPanel;
}
else if (type == "TerminalPanel")
{
panel = gApp.mTerminalPanel;
}
else if (type == "ConsolePanel")
{
panel = gApp.mConsolePanel;
}
if (panel != null)
{

View file

@ -2375,7 +2375,7 @@ namespace IDE.ui
base.KeyDown(keyCode, isRepeat);
if (mWidgetWindow.GetKeyFlags() == .Ctrl)
if (mWidgetWindow.GetKeyFlags(true) == .Ctrl)
{
switch (keyCode)
{
@ -2388,7 +2388,7 @@ namespace IDE.ui
default:
}
}
else if (mWidgetWindow.GetKeyFlags() == .None)
else if (mWidgetWindow.GetKeyFlags(true) == .None)
{
if (keyCode == KeyCode.Delete)
RemoveSelectedItems();

View file

@ -394,7 +394,7 @@ namespace IDE.ui
{
var focusedListViewItem = GetRoot().FindFocusedItem();
bool changeFocus = (keyCode == .Tab) && (mWidgetWindow.GetKeyFlags() == .None);
bool changeFocus = (keyCode == .Tab) && (mWidgetWindow.GetKeyFlags(true) == .None);
if ((keyCode == .Right) && ((focusedListViewItem == null) || (focusedListViewItem.GetChildCount() == 0)))
changeFocus = true;
@ -454,7 +454,7 @@ namespace IDE.ui
{
var propertiesDialog = (PropertiesDialog)mParent;
let keyFlags = mWidgetWindow.GetKeyFlags();
let keyFlags = mWidgetWindow.GetKeyFlags(true);
bool changeFocus = (keyCode == .Tab) && (keyFlags == .Shift);
if (keyCode == .Left)
{

View file

@ -0,0 +1,24 @@
#pragma warning disable 168
using System;
using Beefy.geom;
using Beefy.gfx;
using System.Text;
using Beefy.theme.dark;
using System.Security.Cryptography;
using Beefy.widgets;
using Beefy.events;
using System.Diagnostics;
using Beefy.utils;
namespace IDE.ui;
class TerminalPanel : Panel
{
public override void Serialize(StructuredData data)
{
base.Serialize(data);
data.Add("Type", "TerminalPanel");
}
}

View file

@ -0,0 +1,20 @@
namespace IDE.util;
class ConsoleProvider
{
public struct Cell
{
public char32 mChar;
public uint32 mFgColor;
public uint32 mBgColor;
}
public virtual void Get(int col, int row)
{
}
}
class WinNativeConsoleProvider
{
}