Обновление примера согласно реализации движка.

This commit is contained in:
Alexander Zhirov 2026-01-06 11:00:19 +03:00
parent 2bab6fc3e9
commit c43ef1e908
Signed by: alexander
GPG key ID: C8D8BE544A27C511
3 changed files with 54 additions and 17 deletions

View file

@ -1,24 +1,13 @@
import ncui;
import std.stdio : writeln;
import simple;
void main()
{
auto config = SessionConfig(InputMode.raw, Cursor.normal, Echo.on, Keypad.on);
Session session;
try {
session = new Session(config);
} catch (Exception e) {
writeln("Не удалось инициализировать сессию:\n\t", e.msg);
return;
}
try {
session.close();
} catch (Exception e) {
writeln("Не удалось закрыть сессию:\n\t", e.msg);
return;
}
setLogLevel(LogLevel.info);
writeln("OK");
auto config = SessionConfig(InputMode.raw, Cursor.hidden, Echo.off, Keypad.on);
NCUI ncui = new NCUI(config);
auto window = new Simple();
ncui.run(window);
}

View file

@ -0,0 +1,45 @@
module simple.app;
import ncui;
import deimos.ncurses;
final class Simple : ScreenBase
{
override ScreenAction onShow(ScreenContext context)
{
int height = getmaxy(context.session.root());
int width = getmaxx(context.session.root());
if (_window !is null)
{
_window.close();
}
_window = new Window(height / 2, width / 2, 0, 0);
_window.erase();
_window.border();
_window.refresh();
return ScreenAction.none();
}
override ScreenAction handle(ScreenContext context, KeyEvent event)
{
if (event.status == ERR)
{
return ScreenAction.quit(ScreenResult.none());
}
if (event.isChar)
{
if (event.ch == 27) {
return ScreenAction.quit(ScreenResult.none());
}
}
return ScreenAction.none();
}
}

View file

@ -0,0 +1,3 @@
module simple;
public import simple.app;