mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
* 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 commitcf9c24b846. * 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 commitab6c5f3094. * 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 commitdd3df135d8. * Revert "I will never rely on zero-location-based unit test again." This reverts commit62adf6f285. * Revert "Fix newline conflict errors." This reverts commit4acf72612d. * Revert "Add more unit tests to LineCanvas." This reverts commit66bc6f514e. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit680ba264e1. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit69a7f17f19. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commitdade9fd767. * 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 commitc2efa8e42e. * 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 <tig@users.noreply.github.com> * 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 https://github.com/gui-cs/Terminal.Gui/issues/3211#issue-2098878820 * 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 https://github.com/gui-cs/Terminal.Gui/issues/3224#issuecomment-1924096038 * 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 --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
748 lines
30 KiB
C#
748 lines
30 KiB
C#
//
|
|
// TODO:
|
|
// * FindNCurses needs to remove the old probing code
|
|
// * Removal of that proxy code
|
|
// * Need to implement reading pointers with the new API
|
|
// * Can remove the manual Dlopen features
|
|
// * initscr() diagnostics based on DLL can be fixed
|
|
//
|
|
// binding.cs.in: Core binding for curses.
|
|
//
|
|
// This file attempts to call into ncurses without relying on Mono's
|
|
// dllmap, so it will work with .NET Core. This means that it needs
|
|
// two sets of bindings, one for "ncurses" which works on OSX, and one
|
|
// that works against "libncursesw.so.5" which is what you find on
|
|
// assorted Linux systems.
|
|
//
|
|
// Additionally, I do not want to rely on an external native library
|
|
// which is why all this pain to bind two separate ncurses is here.
|
|
//
|
|
// Authors:
|
|
// Miguel de Icaza (miguel.de.icaza@gmail.com)
|
|
//
|
|
// Copyright (C) 2007 Novell (http://www.novell.com)
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
|
|
using System.Runtime.InteropServices;
|
|
using Terminal.Gui;
|
|
|
|
namespace Unix.Terminal;
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
public partial class Curses
|
|
{
|
|
// We encode ESC + char (what Alt-char generates) as 0x2000 + char
|
|
public const int KeyAlt = 0x2000;
|
|
private static nint curses_handle, curscr_ptr, lines_ptr, cols_ptr;
|
|
|
|
// If true, uses the DllImport into "ncurses", otherwise "libncursesw.so.5"
|
|
//static bool use_naked_driver;
|
|
private static UnmanagedLibrary curses_library;
|
|
private static int lines, cols;
|
|
private static Window main_window;
|
|
private static NativeMethods methods;
|
|
private static char [] r = new char [1];
|
|
private static nint stdscr;
|
|
public static int ColorPairs => methods.COLOR_PAIRS ();
|
|
|
|
public static int Cols
|
|
{
|
|
get => cols;
|
|
internal set =>
|
|
|
|
// For unit tests
|
|
cols = value;
|
|
}
|
|
|
|
public static bool HasColors => methods.has_colors ();
|
|
|
|
public static int Lines
|
|
{
|
|
get => lines;
|
|
internal set =>
|
|
|
|
// For unit tests
|
|
lines = value;
|
|
}
|
|
|
|
//
|
|
// Have to wrap the native addch, as it can not
|
|
// display unicode characters, we have to use addstr
|
|
// for that. but we need addch to render special ACS
|
|
// characters
|
|
//
|
|
public static int addch (int ch)
|
|
{
|
|
if (ch < 127 || ch > 0xffff)
|
|
{
|
|
return methods.addch (ch);
|
|
}
|
|
|
|
var c = (char)ch;
|
|
|
|
return addwstr (new string (c, 1));
|
|
}
|
|
|
|
public static int addstr (string format, params object [] args)
|
|
{
|
|
string s = string.Format (format, args);
|
|
|
|
return addwstr (s);
|
|
}
|
|
|
|
public static int addwstr (string s) { return methods.addwstr (s); }
|
|
public static int attroff (int attrs) { return methods.attroff (attrs); }
|
|
|
|
//static public int wechochar (IntPtr win, int ch) => methods.wechochar (win, ch);
|
|
public static int attron (int attrs) { return methods.attron (attrs); }
|
|
public static int attrset (int attrs) { return methods.attrset (attrs); }
|
|
public static int cbreak () { return methods.cbreak (); }
|
|
|
|
//
|
|
// Returns true if the window changed since the last invocation, as a
|
|
// side effect, the Lines and Cols properties are updated
|
|
//
|
|
public static bool CheckWinChange ()
|
|
{
|
|
int l, c;
|
|
|
|
console_sharp_get_dims (out l, out c);
|
|
|
|
if (l < 1)
|
|
{
|
|
l = 1;
|
|
}
|
|
|
|
if (l != lines || c != cols)
|
|
{
|
|
lines = l;
|
|
cols = c;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static int clearok (nint win, bool bf) { return methods.clearok (win, bf); }
|
|
public static int COLOR_PAIRS () { return methods.COLOR_PAIRS (); }
|
|
public static int curs_set (int visibility) { return methods.curs_set (visibility); }
|
|
|
|
public static string curses_version ()
|
|
{
|
|
nint v = methods.curses_version ();
|
|
|
|
return $"{Marshal.PtrToStringAnsi (v)}, {curses_library.LibraryPath}";
|
|
}
|
|
|
|
public static int def_prog_mode () { return methods.def_prog_mode (); }
|
|
public static int def_shell_mode () { return methods.def_shell_mode (); }
|
|
public static int doupdate () { return methods.doupdate (); }
|
|
public static int echo () { return methods.echo (); }
|
|
|
|
//static public int addch (int ch) => methods.addch (ch);
|
|
public static int echochar (int ch) { return methods.echochar (ch); }
|
|
|
|
//
|
|
// The proxy methods to call into each version
|
|
//
|
|
public static int endwin () { return methods.endwin (); }
|
|
public static int flushinp () { return methods.flushinp (); }
|
|
public static int get_wch (out int sequence) { return methods.get_wch (out sequence); }
|
|
public static int getch () { return methods.getch (); }
|
|
public static uint getmouse (out MouseEvent ev) { return methods.getmouse (out ev); }
|
|
public static int halfdelay (int t) { return methods.halfdelay (t); }
|
|
public static bool has_colors () { return methods.has_colors (); }
|
|
public static void idcok (nint win, bool bf) { methods.idcok (win, bf); }
|
|
public static int idlok (nint win, bool bf) { return methods.idlok (win, bf); }
|
|
public static void immedok (nint win, bool bf) { methods.immedok (win, bf); }
|
|
public static int init_pair (short pair, short f, short b) { return methods.init_pair (pair, f, b); }
|
|
|
|
/// <summary>
|
|
/// The init_pair routine changes the definition of a color-pair.It takes three arguments: the number of the
|
|
/// color-pair to be changed, the fore- ground color number, and the background color number.For portable ap-
|
|
/// plications: o The first argument must be a legal color pair value.If default colors are used (see
|
|
/// use_default_colors(3x)) the upper limit is ad- justed to allow for extra pairs which use a default color in fore-
|
|
/// ground and/or background. o The second and third arguments must be legal color values. If the color-pair was
|
|
/// previously initialized, the screen is refreshed and all occurrences of that color-pair are changed to the new
|
|
/// defini- tion. As an extension, ncurses allows you to set color pair 0 via the as- sume_default_colors (3x)
|
|
/// routine, or to specify the use of default col- ors (color number -1) if you first invoke the use_default_colors
|
|
/// (3x) routine.
|
|
/// </summary>
|
|
/// <param name="pair"></param>
|
|
/// <param name="foreground"></param>
|
|
/// <param name="background"></param>
|
|
/// <returns></returns>
|
|
public static int InitColorPair (short pair, short foreground, short background) { return methods.init_pair (pair, foreground, background); }
|
|
|
|
public static Window initscr ()
|
|
{
|
|
setlocale (LC_ALL, "");
|
|
FindNCurses ();
|
|
|
|
// Prevents the terminal from being locked after exiting.
|
|
reset_shell_mode ();
|
|
|
|
main_window = new Window (methods.initscr ());
|
|
|
|
try
|
|
{
|
|
console_sharp_get_dims (out lines, out cols);
|
|
}
|
|
catch (DllNotFoundException)
|
|
{
|
|
endwin ();
|
|
|
|
Console.Error.WriteLine (
|
|
"Unable to find the @MONO_CURSES@ native library\n"
|
|
+ "this is different than the managed mono-curses.dll\n\n"
|
|
+ "Typically you need to install to a LD_LIBRARY_PATH directory\n"
|
|
+ "or DYLD_LIBRARY_PATH directory or run /sbin/ldconfig"
|
|
);
|
|
Environment.Exit (1);
|
|
}
|
|
|
|
//Console.Error.WriteLine ($"using curses {Curses.curses_version ()}");
|
|
|
|
return main_window;
|
|
}
|
|
|
|
public static int intrflush (nint win, bool bf) { return methods.intrflush (win, bf); }
|
|
public static bool is_term_resized (int lines, int columns) { return methods.is_term_resized (lines, columns); }
|
|
|
|
public static int IsAlt (int key)
|
|
{
|
|
if ((key & KeyAlt) != 0)
|
|
{
|
|
return key & ~KeyAlt;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static bool isendwin () { return methods.isendwin (); }
|
|
public static int keypad (nint win, bool bf) { return methods.keypad (win, bf); }
|
|
public static int leaveok (nint win, bool bf) { return methods.leaveok (win, bf); }
|
|
public static int meta (nint win, bool bf) { return methods.meta (win, bf); }
|
|
public static int mouseinterval (int interval) { return methods.mouseinterval (interval); }
|
|
|
|
public static Event mousemask (Event newmask, out Event oldmask)
|
|
{
|
|
nint e;
|
|
var ret = (Event)methods.mousemask ((nint)newmask, out e);
|
|
oldmask = (Event)e;
|
|
|
|
return ret;
|
|
}
|
|
|
|
public static int move (int line, int col) { return methods.move (line, col); }
|
|
|
|
public static int mvaddch (int y, int x, int ch)
|
|
{
|
|
if (ch < 127 || ch > 0xffff)
|
|
{
|
|
return methods.mvaddch (y, x, ch);
|
|
}
|
|
|
|
var c = (char)ch;
|
|
|
|
return mvaddwstr (y, x, new string (c, 1));
|
|
}
|
|
|
|
public static int mvaddwstr (int y, int x, string s) { return methods.mvaddwstr (y, x, s); }
|
|
public static int mvgetch (int y, int x) { return methods.mvgetch (y, x); }
|
|
public static int nl () { return methods.nl (); }
|
|
public static int nocbreak () { return methods.nocbreak (); }
|
|
public static int noecho () { return methods.noecho (); }
|
|
public static int nonl () { return methods.nonl (); }
|
|
public static void noqiflush () { methods.noqiflush (); }
|
|
public static int noraw () { return methods.noraw (); }
|
|
public static int notimeout (nint win, bool bf) { return methods.notimeout (win, bf); }
|
|
public static void qiflush () { methods.qiflush (); }
|
|
public static int raw () { return methods.raw (); }
|
|
public static int redrawwin (nint win) { return methods.redrawwin (win); }
|
|
public static int refresh () { return methods.refresh (); }
|
|
public static int reset_prog_mode () { return methods.reset_prog_mode (); }
|
|
public static int reset_shell_mode () { return methods.reset_shell_mode (); }
|
|
public static int resetty () { return methods.resetty (); }
|
|
public static int resize_term (int lines, int columns) { return methods.resize_term (lines, columns); }
|
|
public static int resizeterm (int lines, int columns) { return methods.resizeterm (lines, columns); }
|
|
public static int savetty () { return methods.savetty (); }
|
|
public static int scrollok (nint win, bool bf) { return methods.scrollok (win, bf); }
|
|
public static int set_escdelay (int size) { return methods.set_escdelay (size); }
|
|
|
|
[DllImport ("libc")]
|
|
public static extern int setlocale (int cate, [MarshalAs (UnmanagedType.LPStr)] string locale);
|
|
|
|
public static int setscrreg (int top, int bot) { return methods.setscrreg (top, bot); }
|
|
public static int start_color () { return methods.start_color (); }
|
|
public static int StartColor () { return methods.start_color (); }
|
|
public static int timeout (int delay) { return methods.timeout (delay); }
|
|
public static int typeahead (nint fd) { return methods.typeahead (fd); }
|
|
public static int ungetch (int ch) { return methods.ungetch (ch); }
|
|
public static uint ungetmouse (ref MouseEvent ev) { return methods.ungetmouse (ref ev); }
|
|
public static int use_default_colors () { return methods.use_default_colors (); }
|
|
public static void use_env (bool f) { methods.use_env (f); }
|
|
|
|
// TODO: Upgrade to ncurses 6.1 and use the extended version
|
|
//public static int InitExtendedPair (int pair, int foreground, int background) => methods.init_extended_pair (pair, foreground, background);
|
|
public static int UseDefaultColors () { return methods.use_default_colors (); }
|
|
public static int waddch (nint win, int ch) { return methods.waddch (win, ch); }
|
|
public static int wmove (nint win, int line, int col) { return methods.wmove (win, line, col); }
|
|
|
|
//static public int wredrawwin (IntPtr win, int beg_line, int num_lines) => methods.wredrawwin (win, beg_line, num_lines);
|
|
public static int wnoutrefresh (nint win) { return methods.wnoutrefresh (win); }
|
|
public static int wrefresh (nint win) { return methods.wrefresh (win); }
|
|
public static int wsetscrreg (nint win, int top, int bot) { return methods.wsetscrreg (win, top, bot); }
|
|
public static int wtimeout (nint win, int delay) { return methods.wtimeout (win, delay); }
|
|
internal static nint console_sharp_get_curscr () { return Marshal.ReadIntPtr (curscr_ptr); }
|
|
|
|
internal static void console_sharp_get_dims (out int lines, out int cols)
|
|
{
|
|
lines = Marshal.ReadInt32 (lines_ptr);
|
|
cols = Marshal.ReadInt32 (cols_ptr);
|
|
|
|
//int cmd;
|
|
//if (UnmanagedLibrary.IsMacOSPlatform) {
|
|
// cmd = TIOCGWINSZ_MAC;
|
|
//} else {
|
|
// cmd = TIOCGWINSZ;
|
|
//}
|
|
|
|
//if (ioctl (1, cmd, out winsize ws) == 0) {
|
|
// lines = ws.ws_row;
|
|
// cols = ws.ws_col;
|
|
|
|
// if (lines == Lines && cols == Cols) {
|
|
// return;
|
|
// }
|
|
|
|
// resizeterm (lines, cols);
|
|
//} else {
|
|
// lines = Lines;
|
|
// cols = Cols;
|
|
//}
|
|
}
|
|
|
|
internal static nint console_sharp_get_stdscr () { return stdscr; }
|
|
|
|
internal static nint read_static_ptr (string key)
|
|
{
|
|
nint ptr = get_ptr (key);
|
|
|
|
return Marshal.ReadIntPtr (ptr);
|
|
}
|
|
|
|
private static void FindNCurses ()
|
|
{
|
|
LoadMethods ();
|
|
curses_handle = methods.UnmanagedLibrary.NativeLibraryHandle;
|
|
|
|
stdscr = read_static_ptr ("stdscr");
|
|
curscr_ptr = get_ptr ("curscr");
|
|
lines_ptr = get_ptr ("LINES");
|
|
cols_ptr = get_ptr ("COLS");
|
|
}
|
|
|
|
private static nint get_ptr (string key)
|
|
{
|
|
nint ptr = curses_library.LoadSymbol (key);
|
|
|
|
if (ptr == nint.Zero)
|
|
{
|
|
throw new Exception ("Could not load the key " + key);
|
|
}
|
|
|
|
return ptr;
|
|
}
|
|
|
|
//[DllImport ("libc")]
|
|
//public extern static int ioctl (int fd, int cmd, out winsize argp);
|
|
|
|
private static void LoadMethods ()
|
|
{
|
|
string [] libs = UnmanagedLibrary.IsMacOSPlatform
|
|
? new [] { "libncurses.dylib" }
|
|
: new [] { "libncursesw.so.6", "libncursesw.so.5" };
|
|
var attempts = 1;
|
|
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
curses_library = new UnmanagedLibrary (libs, false);
|
|
methods = new NativeMethods (curses_library);
|
|
|
|
break;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (attempts == 1)
|
|
{
|
|
attempts++;
|
|
|
|
(int exitCode, string result) =
|
|
ClipboardProcessRunner.Bash ("cat /etc/os-release", waitForOutput: true);
|
|
|
|
if (exitCode == 0 && result.Contains ("opensuse"))
|
|
{
|
|
libs [0] = "libncursesw.so.5";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw ex.GetBaseException ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//[StructLayout (LayoutKind.Sequential)]
|
|
//public struct winsize {
|
|
// public ushort ws_row;
|
|
// public ushort ws_col;
|
|
// public ushort ws_xpixel; /* unused */
|
|
// public ushort ws_ypixel; /* unused */
|
|
//};
|
|
|
|
[StructLayout (LayoutKind.Sequential)]
|
|
public struct MouseEvent
|
|
{
|
|
public short ID;
|
|
public int X, Y, Z;
|
|
public Event ButtonState;
|
|
}
|
|
}
|
|
|
|
#pragma warning disable RCS1102 // Make class static.'
|
|
internal class Delegates
|
|
{
|
|
#pragma warning restore RCS1102 // Make class static.
|
|
#pragma warning disable CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
|
|
public delegate nint initscr ();
|
|
|
|
public delegate int endwin ();
|
|
|
|
public delegate bool isendwin ();
|
|
|
|
public delegate int cbreak ();
|
|
|
|
public delegate int nocbreak ();
|
|
|
|
public delegate int echo ();
|
|
|
|
public delegate int noecho ();
|
|
|
|
public delegate int halfdelay (int t);
|
|
|
|
public delegate int raw ();
|
|
|
|
public delegate int noraw ();
|
|
|
|
public delegate void noqiflush ();
|
|
|
|
public delegate void qiflush ();
|
|
|
|
public delegate int typeahead (nint fd);
|
|
|
|
public delegate int timeout (int delay);
|
|
|
|
public delegate int wtimeout (nint win, int delay);
|
|
|
|
public delegate int notimeout (nint win, bool bf);
|
|
|
|
public delegate int keypad (nint win, bool bf);
|
|
|
|
public delegate int meta (nint win, bool bf);
|
|
|
|
public delegate int intrflush (nint win, bool bf);
|
|
|
|
public delegate int clearok (nint win, bool bf);
|
|
|
|
public delegate int idlok (nint win, bool bf);
|
|
|
|
public delegate void idcok (nint win, bool bf);
|
|
|
|
public delegate void immedok (nint win, bool bf);
|
|
|
|
public delegate int leaveok (nint win, bool bf);
|
|
|
|
public delegate int wsetscrreg (nint win, int top, int bot);
|
|
|
|
public delegate int scrollok (nint win, bool bf);
|
|
|
|
public delegate int nl ();
|
|
|
|
public delegate int nonl ();
|
|
|
|
public delegate int setscrreg (int top, int bot);
|
|
|
|
public delegate int refresh ();
|
|
|
|
public delegate int doupdate ();
|
|
|
|
public delegate int wrefresh (nint win);
|
|
|
|
public delegate int redrawwin (nint win);
|
|
|
|
//public delegate int wredrawwin (IntPtr win, int beg_line, int num_lines);
|
|
public delegate int wnoutrefresh (nint win);
|
|
|
|
public delegate int move (int line, int col);
|
|
|
|
public delegate int curs_set (int visibility);
|
|
|
|
public delegate int addch (int ch);
|
|
|
|
public delegate int echochar (int ch);
|
|
|
|
public delegate int mvaddch (int y, int x, int ch);
|
|
|
|
public delegate int addwstr ([MarshalAs (UnmanagedType.LPWStr)] string s);
|
|
|
|
public delegate int mvaddwstr (int y, int x, [MarshalAs (UnmanagedType.LPWStr)] string s);
|
|
|
|
public delegate int wmove (nint win, int line, int col);
|
|
|
|
public delegate int waddch (nint win, int ch);
|
|
|
|
public delegate int attron (int attrs);
|
|
|
|
public delegate int attroff (int attrs);
|
|
|
|
public delegate int attrset (int attrs);
|
|
|
|
public delegate int getch ();
|
|
|
|
public delegate int get_wch (out int sequence);
|
|
|
|
public delegate int ungetch (int ch);
|
|
|
|
public delegate int mvgetch (int y, int x);
|
|
|
|
public delegate bool has_colors ();
|
|
|
|
public delegate int start_color ();
|
|
|
|
public delegate int init_pair (short pair, short f, short b);
|
|
|
|
public delegate int use_default_colors ();
|
|
|
|
public delegate int COLOR_PAIRS ();
|
|
|
|
public delegate uint getmouse (out Curses.MouseEvent ev);
|
|
|
|
public delegate uint ungetmouse (ref Curses.MouseEvent ev);
|
|
|
|
public delegate int mouseinterval (int interval);
|
|
|
|
public delegate nint mousemask (nint newmask, out nint oldMask);
|
|
|
|
public delegate bool is_term_resized (int lines, int columns);
|
|
|
|
public delegate int resize_term (int lines, int columns);
|
|
|
|
public delegate int resizeterm (int lines, int columns);
|
|
|
|
public delegate void use_env (bool f);
|
|
|
|
public delegate int flushinp ();
|
|
|
|
public delegate int def_prog_mode ();
|
|
|
|
public delegate int def_shell_mode ();
|
|
|
|
public delegate int reset_prog_mode ();
|
|
|
|
public delegate int reset_shell_mode ();
|
|
|
|
public delegate int savetty ();
|
|
|
|
public delegate int resetty ();
|
|
|
|
public delegate int set_escdelay (int size);
|
|
|
|
public delegate nint curses_version ();
|
|
}
|
|
|
|
internal class NativeMethods
|
|
{
|
|
public readonly Delegates.addch addch;
|
|
public readonly Delegates.addwstr addwstr;
|
|
public readonly Delegates.attroff attroff;
|
|
|
|
//public readonly Delegates.wechochar wechochar;
|
|
public readonly Delegates.attron attron;
|
|
public readonly Delegates.attrset attrset;
|
|
public readonly Delegates.cbreak cbreak;
|
|
public readonly Delegates.clearok clearok;
|
|
public readonly Delegates.COLOR_PAIRS COLOR_PAIRS;
|
|
public readonly Delegates.curs_set curs_set;
|
|
public readonly Delegates.curses_version curses_version;
|
|
public readonly Delegates.def_prog_mode def_prog_mode;
|
|
public readonly Delegates.def_shell_mode def_shell_mode;
|
|
public readonly Delegates.doupdate doupdate;
|
|
public readonly Delegates.echo echo;
|
|
public readonly Delegates.echochar echochar;
|
|
public readonly Delegates.endwin endwin;
|
|
public readonly Delegates.flushinp flushinp;
|
|
public readonly Delegates.get_wch get_wch;
|
|
public readonly Delegates.getch getch;
|
|
public readonly Delegates.getmouse getmouse;
|
|
public readonly Delegates.halfdelay halfdelay;
|
|
public readonly Delegates.has_colors has_colors;
|
|
public readonly Delegates.idcok idcok;
|
|
public readonly Delegates.idlok idlok;
|
|
public readonly Delegates.immedok immedok;
|
|
public readonly Delegates.init_pair init_pair;
|
|
public readonly Delegates.initscr initscr;
|
|
public readonly Delegates.intrflush intrflush;
|
|
public readonly Delegates.is_term_resized is_term_resized;
|
|
public readonly Delegates.isendwin isendwin;
|
|
public readonly Delegates.keypad keypad;
|
|
public readonly Delegates.leaveok leaveok;
|
|
public readonly Delegates.meta meta;
|
|
public readonly Delegates.mouseinterval mouseinterval;
|
|
public readonly Delegates.mousemask mousemask;
|
|
public readonly Delegates.move move;
|
|
public readonly Delegates.mvaddch mvaddch;
|
|
public readonly Delegates.mvaddwstr mvaddwstr;
|
|
public readonly Delegates.mvgetch mvgetch;
|
|
public readonly Delegates.nl nl;
|
|
public readonly Delegates.nocbreak nocbreak;
|
|
public readonly Delegates.noecho noecho;
|
|
public readonly Delegates.nonl nonl;
|
|
public readonly Delegates.noqiflush noqiflush;
|
|
public readonly Delegates.noraw noraw;
|
|
public readonly Delegates.notimeout notimeout;
|
|
public readonly Delegates.qiflush qiflush;
|
|
public readonly Delegates.raw raw;
|
|
public readonly Delegates.redrawwin redrawwin;
|
|
public readonly Delegates.refresh refresh;
|
|
public readonly Delegates.reset_prog_mode reset_prog_mode;
|
|
public readonly Delegates.reset_shell_mode reset_shell_mode;
|
|
public readonly Delegates.resetty resetty;
|
|
public readonly Delegates.resize_term resize_term;
|
|
public readonly Delegates.resizeterm resizeterm;
|
|
public readonly Delegates.savetty savetty;
|
|
public readonly Delegates.scrollok scrollok;
|
|
public readonly Delegates.set_escdelay set_escdelay;
|
|
public readonly Delegates.setscrreg setscrreg;
|
|
public readonly Delegates.start_color start_color;
|
|
public readonly Delegates.timeout timeout;
|
|
public readonly Delegates.typeahead typeahead;
|
|
public readonly Delegates.ungetch ungetch;
|
|
public readonly Delegates.ungetmouse ungetmouse;
|
|
public readonly Delegates.use_default_colors use_default_colors;
|
|
public readonly Delegates.use_env use_env;
|
|
public readonly Delegates.waddch waddch;
|
|
public readonly Delegates.wmove wmove;
|
|
|
|
//public readonly Delegates.wredrawwin wredrawwin;
|
|
public readonly Delegates.wnoutrefresh wnoutrefresh;
|
|
public readonly Delegates.wrefresh wrefresh;
|
|
public readonly Delegates.wsetscrreg wsetscrreg;
|
|
public readonly Delegates.wtimeout wtimeout;
|
|
public UnmanagedLibrary UnmanagedLibrary;
|
|
|
|
public NativeMethods (UnmanagedLibrary lib)
|
|
{
|
|
UnmanagedLibrary = lib;
|
|
initscr = lib.GetNativeMethodDelegate<Delegates.initscr> ("initscr");
|
|
endwin = lib.GetNativeMethodDelegate<Delegates.endwin> ("endwin");
|
|
isendwin = lib.GetNativeMethodDelegate<Delegates.isendwin> ("isendwin");
|
|
cbreak = lib.GetNativeMethodDelegate<Delegates.cbreak> ("cbreak");
|
|
nocbreak = lib.GetNativeMethodDelegate<Delegates.nocbreak> ("nocbreak");
|
|
echo = lib.GetNativeMethodDelegate<Delegates.echo> ("echo");
|
|
noecho = lib.GetNativeMethodDelegate<Delegates.noecho> ("noecho");
|
|
halfdelay = lib.GetNativeMethodDelegate<Delegates.halfdelay> ("halfdelay");
|
|
raw = lib.GetNativeMethodDelegate<Delegates.raw> ("raw");
|
|
noraw = lib.GetNativeMethodDelegate<Delegates.noraw> ("noraw");
|
|
noqiflush = lib.GetNativeMethodDelegate<Delegates.noqiflush> ("noqiflush");
|
|
qiflush = lib.GetNativeMethodDelegate<Delegates.qiflush> ("qiflush");
|
|
typeahead = lib.GetNativeMethodDelegate<Delegates.typeahead> ("typeahead");
|
|
timeout = lib.GetNativeMethodDelegate<Delegates.timeout> ("timeout");
|
|
wtimeout = lib.GetNativeMethodDelegate<Delegates.wtimeout> ("wtimeout");
|
|
notimeout = lib.GetNativeMethodDelegate<Delegates.notimeout> ("notimeout");
|
|
keypad = lib.GetNativeMethodDelegate<Delegates.keypad> ("keypad");
|
|
meta = lib.GetNativeMethodDelegate<Delegates.meta> ("meta");
|
|
intrflush = lib.GetNativeMethodDelegate<Delegates.intrflush> ("intrflush");
|
|
clearok = lib.GetNativeMethodDelegate<Delegates.clearok> ("clearok");
|
|
idlok = lib.GetNativeMethodDelegate<Delegates.idlok> ("idlok");
|
|
idcok = lib.GetNativeMethodDelegate<Delegates.idcok> ("idcok");
|
|
immedok = lib.GetNativeMethodDelegate<Delegates.immedok> ("immedok");
|
|
leaveok = lib.GetNativeMethodDelegate<Delegates.leaveok> ("leaveok");
|
|
wsetscrreg = lib.GetNativeMethodDelegate<Delegates.wsetscrreg> ("wsetscrreg");
|
|
scrollok = lib.GetNativeMethodDelegate<Delegates.scrollok> ("scrollok");
|
|
nl = lib.GetNativeMethodDelegate<Delegates.nl> ("nl");
|
|
nonl = lib.GetNativeMethodDelegate<Delegates.nonl> ("nonl");
|
|
setscrreg = lib.GetNativeMethodDelegate<Delegates.setscrreg> ("setscrreg");
|
|
refresh = lib.GetNativeMethodDelegate<Delegates.refresh> ("refresh");
|
|
doupdate = lib.GetNativeMethodDelegate<Delegates.doupdate> ("doupdate");
|
|
wrefresh = lib.GetNativeMethodDelegate<Delegates.wrefresh> ("wrefresh");
|
|
redrawwin = lib.GetNativeMethodDelegate<Delegates.redrawwin> ("redrawwin");
|
|
|
|
//wredrawwin = lib.GetNativeMethodDelegate<Delegates.wredrawwin> ("wredrawwin");
|
|
wnoutrefresh = lib.GetNativeMethodDelegate<Delegates.wnoutrefresh> ("wnoutrefresh");
|
|
move = lib.GetNativeMethodDelegate<Delegates.move> ("move");
|
|
curs_set = lib.GetNativeMethodDelegate<Delegates.curs_set> ("curs_set");
|
|
addch = lib.GetNativeMethodDelegate<Delegates.addch> ("addch");
|
|
echochar = lib.GetNativeMethodDelegate<Delegates.echochar> ("echochar");
|
|
mvaddch = lib.GetNativeMethodDelegate<Delegates.mvaddch> ("mvaddch");
|
|
addwstr = lib.GetNativeMethodDelegate<Delegates.addwstr> ("addwstr");
|
|
mvaddwstr = lib.GetNativeMethodDelegate<Delegates.mvaddwstr> ("mvaddwstr");
|
|
wmove = lib.GetNativeMethodDelegate<Delegates.wmove> ("wmove");
|
|
waddch = lib.GetNativeMethodDelegate<Delegates.waddch> ("waddch");
|
|
attron = lib.GetNativeMethodDelegate<Delegates.attron> ("attron");
|
|
attroff = lib.GetNativeMethodDelegate<Delegates.attroff> ("attroff");
|
|
attrset = lib.GetNativeMethodDelegate<Delegates.attrset> ("attrset");
|
|
getch = lib.GetNativeMethodDelegate<Delegates.getch> ("getch");
|
|
get_wch = lib.GetNativeMethodDelegate<Delegates.get_wch> ("get_wch");
|
|
ungetch = lib.GetNativeMethodDelegate<Delegates.ungetch> ("ungetch");
|
|
mvgetch = lib.GetNativeMethodDelegate<Delegates.mvgetch> ("mvgetch");
|
|
has_colors = lib.GetNativeMethodDelegate<Delegates.has_colors> ("has_colors");
|
|
start_color = lib.GetNativeMethodDelegate<Delegates.start_color> ("start_color");
|
|
init_pair = lib.GetNativeMethodDelegate<Delegates.init_pair> ("init_pair");
|
|
use_default_colors = lib.GetNativeMethodDelegate<Delegates.use_default_colors> ("use_default_colors");
|
|
COLOR_PAIRS = lib.GetNativeMethodDelegate<Delegates.COLOR_PAIRS> ("COLOR_PAIRS");
|
|
getmouse = lib.GetNativeMethodDelegate<Delegates.getmouse> ("getmouse");
|
|
ungetmouse = lib.GetNativeMethodDelegate<Delegates.ungetmouse> ("ungetmouse");
|
|
mouseinterval = lib.GetNativeMethodDelegate<Delegates.mouseinterval> ("mouseinterval");
|
|
mousemask = lib.GetNativeMethodDelegate<Delegates.mousemask> ("mousemask");
|
|
is_term_resized = lib.GetNativeMethodDelegate<Delegates.is_term_resized> ("is_term_resized");
|
|
resize_term = lib.GetNativeMethodDelegate<Delegates.resize_term> ("resize_term");
|
|
resizeterm = lib.GetNativeMethodDelegate<Delegates.resizeterm> ("resizeterm");
|
|
use_env = lib.GetNativeMethodDelegate<Delegates.use_env> ("use_env");
|
|
flushinp = lib.GetNativeMethodDelegate<Delegates.flushinp> ("flushinp");
|
|
def_prog_mode = lib.GetNativeMethodDelegate<Delegates.def_prog_mode> ("def_prog_mode");
|
|
def_shell_mode = lib.GetNativeMethodDelegate<Delegates.def_shell_mode> ("def_shell_mode");
|
|
reset_prog_mode = lib.GetNativeMethodDelegate<Delegates.reset_prog_mode> ("reset_prog_mode");
|
|
reset_shell_mode = lib.GetNativeMethodDelegate<Delegates.reset_shell_mode> ("reset_shell_mode");
|
|
savetty = lib.GetNativeMethodDelegate<Delegates.savetty> ("savetty");
|
|
resetty = lib.GetNativeMethodDelegate<Delegates.resetty> ("resetty");
|
|
set_escdelay = lib.GetNativeMethodDelegate<Delegates.set_escdelay> ("set_escdelay");
|
|
curses_version = lib.GetNativeMethodDelegate<Delegates.curses_version> ("curses_version");
|
|
}
|
|
}
|
|
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
|
#pragma warning restore CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
|