From 70c40bfec82cc104f129e738f2729d8117808d31 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Wed, 21 Oct 2020 21:59:41 +0200 Subject: [PATCH] curses: Add Terminfo API set, function keycodes F(n) and minor changes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some terminfo-related API were already bound (mvcur, vidattr, vidputs); move these all together, and add missing symbols (all from term.h). Bind the “F(n)” macro for function key codes. Annotate VidputsPutcFunc for correct C generation. Add attribute A_ITALIC (ncurses extension). --- vapi/curses.vapi | 61 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/vapi/curses.vapi b/vapi/curses.vapi index 8e20a1b4d..fc5dc25e3 100644 --- a/vapi/curses.vapi +++ b/vapi/curses.vapi @@ -1,4 +1,4 @@ -/* curses.vala +/* curses.vapi * * Copyright (c) 2007 Ed Schouten * All rights reserved. @@ -360,7 +360,6 @@ namespace Curses { public int mvaddnstr(int y, int x, string str, int n); public int mvaddstr(int y, int x, string str); public int mvchgat(int y, int x, int n, ulong attr, short color); - public int mvcur(int oldrow, int oldcol, int newrow, int newcol); public int mvdelch(int y, int x); public int mvgetch(int y, int x); public int mvgetnstr(int y, int x, string str, int n); @@ -432,23 +431,63 @@ namespace Curses { public int typeahead(int fd); public int ungetch(int ch); public void use_env(bool bf); - public int vidattr(ulong attrs); - public delegate int VidputsPutcFunc(char ch); - public int vidputs(ulong attrs, VidputsPutcFunc putc); public int vline(ulong ch, int n); + // curses interface to terminfo (term.h) + [CCode (cname = "TERMINAL", cheader_filename = "term.h", has_type_id = false)] + public struct Terminal { + [CCode (cname = "set_curterm")] + public unowned Terminal? set_cur(); + [CCode (cname = "del_curterm")] + public int del_cur(); + } + public static Terminal? cur_term; + [CCode (cheader_filename = "term.h")] + public int setupterm(string? term, int filedes, out int errret); + [CCode (cheader_filename = "term.h")] + public int setterm(string? term); + [CCode (cheader_filename = "term.h")] + public int restartterm(string? term, int filedes, out int errret); + + [CCode (has_typedef = false, has_target = false)] + public delegate int VidputsPutcFunc([CCode (type = "int")] char c); + + [CCode (cheader_filename = "term.h")] + namespace TermInfo { + [CCode (cname = "tputs")] +#if POSIX + public int puts(string str, int affcnt = 1, VidputsPutcFunc putc = (c) => Posix.stdout.putc (c)); +#else + public int puts(string str, int affcnt = 1, VidputsPutcFunc putc = (c) => GLib.stdout.putc (c)); +#endif + [CCode (cname = "tigetflag")] + public int getflag(string capname); + [CCode (cname = "tigetnum")] + public int getnum(string capname); + [CCode (cname = "tigetstr")] + public unowned string? getstr(string capname); + [CCode (cname = "tiparm")] + public unowned string parm(string capname, ...); + } + + public int vidputs(ulong attrs, VidputsPutcFunc putc); + public int vidattr(ulong attrs); + + public int mvcur(int oldrow, int oldcol, int newrow, int newcol); + [CCode (cprefix = "A_", has_type_id = false)] public enum Attribute { NORMAL, ATTRIBUTES, CHARTEXT, COLOR, STANDOUT, UNDERLINE, REVERSE, BLINK, DIM, BOLD, ALTCHARSET, INVIS, - PROTECT, HORIZONTAL, LEFT, LOW, RIGHT, TOP, VERTICAL + PROTECT, HORIZONTAL, LEFT, LOW, RIGHT, TOP, VERTICAL, + ITALIC // ITALIC is an ncurses extension } [CCode (has_type_id = false)] public enum Key { CODE_YES, MIN, BREAK, SRESET, RESET, DOWN, UP, LEFT, - RIGHT, HOME, BACKSPACE, F0, /* XXX F(n), */ DL, IL, DC, - IC, EIC, CLEAR, EOS, EOL, SF, SR, NPAGE, PPAGE, STAB, + RIGHT, HOME, BACKSPACE, F0, DL, IL, DC, IC, EIC, + CLEAR, EOS, EOL, SF, SR, NPAGE, PPAGE, STAB, CTAB, CATAB, ENTER, PRINT, LL, A1, A3, B2, C1, C3, BTAB, BEG, CANCEL, CLOSE, COMMAND, COPY, CREATE, END, EXIT, FIND, HELP, MARK, MESSAGE, MOVE, NEXT, OPEN, OPTIONS, @@ -458,7 +497,11 @@ namespace Curses { SHOME, SIC, SLEFT, SMESSAGE, SMOVE, SNEXT, SOPTIONS, SPREVIOUS, SPRINT, SREDO, SREPLACE, SRIGHT, SRSUME, SSAVE, SSUSPEND, SUNDO, SUSPEND, UNDO, MOUSE, RESIZE, - EVENT, MAX + EVENT, MAX; + + public static int F (int n) { + return F0 + n; + } } /* TODO: mouse + wide char support */ -- 2.47.2