-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control: terminal emulator #21
Comments
Someone at Build told me about a full VT emulator they were about to open source, it is here: Need to wait for the license to be official, then we can use it. |
Working on one as part of XtermSharp: https://github.com/migueldeicaza/XtermSharp the GuiCsConsole has it, will split it out later. |
Hi, it seems @darrenstarr has updated the License to MIT. |
It depends what you’re looking for. I was going for compatibility. So if you look at the UWP example, you’ll find it’s pretty complete. Since I went for maximum compatibility and support all scrolling modes as well as protected areas and characters, it might not be as fast as some other libraries. Once I start my new job at the university, I’ll have time to support it better and if it’s possible to do so, I’ll move to a no-copy model as well as switching to a hierarchal state machine for parsing. This might be an issue since I found a lot of cases (beyond standard VT320) which breaks state machine and cause artifacts. I’m also planning on supporting sixel graphics which may seem silly, but is great for things like math. The greatest weakness in the implementation currently is that I’m not invalidating with time enough control. This is because UWP tends to handle redraws coarsely. I’ll finish ISO2022 (if I remember the number) encoding support as well as X-JIS as soon as I get a chance. Let me know if there’s anything I can do to help. No exaggeration, I wrote most of VtNetCore in a weekend. The rest has been adding more and more features. |
@darrenstarr thank you, currently I only want basic foreground/background colors. Actually I was about to write a simple parser myself and translate the Codes into the corresponding System.Console Commands, but it would be better to re-use a parser done properly ;-) I don't see any Adapter to Console Functionality in your Code though. Do you think I am on the right track using your code for what I want to achieve? Could you give me a Code-hint to start with? PS: to clarify, I know I can enable all this on the Windows10 Console and many Unix Terminals, but I would like to stick with the standard .NET Core Console. |
The XtermParser component of my code isn’t too hard to use for that. It parses everything, but if you implement a controller (inherit it) and implement the functions you want, it should do what you’re looking for. I am on my phone now, but I can talk more intelligently about it when I’m in front of a keyboard. :) I warn against making an oversimplified parser... it’s absolutely amazing how many crazy cases there are. But if you have a controlled data set... it might not be an issue. |
Sorry... responded before reading the whole thing. |
@darrenstarr That's why I'm asking, no worries, I won't, although it seems tempting. |
Look at IVirtualTerminalController. Subclass it, then implement the interesting features. Pass your instance to the DataConsumer class. The DataConsumer is the parser and the IVirtualTerminalController is what it calls as it parses. You just need to push data to the consumer. |
Ah, I see, a very broad Interface, but quite specific and I can leave Methods empty if they don't interest me. Just out of curiosity, what does the concrete VirtualTerminalController do? What is its purpose? Is it the "model" for the Terminal GUI? |
It is the model... but to use the term loosely, it's an observable model. If you look at https://github.com/darrenstarr/VtNetCore.UWP you'll see there's an implementation for UWP and I also had Cocoa working at one point, but I haven't followed up on it. There's also an AvaloniaUI version which is used by AvaloniaStudio. You can leave empty as much as you want. The definitions for some of the items are pretty specific. INCITS 4-1986[R2012] (or ISO6429 C0 & C1 codes) ... Wikipedia does a great job describing them https://en.wikipedia.org/wiki/C0_and_C1_control_codes This is pretty important for how you'll handle backspace, and tabs and such. I doubt you'll need to be concerned with it, but shift in and shift out are pretty confusing, Be mindful of "SetUtf8()", the parser will take care of this itself, but it could be useful to make sure that it's sent at the start of a session. By default, 8-bit values mean ASCII-extended (if I recall correctly). I should probably provide header documentation in IVirtualTerminalController now that I'm pretty sure it's there to stay :) |
public void SetCharacterAttribute(int parameter) This is the function I think you're most interested in. It's the most common method of setting the text color. |
@darrenstarr thanks again, would you care for a pull request with my implementation of a ConsoleTerminal.cs when I'm ready? I have to sort it out with a change I did: I switched to System.ConsoleKey and ConsoleModifiers modifiers. Would you object to that? |
I had no idea there was a .NET Core solution to that... I'm concerned that it will have an issue with IMEs... if I understand correctly, there is no .NET Core mapper for ConsoleKey/ConsoleModifiers and unicode. I'll look into what's being done on Windows Terminal. I am guessing they have a solution for that :) In the meantime, I don't see any drawback to having an alternative. I'm always interested in pull requests. :) |
I created a Core 1.1 Solution and ConsoleKey/ConsoleModifiers were available. What are IMEs? |
Input method editors. If you were to watch a person type in Korean for example, they have the same key codes as we have, but each key has a different meaning than ours do. As they type more, the characters combine to create more complex characters. Of course at this time, I don't have support for complex scripts, but I write in Norwegian, Danish, Swedish and Spanish quite often. When I switch between keyboard layouts the key codes for each button don't change, but they need to be interpretted differently. For example ';' and 'ø' are the same key code using ConsoleKey on my keyboard depending on which IME I'm using. Handwriting and voice input should also be considered. Surprisingly, at Opera (back when I was a developer there), I think we used 2000+ hours to get basic support for keyboard input as such. Windows has translation tools built in to deal with that issue though. I'll have to read more on ECMA-48 to better understand how to support internationalization. But for now, the method I'm using works for latin scripts. |
ping... @SpocWeb is there anything I can help you with? Or did you decide my code was so horrible you abandoned it? :) |
No, sorry, I was busy. Now I'm fighting conflicting private and business git credentials... |
Well, I am biased, so I would recommend my terminal and will eventually bundle it here, but it is really up to you. |
I thought so ;-) would do the same, but Darren's solution seemed much more complete, so I adapted it. |
I’m teaching all week (and next) so I’ll handle the day pull request after :) Thanks! And Miguel, I am biased too :) But, if you started before me, I would have extended yours instead. As for Microsoft Terminal... it is beautiful and those guys are really working wonders. It was a real shame they chose to kill portability by making it C++. I plan to port their DirectX view when I can find the time. I am a little concerned that they are basing their state machine on an antiquated VT520 doc. And I’m a little worried that their line wrapping logic could keep them from implementing protected regions without some considerable refactoring. Either way, my code, Miguel’s and Richard’s team’s are all really good and it’s fantastic that we’re finally getting proper terminal support on Windows in the open source :) |
XtermSharp now contains a gui.cs terminal emulator: https://github.com/migueldeicaza/XtermSharp/tree/master/GuiCsHost |
Did you implement sixel? If so I would love to give it a spin. :) |
Hey Miguel,
Long time, no hear (I abandoned twitter), I hope all is well.
I did start working towards implementing it, but was side tracked because I needed something to accurately verify against and xterm seemed to discontinue support for it and frankly, I didn’t have much luck getting it working on vtstar.
I now have a Dec VT320 on my desk which I haven’t had a chance to mess around with. If you’re up for implementing it on your side, I’m certainly interested in assisting even if only to write unit tests for it.
I’ve been through the docs and it seems pretty straight forward. The main concern is that handling scroll-back gracefully looks challenging and making the graphics ephemeral is less than interesting. If only for math purposes, you don’t want the buffer the be dropped just because you scroll.
If you come up with a reasonable solution for how to support a frame buffer (architecturally) which addresses those issues, I haven’t invested the time in it and I have some hairbrained ideas, I’d love to hear what you come up with.
Also, I think the biggest concern I had with doing it was that I wanted to make sure that it supported high-DPI gracefully.
I don’t know if you have a proper DEC terminal to test against, but if you want, I can aim a webcam at the VT320, plug it into a Raspberry Pi and you can have a shell account to push to /dev/ttySx on.
Let me know if any of this would help 😊
* Darren
…________________________________
From: Autumn Lamonte ***@***.***>
Sent: Thursday, February 3, 2022 5:15:43 PM
To: migueldeicaza/gui.cs ***@***.***>
Cc: Darren Starr ***@***.***>; Mention ***@***.***>
Subject: Re: [migueldeicaza/gui.cs] Control: terminal emulator (#21)
@darrenstarr<https://github.com/darrenstarr>
I’m also planning on supporting sixel graphics which may seem silly, but is great for things like math.
Did you implement sixel? If so I would love to give it a spin. :)
—
Reply to this email directly, view it on GitHub<#21 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACQKO3WSYCDDN6VP4GSHPO3UZKS27ANCNFSM4ELJGAGQ>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I did an implementation using XtermSharp, which could use an update: https://github.com/migueldeicaza/XtermSharp/tree/master/GuiCsHost I think the major issue is whether the code above gets merged into gui.cs (and thus takes a dependency on XtermSharp), or if XtermSharp takes a dependency on gui.cs, or if I split this out so neither gui.cs or XtermSharp take dependencies, and the terminal emulator is standalone. |
As for Sixel support: I implemented Sixel support (and a bunch of other graphic APIs) in my Swift version of the terminal emulator, and it could be easily backported to XtermSharp. XtermSharp could get a big boost by bringing all the changes I did to SwiftTerm, I kept an issue to track those here: |
Would there be a way to test sixel at this time? I have an interest in image-supporting terminals, and if another embeddable terminal widget can now do it I would love to advertise it. :) |
Someone would need to port the code from Swift to C#, I do not currently have much time to devote to that backport. That said, you could try SwiftTerm which supports assorted image formats (including sixel) |
…tting (#3241) * Removed resharper settings from editorconfig * Remove constructors with frame parameters from Button class. * Remove constructors with frame parameters from CheckBox class. * Cleanup code. * Remove constructors with frame parameters from ComboBox class. * @BDisp Remove constructors with frame parameters from FrameView class. * Remove constructors with frame parameters from Label class. * Remove constructors with frame parameters from ListView class. * Remove constructors with frame parameters from ScrollBarView class. * Remove constructors with frame parameters from ScrollView class. * Remove namespace braces. * Cleanup code. * Cleanup code. * Cleanup code. * Remove constructors with frame parameters from TextField class. * Remove constructors with frame parameters from TimeField class. * Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty. * Remove constructors with frame parameters from Toplevel class. * Remove constructors with frame parameters from Window class. * Fix merge errors. * Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty." This reverts commit cf9c24b. * Revert unit test. * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980) * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame * Trying fix this unit test that sometimes fail. * Fixes #2983. View need a alternative DrawFrame for the v2. * Use new DrawFrame method. * Change _lines field to Lines property. * Add TabWindow unit test. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Revert "Change _lines field to Lines property." This reverts commit ab6c5f3. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Force render immediately instead of join. * I will never rely on zero-location-based unit test again. * Fix TestTreeViewColor unit test fail. * Using location of 3 to avoid be divisible by 2 and so avoiding bugs. * Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs." This reverts commit dd3df13. * Revert "I will never rely on zero-location-based unit test again." This reverts commit 62adf6f. * Revert "Fix newline conflict errors." This reverts commit 4acf726. * Revert "Add more unit tests to LineCanvas." This reverts commit 66bc6f5. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit 680ba26. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit 69a7f17. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commit dade9fd. * Reverting this changes to start a new one. * Add horizontal and vertical support for combining glyphs. * Fix text and auto size behavior. * Add TabWidth property. * Add unit test for WordWrap. * Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false. * Using Frame to force read from the get method. * Fix some issues with AutoSize and ForceValidatePosDim. * Fixing broken unit tests. * Restoring code I've broken. * Removing forgotten code. * Only LayoutStyle.Computed can change the Frame. * DateField and TimeField depends on LayoutStyle.Computed. * Fix unit tests related with LayoutStyle. * Implements tabs, left and right arrows as View. * Draws a minimum full border. * Adds missing XML parameter. * Adds assert tests for Frame. * Removes duplicates InlineData. * Adds more unit tests for minimum full border without Left and Right thickness. * Trying to fix the TestTreeViewColor unit test fail. * Prevents a user to set TextDirection to -1. * Prevents any invalid TextDirection value. * Removes (TextDirection)(-1). * Removes unnecessary TextDirection initialization. * Removes LayoutStyle. * Fixing unit tests with border. * Trying to fix TestTreeViewColor again. * Revert "Trying to fix TestTreeViewColor again." This reverts commit c2efa8e. * Trying to fix TestTreeViewColor again. * Fix merge errors. * Fix merge errors. * Restoring unit test. * Restores the right XML comment. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Only call OnResizeNeeded if it's LayoutStyle.Computed. * Fix merge errors. * Fix merge errors. * Fix unit tests fail. * Reformat. * Again. * Rename to OnDrawAdornments. * Fix failing unit tests. * Reduces indentation and cleanup code. * Cleanup code. * Fix bug done when cleanup. * Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent. * Removes Tab constructor parameters. --------- Co-authored-by: Tig <[email protected]> * Fix merge errors. * Remove constructors with parameters from Button. * Remove parenthesis on objects initializers from Button. * Remove constructors with parameters from CheckBox. * Remove parenthesis on objects initializers from CheckBox. * Remove constructors with parameters from ComboBox. * Remove constructors with parameters from FrameView. * Remove parenthesis on objects initializers from FrameView. * Initial commit * Renamed Direction enum for clarity in refactoring unit tests * Moved nav tests to NavigationTests * Moved view tests around * Cleaning up TextFormatter and View.AutoSize code * Fixed latent TextFormatter bug with \n * removed Application dependency on some autosize unit tests * Fixed Label tests to deal with auotsize overriding height/width * Fixed more label tests. WIP * Fixed all places where AutoSize = happend after setting Dims * Started adding new primitive View.Text tests * Code comments * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized. * Changes needed for unit tests pass on remove parameters constructors from the Label class. * Remove constructors with parameters from Label. * Remove parenthesis on objects initializers from Label. * Prefix private fields with underscore. * Renamed to MaxLength. * Remove constructors with parameters from ListView. * MakeWrapper not needed anymore. * Remove parenthesis on objects initializers from ListView. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Fixed messagebox * Remove constructors with parameters from ScrollBarView and ScrollView. * Remove parenthesis on objects initializers from ScrollBarView and ScrollView. * Cleanup code. * Fix merge errors. * Add empty dotsettings for solution and projects. * Set ReSharper language analysis level for projects to C#12 * Make ReSharper consider itself the boss for style * Add rule to enforce property backing fields above the property * Disable auto-detection of naming rules so ReSharper doesn't change them by itself * Don't let someone's VS settings override the indent settings * Explicitly set tab width to 4 spaces and force spaces. * Rules to keep various multi-line constructs aligned within themselves * Curly brace rules (Using K&R style, per current project spec) * Blank line rules Mostly to add breaks in various situations, and also to enforce max of 1 blank line. * Increase auto-wrap to 160 from default of 120 * Line break at end of all files, to make Unixy systems happy * Keep attributes on their own lines except for methods and records that are themselves single-line * Increase attribute auto-wrap to 60 from default of 38 * Wrap/chop rules for long method signatures and record declarations Chop if either already multi-line or if over 8 parameters. Chop AFTER the left paren and BEFORE the first parameter. * Chop rules for generics For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment. * Always enforce enum members on their own lines * One-line functions completely on one line They're usually expression-bodied anyway, here, so this is almost irrelevant * Keep control flow statements on their own lines * Follow same chop rules for method invocation as method declaration * Chop long or multi-line method chains or patterns * Wrap rules for binary operators Operator at beginning of new lines Auto-chop if long or already multi-line * Spaces between keywords and their opening parentheses * Add file layout rules for organization of reorderable items like fields, properties, etc. Ugly XML, so load it up in the UI to look at it It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping. * Deconstructors use per-member types * Use keywords for built-in types and increase severity of inspection for violations Also apply to IntPtr and similar, which should now be nint and similar * Apply syntax style on completion. * Use var when evident for built-in and simple types, but not elsewhere * Increase severity for some minor redundancy and clarity inspections * Enforce braces always required for blocks, and treat as error * Warn if a local function is not statement-bodied * Increase various inspection severities IF Condition => Severity: Attributes not wrapped property => Suggestion Constructors expression-bodied => Error default doesn't have type when it isn't clear => suggestion Namespaces not file-scoped => error Methods not statement-bodied => hint Null check pattern not the object property pattern => Error * Adjust preference order of null check patterns to make object pattern highest * XmlDoc rules to keep tags and contents aligned and wrapped * Add a few custom profiles for code cleanup and make the full profile default * Remove parts for languages not used in this solution * copied in v2_develop changes * Merged v2_develop * Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests * TextFormatter.Lines -> GetLines () * Let ReSharper know we intend to localize things * TextFormatter code cleanup * copied in v2_develop changes * Merged v2_develop * Spaces aren't wanted here either. * Fix merge errors. * Fixes ContentBottomRightCorner related with #3211 (comment) * Remove constructors with parameters from ContextMenu. * Remove commented code. * Remove constructors with parameters from OpenDialog. * Remove constructors with parameters from SaveDialog. * Remove constructors with parameters from TextField. * Remove constructors with parameters from TimeField. * Fix unit test. * Remove unnecessary SetInitialProperties method. * Remove unnecessary SetInitialProperties method. * Remove parenthesis on objects initializers from Toplevel and Window. * Remove constructors with parameters from RadioGroup. * Remove constructors with parameters from TextView. * Remove constructors with parameters from MenuBar. * TEMPORARY: Turn everything that was set to error down to warning or lower * Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled. * Remove constructors with parameters from Menu. * Remove constructors with parameters from View. * Change constructor to internal because is mainly useful for testing. * ReSharper Cleanup Code. * Added format only r# config * Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. * Remove constructors with parameters from Dialog. * Remove constructors with parameters from TextValidateField. * Fixes #3224 (comment) * Fixes #3225. Press CursorDown on TabView doesn't move to the next view. * Fixes #3229. TextFormatter should have a FillRemaining property. * Testing formatting merge in bdisp * Testing formatting merge * Testing formatting merge bdisp * Testing formatting merge 2 * xmldoc format * R# Full Code Cleanup * R# Full Code Cleanup2 * R# Full Code Cleanup2 * Merged! But broke tests * Refixing... * Refixed DrawTests * Refixed ViewTests * Refixed Text Tests * Refixed more unit tests * Refixed scenarios * Refixed rest of scenarios * Refixed ViewsTests * Refixed rest of tests. All unit tests pass again! * Fixed warnings * Updated R# version. Added new code cleanup settings * Applied latest code cleanup to solution * Another code cleanup pass * Tweaked r# settings. .editorconfig now matches. * r# else on separate line * r# - update * r# - full solution * test commit * test commit * test commit * Removed extra profiles * Full cleanup following cleaning up profiles * Null checking pattern rules/inspections * Tabs and extra whitespace are evil * Attributes on their own lines * Code layout rules to put fields first and to put backing fields with their properties * Merged v2_develop * Full cleanup following dodexahedron's PR * Told ReSharper to write its settings to the .editorconfig, to sync them up * Update CONTRIBUTING.md for new formatting rules and link some bullets for convenience #21 * Fix anchor Signed-off-by: dodexahedron <[email protected]> * Tweak bullet indent for clarity Signed-off-by: dodexahedron <[email protected]> --------- Signed-off-by: dodexahedron <[email protected]> Co-authored-by: Tig Kindel <[email protected]> Co-authored-by: Tig Kindel <[email protected]> Co-authored-by: BDisp <[email protected]>
Can use the work-in-progress XtermSharp and mono/pty-sharp
The text was updated successfully, but these errors were encountered: