using Brutal.Strings; namespace Brutal.NotCursesApi; /// /// Hand-written ergonomics for the notcurses direct-mode handle. Most instance methods are /// auto-generated by Brutal.NotCurses.Generate (see Generated/Wrappers.gen.cs); /// only the things the generator can't infer (static factory, IDisposable, convenience overloads) live here. /// /// /// Direct mode doesn't take over the terminal. It lets you write colored/styled output inline. /// Init once at the start, write what you need, then . /// public readonly unsafe partial struct NcDirectHandle : IDisposable { /// Initializes notcurses in direct mode against stdout. Throws on init failure. /// The terminfo entry to use; default (default) reads $TERM. /// Bitmask of flags. public static NcDirectHandle Init(RefString8 termtype = default, NcDirectOption flags = default) { var d = NotCurses.PInvoke.ncdirect_core_init(termtype, default, flags); if (d.IsNull()) throw new InvalidOperationException("ncdirect_core_init failed."); return d; } /// string overload of ; encodes via . public static NcDirectHandle Init(string? termtype, NcDirectOption flags = default) { if (termtype is null) return Init(default(RefString8), flags); using var buf = new ScratchBuffer(termtype, stackalloc byte[256]); return Init(buf.Bytes, flags); } /// Convenience overload: write a UTF-8 string with default terminal colors (channels = 0). public void PutStr(string text) { using var buf = new ScratchBuffer(text, stackalloc byte[256]); PutStr(0, buf.Bytes); } /// Tears down direct mode and restores any modified terminal state. Calls . public void Dispose() => Stop(); }