Clearing MacOS terminal in .Net Core C# - c#

I'm currently developing a console app and I've designed my menus in a way such that the active element of the menu is highlighted with a specific background color. To re-render the menu after the change of an active element I'm moving the cursor with the Console.SetCursorPosition(0,0) to the very top of the window to then rewrite all the lines. Also, the Console.Clear() method is used to clear the console before moving to another menu (which can be of different size).
However, this approach does not seem to work on MacOS - the Console.Clear() method is not working, and the Console.SetCursorPosition(0,0) is not working in the way it should - the menus overlap each other instead of being cleared.
Is there any way to make this work on MacOS, or is it impossible due to some of the features of the MacOS terminal?

My suggestion would be to use the CursesSharp library to do this.
CursesSharp provides C# bindings to the ncurses.h library for Unix-like systems. In theory, you ought to be able to do anything you want to do that the ncurses library is capable of, including clearing the screen and setting the cursor position.

Related

Mouse hover detection in .NET MAUI

I want to detect mouse hovering over visual elements in .NET MAUI ( like buttons ). I cannot find any "onmouseover"/"ismouseover" events for this. How can I implement this.
All requests for "desktop" style control of keyboard and mouse have been consolidated under Maui issue: Desktop platforms: Mouse and Keyboard.
jfversluis' comment (at that issue or a related issue) indicates that no work in this area has yet been planned.
That issue is the place to discuss the topic (express interest in, or add any specific requirements or use cases), until there is a plan.
Until then, the work-around is generally to write Windows-only code in the Windows folder of your Maui project.
Unfortunately for mouse, that only gives window or desktop-relative mouse information. AFAIK, There currently is no easy way to interact with individual UI elements while the mouse moves. (Because Maui started as Xamarin started as mobile cross-platform code; touch devices don't have concept of cursor being moved around screen.)
A crude hack is to use AbsoluteLayout: position UI elements at exact positions, so you know where they are, then write (Windows-only) code that does your own "detection".
The next level of sophistication would be to write code that traverses a window's "visual tree" of UI elements, to detect what control the mouse is over. Maui must have such logic internally somewhere, to handle touch events. Unless it relies on each platform's UI code to decide that. TBD.
For now, Maui makes sense for apps that can live with a "touch" paradigm, rather than a "desktop" paradigm.
This isn't an answer per say, but as a suggestion you could try and determine when the mouse would be over the VisualElement and then use StateTriggers to actively apply a VisualState.
MAUI Triggers

HoloLens DirectX C# app: Is it possible to show some text on the slate?

I've created my HoloLens application from the "Holographic DirectX 11 App (Universal Windows)" template. When I start the app, it shows a slate (a 2D window) in the HoloLens and I need to place it in the space. Then my app will work as a hologram (in an immersive view).
Before going to the immersive view, I want to check some conditions and show a message to the user, if the application cannot start.
Currently, my app does not have any XAML code.
It uses SharpDX library.
Can I write some text on the slate window?
I understand that this is an old question, but I will answer just in case somebody else needs to do something similar.
There are two possible ways to do that:
1) Perhaps the easiest way is to start your app as a XAML app and then, if everything is alright, to switch to DirectX mode, otherwise write your message on the main XAML window of the app. You could also provide a "Go Holographic" button for the user. There is a very good blog post here by Jonathan Antoine, which explains how to perform the switch between XAML and Holographic mode in detail- it also provides the source code
2) Another solution is to write your text to a DirectX texture and then paint that texture onto a rectangle in the 3D immersive mode. But that one is probably not exactly what you want since you'll need to switch to Holographic mode first and it is a fair amount of work

Combining C#.Net and VTK without ActiViz.Net

I have an assignment which, if I could implement it any way I wanted, would be relatively easy. Alas, there are a number of restrictions on the implementation. I need to create a Visual Studio project which uses C#.Net Windows Presentation Form (WPF) for the GUI and Visualization Toolkit (VTK) with C++ for 3D rendering. If you look that up on-line, you'll soon find something specifically designed for this--ActiViz.Net. Unfortunately, using ActiViz.Net is specifically forbidden.
I've been able to build VTK and the example projects in Visual Studio. I'm still not entirely comfortable with it, but I at least know how to do some basic rendering. WPF doesn't seem too bad on its own. But how do I combine these into a single project, with the GUI influencing the rendering? So for example, I'd use WPF to make a button that said "enlarge sphere". I'd use VTK to render a sphere, either in the same window that had the button, or in a separate window. When the user clicks the button, it will run an event method in C#. And that method will somehow tell the C++ code using VTK to make the sphere larger.
At the moment, I'm not even sure how to make a single project with both of these parts, let alone how to communicate between them. Really, the best I can think of right now is two separate programs, with the GUI program launching the 3D program, and influencing the rendering by writing out a file that the rendering program reads. Not very elegant, I know. Any better ideas?

How can i find the order of the taskbar items in Windows 7?

I would like to establish what is the order of the taskbar items in Windows 7. The reason is that I would like to create an script (written in AutoHotkey or C#) that restore a set of icons to a previous determined order. I wan't to do this because any Virtual Desktop solutions for Windows forget the great and important point of keeping the taskbar item's order, i.e between desktop changes the order of the taskbar items are completely ignored and lost. The reason of why they ignore that fact is maybe because all of them rely in the HIDE/UNHIDE approach, they save what windows are active in any desktop and then between switches they Hide or UnHide the corresponding windows.
I already found a semi solution writted in QT/C++ (Location of app on the Windows 7 Taskbar) that base his function in find the left-upper pixel position of an item based in his color. I don't like that approach because the use of different themes or visual styles would break his functioning. I hope someone has another suggestion. This question differs from that in the link that I'm only interested in the order not in the exact pixel position of any button.
You may want to start with the Windows® API Code Pack for Microsoft® .NET Framework. This API allows you access to several Windows APIs (including certain taskbar functions) from managed code.
However, I'm not certain yet that it allows for functionality regarding the task bar in general vs. a specific application's taskbar entry. I will continue researching this and update if/when I find more information.

How can I write windows 7 desktop gadgets using c# & WPF?

I want to write a desktop gadget that will group icons on my desktop (using c# & WPF).
It will be a docked window that I can drag icons to it and they will stay their. Also there can be couple of this windows.
Where do I begin?
**I saw all the post here about it but I got lost. Please direct me to examples and explanation pages.
To expand on cevik's answer:
You cannot create WPF applications as gadgets BUT you have two options (which aren't as bad as you'd expect).
The reason is that widgets are composed mainly of web pages (HTML) and not executable (*.exe).
The problem of course is that WPF will only work with & produce executables.
First option - Windows API:
When I said you can't what I really meant is you can't use the Windows Vista/7 gadget platform to make your widgets.
However, you can always achieve a similar effect by using the Windows API.
The Windows API will let you do stuff to windows such as making them always on the background of other programs, which sounds to me like ~80% there (The rest would be stuff like making sure your window doesn't get re-sized or minimized, etc.).
Just as a note, the function you'd be looking for to make the window behind all other windows would be SetWindowPos (specifically the second parameter).
However make sure there isn't a library which already implements these stuff because it can be rather difficult (and consist of A LOT of surprises).
Second option - Silverlight
silverlight can be perceived as WPF for the web.
That obviously solves our problem.
However there is a cost to it, as expected.
Silverlight doesn't have all the features WPF has (possibly not all of the .NET framework as-well, not sure about that as I'm not really using it).
However it should be more than enough to get you by so you should definitely check it out.
Once you have your Silverlight application (and webpage) you'll have to create a manifest & install the gadget to your desktop. See here how to do so.
Maybe this will help you.
Template to easily get started on developing a Sideber Gadget using Silverlight 3.0 or 4.0 controls in C#.

Categories