mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 04:58:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
45
brutal.notcurses/Brutal.NotCurses/NcDirectHandle.cs
Normal file
45
brutal.notcurses/Brutal.NotCurses/NcDirectHandle.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using Brutal.Strings;
|
||||
|
||||
namespace Brutal.NotCursesApi;
|
||||
|
||||
/// <summary>
|
||||
/// Hand-written ergonomics for the notcurses direct-mode handle. Most instance methods are
|
||||
/// auto-generated by <c>Brutal.NotCurses.Generate</c> (see <c>Generated/Wrappers.gen.cs</c>);
|
||||
/// only the things the generator can't infer (static factory, IDisposable, convenience overloads) live here.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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 <see cref="Dispose"/>.
|
||||
/// </remarks>
|
||||
public readonly unsafe partial struct NcDirectHandle : IDisposable
|
||||
{
|
||||
/// <summary>Initializes notcurses in direct mode against <c>stdout</c>. Throws on init failure.</summary>
|
||||
/// <param name="termtype">The terminfo entry to use; default (<c>default</c>) reads <c>$TERM</c>.</param>
|
||||
/// <param name="flags">Bitmask of <see cref="NcDirectOption"/> flags.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary><c>string</c> overload of <see cref="Init(RefString8, NcDirectOption)"/>; encodes via <see cref="ScratchBuffer"/>.</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>Convenience overload: write a UTF-8 string with default terminal colors (channels = 0).</summary>
|
||||
public void PutStr(string text)
|
||||
{
|
||||
using var buf = new ScratchBuffer(text, stackalloc byte[256]);
|
||||
PutStr(0, buf.Bytes);
|
||||
}
|
||||
|
||||
/// <summary>Tears down direct mode and restores any modified terminal state. Calls <see cref="Stop"/>.</summary>
|
||||
public void Dispose() => Stop();
|
||||
}
|
||||
Loading…
Reference in a new issue