1
0
Fork 0
forked from fun/fun

Very basic Notcurses support. There are bugs! (0.37.45)

This commit is contained in:
Johannes Findeisen 2026-01-03 21:11:26 +01:00
commit fd582f4d3a
30 changed files with 465 additions and 5 deletions

42
lib/ui/notcurses.fun Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-03
*/
// Notcurses stdlib abstraction wrapping VM NC_* builtins.
// Provides a tiny OO-style helper around nc_init/nc_clear/nc_draw_text/nc_getch/nc_shutdown.
// If Fun was built without Notcurses support, init() returns 0 and methods are no-ops.
class Notcurses()
// Initialize Notcurses core. Returns 1 on success, 0 on failure.
fun init(this)
return nc_init()
// Clear the screen and render. Returns 0 on success, -1 on error.
fun clear(this)
return nc_clear()
// Draw text at y, x and render. Returns 0 on success, -1 on error.
fun draw_text(this, y, x, text)
// allow flexible types
return nc_draw_text(to_number(y), to_number(x), to_string(text))
// Get a Unicode codepoint (int). timeout_ms<=0 blocks; >0 returns -1 if no key ready.
fun getch(this, timeout_ms)
if timeout_ms == nil
timeout_ms = 0
return nc_getch(to_number(timeout_ms))
// Shut down Notcurses, restoring the terminal.
fun shutdown(this)
return nc_shutdown()
// (banner helper removed temporarily due to parser limitations)