Login
lib.cr at tip
Login

File src/remicharms/lib.cr from the latest check-in


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
   114
   115
   116
   117
   118
   119
   120
   121
   122
   123
   124
   125
   126
   127
   128
   129
   130
   131
   132
   133
   134
   135
   136
   137
   138
   139
   140
   141
   142
   143
   144
   145
   146
   147
   148
   149
   150
   151
   152
   153
   154
   155
   156
   157
   158
   159
   160
   161
   162
   163
   164
   165
   166
   167
   168
   169
   170
   171
   172
   173
   174
   175
   176
   177
   178
   179
   180
   181
   182
   183
   184
   185
   186
   187
   188
   189
   190
   191
   192
   193
   194
   195
   196
   197
   198
   199
   200
   201
   202
   203
   204
   205
   206
   207
   208
   209
   210
   211
   212
   213
   214
   215
   216
   217
   218
   219
   220
   221
   222
   223
   224
   225
   226
   227
   228
   229
   230
   231
   232
   233
   234
   235
   236
   237
   238
   239
   240
   241
   242
   243
   244
   245
   246
   247
   248
   249
   250
   251
   252
   253
   254
   255
   256
   257
   258
   259
   260
   261
   262
   263
   264
   265
   266
   267
   268
   269
   270
   271
   272
   273
   274
   275
   276
   277
   278
   279
   280
   281
   282
   283
   284
   285
   286
   287
   288
   289
   290
   291
   292
   293
   294
   295
   296
   297
   298
   299
   300
   301
   302
   303
   304
   305
   306
   307
   308
   309
   310
   311
   312
   313
   314
   315
   316
   317
   318
   319
   320
   321
   322
   323
   324
   325
   326
   327
   328
   329
   330
   331
   332
   333
   334
   335
   336
   337
   338
   339
   340
   341
   342
   343
   344
   345
   346
   347
   348
   349
   350
   351
   352
   353
   354
   355
   356
   357
   358
   359
   360
   361
   362
   363
   364
   365
   366
   367
   368
   369
   370
   371
   372
   373
   374
   375
   376
   377
   378
   379
   380
   381
   382
   383
   384
   385
   386
   387
   388
   389
   390
   391
   392
   393
   394
   395
   396
   397
   398
   399
   400
   401
   402
   403
   404
   405
   406
   407
   408
   409
   410
   411
   412
   413
   414
   415
   416
   417
   418
   419
   420
   421
   422
   423
   424
   425
   426
   427
   428
   429
   430
   431
   432
   433
   434
   435
   436
   437
   438
   439
   440
   441
   442
   443
   444
   445
   446
   447
   448
   449
   450
   451
   452
   453
   454
   455
   456
   457
   458
   459
   460
   461
   462
   463
   464
   465
   466
   467
   468
   469
   470
   471
   472
   473
   474
   475
   476
   477
   478
   479
   480
   481
   482
   483
   484
   485
   486
   487
   488
   489
   490
   491
   492
   493
   494
   495
   496
   497
   498
   499
   500
   501
   502
   503
   504
   505
   506
   507
   508
   509
   510
   511
   512
   513
   514
   515
   516
   517
   518
   519
   520
   521
   522
   523
   524
   525
   526
   527
   528
   529
   530
   531
   532
   533
   534
   535
   536
   537
   538
   539
   540
   541
   542
   543
   544
   545
   546
   547
   548
   549
   550
   551
   552
   553
   554
   555
   556
   557
   558
   559
   560
   561
   562
   563
   564
   565
   566
   567
   568
   569
   570
   571
   572
   573
   574
   575
   576
   577
   578
   579
   580
   581
   582
   583
   584
   585
   586
   587
   588
   589
   590
   591
   592
   593
   594
   595
   596
   597
   598
   599
   600
   601
   602
   603
   604
   605
   606
   607
   608
   609
   610
   611
   612
   613
   614
   615
   616
   617
   618
   619
   620
   621
   622
   623
   624
   625
   626
   627
   628
   629
   630
   631
   632
   633
   634
   635
   636
   637
   638
   639
   640
   641
   642
   643
   644
   645
   646
   647
   648
   649
   650
   651
   652
   653
   654
   655
   656
   657
   658
   659
   660
   661
   662
   663
   664
   665
   666
   667
   668
   669
   670
   671
   672
   673
   674
   675
   676
   677
   678
   679
   680
   681
   682
   683
   684
   685
   686
   687
   688
   689
   690
   691
   692
   693
   694
   695
   696
   697
   698
   699
   700
   701
   702
   703
   704
   705
   706
   707
   708
   709
   710
   711
   712
   713
   714
   715
   716
   717
   718
   719
   720
   721
   722
   723
   724
   725
   726
   727
   728
   729
   730
   731
   732
   733
   734
   735
   736
   737
   738
   739
   740
   741
   742
   743
   744
   745
   746
   747
   748
   749
   750
   751
   752
   753
   754
   755
   756
   757
   758
   759
   760
   761
   762
   763
   764
   765
   766
   767
   768
   769
   770
   771
   772
   773
   774
   775
   776
   777
   778
   779
   780
   781
   782
   783
   784
   785
   786
   787
   788
   789
   790
   791
   792
   793
   794
   795
   796
   797
   798
   799
   800
   801
   802
   803
   804
   805
   806
   807
   808
   809
   810
   811
   812
   813
   814
   815
   816
   817
   818
   819
   820
   821
   822
   823
   824
   825
   826
   827
   828
   829
   830
   831
   832
   833
   834
   835
   836
   837
   838
   839
   840
   841
   842
   843
   844
   845
   846
   847
   848
   849
   850
   851
   852
   853
   854
   855
   856
   857
   858
   859
   860
   861
   862
   863
   864
   865
   866
   867
   868
   869
   870
   871
   872
   873
   874
   875
   876
   877
   878
   879
   880
   881
   882
   883
   884
   885
   886
   887
   888
   889
   890
   891
   892
   893
   894
   895
   896
   897
   898
   899
   900
   901
   902
   903
   904
   905
   906
   907
   908
   909
   910
   911
   912
   913
   914
   915
   916
   917
   918
   919
   920
   921
   922
   923
   924
   925
   926
   927
   928
   929
   930
   931
   932
   933
   934
   935
   936
   937
   938
   939
   940
   941
   942
   943
   944
   945
   946
   947
   948
   949
   950
   951
   952
   953
   954
   955
   956
   957
   958
   959
   960
   961
   962
   963
   964
   965
   966
   967
   968
   969
   970
   971
   972
   973
   974
   975
   976
   977
   978
   979
   980
   981
   982
   983
   984
   985
   986
   987
   988
   989
   990
   991
   992
   993
   994
   995
   996
   997
   998
   999
  1000
  1001
  1002
  1003
  1004
  1005
  1006
  1007
  1008
  1009
  1010
  1011
  1012
  1013
  1014
  1015
  1016
  1017
  1018
  1019
  1020
  1021
  1022
  1023
  1024
  1025
  1026
  1027
  1028
  1029
  1030
  1031
  1032
  1033
  1034
  1035
  1036
  1037
  1038
  1039
  1040
  1041
  1042
  1043
  1044
  1045
  1046
  1047
  1048
  1049
  1050
  1051
  1052
  1053
  1054
  1055
  1056
  1057
  1058
  1059
  1060
  1061
  1062
  1063
  1064
  1065
  1066
  1067
  1068
  1069
  1070
  1071
  1072
  1073
  1074
  1075
  1076
  1077
  1078
  1079
  1080
  1081
  1082
  1083
  1084
  1085
  1086
  1087
  1088
  1089
  1090
  1091
  1092
  1093
  1094
  1095
  1096
  1097
  1098
  1099
  1100
  1101
  1102
  1103
  1104
  1105
  1106
  1107
  1108
  1109
  1110
  1111
  1112
  1113
  1114
  1115
  1116
  1117
  1118
  1119
  1120
  1121
  1122
  1123
  1124
  1125
  1126
  1127
  1128
  1129
  1130
  1131
  1132
  1133
  1134
  1135
  1136
  1137
  1138
  1139
  1140
  1141
  1142
  1143
  1144
  1145
  1146
  1147
  1148
  1149
  1150
  1151
  1152
  1153
  1154
  1155
  1156
  1157
  1158
  1159
  1160
  1161
  1162
  1163
  1164
  1165
  1166
  1167
  1168
  1169
  1170
  1171
#### This file is part of RemiCharms, providing Crystal bindings to libcurses.
####
#### Copyright (c) 2023 Remilia Scarlet <remilia@posteo.jp>
#### Copyright (c) 2014-2018 Robert Smith <quad@symbo1ics.com>
#### Copyright (c) 2014 Mark Fedurin <hitecnologys@gmail.com>
#### Copyright (c) 2010 Abhishek Reddy <http://abhishek.geek.nz>
####
#### This file includes portions of code from cl-ncurses, an ncurses interface
#### for Common Lisp.  The copyright notices from cl-ncurses are reproduced
#### below.
####
#### Copyright (c) 2003 Nikodemus Siivola
#### Copyright (c) 2004 Marcelo Ramos <mramos@montevideo.com.uy>
#### Copyright (c) 2007 Jacob Gabrielson <jacobg23@pobox.com>
####
#### This program is free software: you can redistribute it and/or modify it
#### under the terms of the GNU Affero General Public License as published by
#### the Free Software Foundation, either version 3 of the License, or (at your
#### option) any later version.
####
#### This program is distributed in the hope that it will be useful, but WITHOUT
#### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#### FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
#### License for more details.
####
#### You should have received a copy of the GNU Affero General Public License
#### along with this program.  If not, see <https://www.gnu.org/licenses/>.
#### This file is part of RemiCharms, providing Crystal bindings to libcurses.

{% begin %}
@[Link("ncursesw")] # Specifically use ncursesw so we have Unicode.
lib LibNCurses
  ###
  ### Aliases
  ###

  alias PVoid = Pointer(Void)
  alias CInt = LibC::Int
  alias CUInt = LibC::UInt
  alias PCUInt = Pointer(CUInt)
  alias CUInt8 = UInt8
  alias CInt32 = Int32
  alias CUShort = LibC::UShort
  alias CShort = LibC::Short
  alias PCShort = Pointer(CShort)
  alias CString = Pointer(UInt8)
  alias CChar = LibC::Char
  alias CULong = LibC::ULong

  alias ChType = CUInt
  alias AttrT = ChType
  alias PAttrT = Pointer(AttrT)
  alias MMask = CUInt
  alias PChar = Pointer(CUInt8)
  alias ChStr = Pointer(ChType)
  alias FilePtr = PVoid
  alias ScreenPtr = PVoid
  alias WindowPtr = PVoid
  alias WChar = CUShort
  alias CWString = Pointer(WChar)
  alias NCBool = CUInt8

  ###
  ### Globals
  ###

  $colors = COLORS : CInt
  $color_pairs = COLOR_PAIRS : CInt
  $color_paths = COLOR_PATHS : CInt
  $lines = LINES : CInt
  $cols = COLS : CInt
  $tabsize = TABSIZE : CInt
  $escdelay = ESCDELAY : CInt
  $stdscr : WindowPtr
  $curscr : WindowPtr
  $newscr : WindowPtr
  $acs_map : Pointer(ChType)

  ###
  ### Structs
  ###

  struct MEvent
    id : CShort
    x : CInt
    y : CInt
    z : CInt
    bstate : CULong
  end

  ###
  ### Functions
  ###

  ## addch...
  fun addch(ch : ChType) : CInt
  fun echochar(ch : ChType) : CInt
  fun waddch(win : WindowPtr, ch : ChType) : CInt
  fun wechochar(win : WindowPtr, ch : ChType) : CInt
  fun mvaddch(y : CInt, x : CInt, ch : ChType) : CInt
  fun mvwaddch(win : WindowPtr, y : CInt, x : CInt, ch : ChType) : CInt

  ## addchstr...
  fun addchstr(chstr : ChStr) : CInt
  fun addchnstr(chstr : ChStr, n : CInt) : CInt
  fun waddchstr(win : WindowPtr, chstr : ChStr) : CInt
  fun waddchnstr(win : WindowPtr, chstr : ChStr, n : CInt) : CInt
  fun mvaddchstr(y : CInt, x : CInt, chstr : ChStr) : CInt
  fun mvaddchnstr(y : CInt, x : CInt, chstr : ChStr, n : CInt) : CInt
  fun mvwaddchstr(win : WindowPtr, y : CInt, x : CInt, chstr : ChStr) : CInt
  fun mvwaddchnstr(win : WindowPtr, y : CInt, x : CInt, chstr : ChStr, n : CInt) : CInt

  ## addstr...
  fun addstr(str : CString) : CInt
  fun addnstr(str : CString, n : CInt) : CInt
  fun waddstr(win : WindowPtr, str : CString) : CInt
  fun waddnstr(win : WindowPtr, str : CString, n : CInt) : CInt
  fun mvaddstr(y : CInt, x : CInt, str : CString) : CInt
  fun mvaddnstr(y : CInt, x : CInt, str : CString, n : CInt) : CInt
  fun mvwaddstr(win : WindowPtr, y : CInt, x : CInt, str : CString) : CInt
  fun mvwaddnstr(win : WindowPtr, y : CInt, x : CInt, str : CString, n : CInt) : CInt

  ## attr... color...
  fun attroff(attrs : CInt) : CInt
  fun attron(attrs : CInt) : CInt
  fun attrset(attrs : CInt) : CInt

  fun wattroff(win : WindowPtr, attrs : CInt) : CInt
  fun wattron(win : WindowPtr, attrs : CInt) : CInt
  fun wattrset(win : WindowPtr, attrs : CInt) : CInt

  fun color_set(colorPairNum : CShort, opts : PVoid) : CInt
  fun wcolor_set(win : WindowPtr, color : CShort, opts : PVoid) : CInt

  fun standend : CInt
  fun standout : CInt
  fun wstandend(win : WindowPtr) : CInt
  fun wstandout(win : WindowPtr) : CInt

  fun attr_get(attrs : AttrT, pair : PCShort, opts : PVoid) : CInt
  fun attr_set(attrs : AttrT, pair : PCShort, opts : PVoid) : CInt
  fun wattr_get(win : WindowPtr, attrs : PAttrT, pair : PCShort, opts : PVoid) : CInt
  fun wattr_set(win : WindowPtr, attrs : AttrT, pair : PCShort, opts : PVoid) : CInt

  fun attr_off(attrs : AttrT, opts : PVoid) : CInt
  fun attr_on(attrs : AttrT, opts : PVoid) : CInt
  fun wattr_off(win : WindowPtr, attrs : AttrT, opts : PVoid) : CInt
  fun wattr_on(win : WindowPtr, attrs : AttrT, opts : PVoid) : CInt

  fun chgat(n : CInt, attrs : AttrT, color : CShort, opts : PVoid) : CInt
  fun wchgat(win : WindowPtr, n : CInt, attrs : AttrT, color : CShort, opts : PVoid) : CInt
  fun mvchgat(y : CInt, x : CInt, n : CInt, attrs : AttrT, color : CShort, opts : PVoid) : CInt
  fun mvwchgat(win : WindowPtr, y : CInt, x : CInt, n : CInt, attrs : AttrT, color : CShort, opts : PVoid) : CInt

  ## beep...
  fun beep : CInt
  fun flash : CInt

  ## bkgd...
  fun bkgdset(ch : ChType) : Void
  fun bkgd(ch : ChType) : CInt
  fun wbkgdset(win : WindowPtr, ch : ChType) : Void
  fun wbkgd(win : WindowPtr, ch : ChType) : CInt
  fun getbkgd(win : WindowPtr) : ChType

  ## bkgrnd...
  # TODO
  #
  # C Prototype: int bkgrnd( const cchar_t *wch);
  # C Prototype: int wbkgrnd( WINDOW *win, const cchar_t *wch);
  # C Prototype: void bkgrndset(const cchar_t *wch );
  # C Prototype: void wbkgrndset(WINDOW *win, const cchar_t *wch);
  # C Prototype: int getbkgrnd(cchar_t *wch);
  # C Prototype: int wgetbkgrnd(WINDOW *win, cchar_t *wch);

  ## border... box... line...
  fun c_border = "border"(ls : ChType, rs : ChType, ts : ChType, bs : ChType,
                          tl : ChType, tr : ChType, bl : ChType, br : ChType) : CInt
  fun c_wborder = "wborder"(win : WindowPtr,
                            ls : ChType, rs : ChType, ts : ChType, bs : ChType,
                            tl : ChType, tr : ChType, bl : ChType, br : ChType) : CInt

  fun c_box = "box"(win : WindowPtr, verCh : ChType, horCh : ChType) : CInt

  fun c_hline = "hline"(ch : ChType, n : CInt) : CInt
  fun c_vline = "vline"(ch : ChType, n : CInt) : CInt
  fun c_whline = "whline"(win : WindowPtr, ch : ChType, n : CInt) : CInt
  fun c_wvline = "wvline"(win : WindowPtr, ch : ChType, n : CInt) : CInt
  fun c_mvhline = "mvhline"(y : CInt, x : CInt, ch : ChType, n : CInt) : CInt
  fun c_mvvline = "mvvline"(y : CInt, x : CInt, ch : ChType, n : CInt) : CInt
  fun c_mvwhline = "mvwhline"(win : WindowPtr, y : CInt, x : CInt, ch : ChType, n : CInt) : CInt
  fun c_mvwvline = "mvwvline"(win : WindowPtr, y : CInt, x : CInt, ch : ChType, n : CInt) : CInt

  ## border_set...
  # TODO:
  #
  # cchar_t * ???
  # C Prototype: int border_set(
  #        const cchar_t *ls, const cchar_t *rs,
  #        const cchar_t *ts, const cchar_t *bs,
  #        const cchar_t *tl, const cchar_t *tr,
  #        const cchar_t *bl, const cchar_t *br );
  # C Prototype: int wborder_set(
  #        WINDOW *win,
  #        const cchar_t *ls, const cchar_t *rs,
  #        const cchar_t *ts, const cchar_t *bs,
  #        const cchar_t *tl, const cchar_t *tr,
  #        const cchar_t *bl, const cchar_t *br);
  # C Prototype: int box_set(
  #        WINDOW *win,
  #        const cchar_t *verch,
  #        const cchar_t *horch);
  # C Prototype: int hline_set(
  #        const cchar_t *wch, int n);
  # C Prototype: int whline_set(
  #        WINDOW *win,
  #        const cchar_t *wch, int n);
  # C Prototype: int mvhline_set(
  #         int y, int x,
  #        const cchar_t *wch, int n);
  # C Prototype: int mvwhline_set(
  #        WINDOW *win,
  #         int y, int x,
  #        const cchar_t *wch, int n);
  # C Prototype: int vline_set(
  #        const cchar_t *wch, int n);
  # C Prototype: int wvline_set(
  #        WINDOW *win,
  #        const cchar_t *wch, int n);
  # C Prototype: int mvvline_set(
  #         int y, int x,
  #        const cchar_t *wch, int n);
  # C Prototype: int mvwvline_set(
  #        WINDOW *win,
  #         int y, int x,
  #        const cchar_t *wch, int n);

  ## clear...
  fun erase : CInt
  fun clear : CInt
  fun clrtobot : CInt
  fun clrtoeol : CInt

  fun werase(win : WindowPtr) : CInt
  fun wclear(win : WindowPtr) : CInt
  fun wclrtobot(win : WindowPtr) : CInt
  fun wclrtoeol(win : WindowPtr) : CInt

  ## color...
  fun start_color : CInt
  fun color_pair = "COLOR_PAIR"(pair : CInt) : CInt

  fun init_pair(pair : CShort, f : CShort, b : CShort) : CInt
  fun init_color(color : CShort, r : CShort, g : CShort, b : CShort) : CInt

  fun has_colors : NCBool
  fun can_change_color : NCBool

  fun color_content(color : CShort, r : PCShort, g : PCShort, b : PCShort) : CInt
  fun pair_content(pair : CShort, f : PCShort, b : PCShort) : CInt

  ## default_colors...
  fun use_default_colors : CInt
  fun assume_default_colors(fg : CInt, bg : CInt) : CInt

  ## delch
  fun delch : CInt
  fun wdelch(win : WindowPtr) : CInt

  fun mvdelch(y : CInt, x : CInt) : CInt
  fun mvwdelch(win : WindowPtr, y : CInt, x : CInt) : CInt

  ## deleteln...
  fun deleteln : CInt
  fun insertln : CInt

  fun wdeleteln(win : WindowPtr) : CInt
  fun winsertln(win : WindowPtr) : CInt

  fun insdelln(n : CInt) : CInt
  fun winsdelln(win : WindowPtr, n : CInt) : CInt

  # extensions...
  fun curses_version : CString
  fun use_extended_names(enable : NCBool) : CInt

  ## get_wch...
  ##
  ## These are wrapped to return better values.

  # :nodoc:
  fun c_get_wch = "get_wch"(target : PCUInt) : CInt
  # :nodoc:
  fun c_wget_wch = "wget_wch"(win : WindowPtr, target : PCUInt) : CInt
  # :nodoc:
  fun c_mvget_wch = "mvget_wch"(y : CInt, x : CInt, target : PCUInt) : CInt
  # :nodoc:
  fun c_mvwget_wch = "mvwget_wch"(win : WindowPtr, y : CInt, x : CInt, target : PCUInt) : CInt

  fun unget_wch(wch : WChar) : CInt

  ## get_wstr...
  # TODO:
  #
  # C Prototype: int get_wstr(wint_t *wstr);
  # C Prototype: int getn_wstr(wint_t *wstr, int n);
  # C Prototype: int wget_wstr(WINDOW *win, wint_t *wstr);
  # C Prototype: int wgetn_wstr(WINDOW *win, wint_t *wstr, int n);
  # C Prototype: int mvget_wstr(int y, int x, wint_t *wstr);
  # C Prototype: int mvgetn_wstr(int y, int x, wint_t *wstr, int n);
  # C Prototype: int mvwget_wstr(WINDOW *win, int y, int x, wint_t *wstr);
  # C Prototype: int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n);

  ## getcchar...
  # TODO:
  #
  # C Prototype: int getcchar(
  #             const cchar_t *wcval,
  #             wchar_t *wch,
  #             attr_t *attrs,
  #             short *color_pair,
  #             void *opts );

  # C Prototype: int setcchar(
  #             cchar_t *wcval,
  #             const wchar_t *wch,
  #             const attr_t attrs,
  #             short color_pair,
  #             void *opts );

  ## getch
  fun getch : CInt
  fun wgetch(win : WindowPtr) : CInt
  fun mvgetch(y : CInt, x : CInt) : CInt
  fun mvwgetch(win : WindowPtr, y : CInt, x : CInt) : CInt

  fun ungetch(ch : CInt) : CInt

  fun getstr(str : CString) : CInt
  fun getnstr(str : CString, n : CInt) : CInt
  fun wgetstr(win : WindowPtr, str : CString) : CInt
  fun wgetnstr(win : WindowPtr, str : CString, n : CInt) : CInt
  fun mvgetstr(y : CInt, x : CInt, str : CString) : CInt
  fun mvgetnstr(y : CInt, x : CInt, str : CString, n : CInt) : CInt
  fun mvwgetstr(win : WindowPtr, y : CInt, x : CInt, str : CString) : CInt
  fun mvwgetnstr(win : WindowPtr, y : CInt, x : CInt, str : CString, n : CInt) : CInt

  {% for fn in [:getcurx, :getcury, :getbegx, :getbegy, :getmaxx, :getmaxy, :getparx, :getpary] %}
    fun {{fn.id}}(win : WindowPtr) : CInt
  {% end %}

  ## in_wch...
  # TODO:
  #
  # C-prototype: int in_wch(cchar_t *wcval);
  # C-prototype: int mvin_wch(int y, int x, cchar_t *wcval);
  # C-prototype: int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval);
  # C-prototype: int win_wch(WINDOW *win, cchar_t *wcval);

  ## in_wchstr...
  # TODO:
  #
  # C-prototype: int in_wchstr(cchar_t *wchstr);
  # C-prototype: int in_wchnstr(cchar_t *wchstr, int n);
  # C-prototype: int win_wchstr(WINDOW *win, cchar_t *wchstr);
  # C-prototype: int win_wchnstr(WINDOW *win, cchar_t *wchstr, int n);
  # C-prototype: int mvin_wchstr(int y, int x, cchar_t *wchstr);
  # C-prototype: int mvin_wchnstr(int y, int x, cchar_t *wchstr, int n);
  # C-prototype: int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wchstr);
  # C-prototype: int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wchstr, int n);

  ## inch...
  fun inch : ChType
  fun winch(win : WindowPtr) : ChType
  fun mvinch(y : CInt, x : CInt) : ChType
  fun mvwinch(win : WindowPtr, y : CInt, x : CInt) : ChType

  ## inchstr
  fun inchstr(chstr : ChStr) : CInt
  fun inchnstr(chstr : ChStr, n : CInt) : CInt
  fun winchstr(win : WindowPtr, chstr : ChStr) : CInt
  fun winchnstr(win : WindowPtr, chstr : ChStr, n : CInt) : CInt
  fun mvinchstr(y : CInt, x : CInt, chstr : ChStr) : CInt
  fun mvinchnstr(y : CInt, x : CInt, chstr : ChStr, n : CInt) : CInt
  fun mvwinchstr(win : WindowPtr, y : CInt, x : CInt, chstr : ChStr) : CInt
  fun mvwinchnstr(win : WindowPtr, y : CInt, x : CInt, chstr : ChStr, n : CInt) : CInt

  ## initscr...
  fun initscr : WindowPtr
  fun endwin : CInt
  fun isendwin : NCBool
  fun newterm(typ : PChar, outd : FilePtr, infd : FilePtr) : ScreenPtr

  fun set_term(sp : ScreenPtr) : ScreenPtr
  fun delscreen(sp : ScreenPtr) : Void

  ## inopts...

  fun cbreak : CInt
  fun nocbreak : CInt
  fun echo : CInt
  fun noecho : CInt
  fun raw : CInt
  fun noraw : CInt

  fun halfdelay(tenths : CInt) : CInt

  fun intrflush(win : WindowPtr, bf : NCBool) : CInt
  fun keypad(win : WindowPtr, bf : NCBool) : CInt
  fun meta(win : WindowPtr, bf : NCBool) : CInt
  fun nodelay(win : WindowPtr, bf : NCBool) : CInt
  fun notimeout(win : WindowPtr, bf : NCBool) : CInt

  fun noqiflush : CInt
  fun qiflush : CInt

  fun timeout(delay : CInt) : Void
  fun wtimeout(win : WindowPtr, delay : CInt) : Void

  fun typeahead(fd : CInt) : CInt

  ## ins_wch...
  # TODO:
  #
  # C-prototype: int ins_wch(const cchar_t *wch);
  # C-prototype: int wins_wch(WINDOW *win, const cchar_t *wch);
  # C-prototype: int mvins_wch(int y, int x, const cchar_t *wch);
  # C-prototype: int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch);

  ## ins_wstr...
  # TODO:
  #
  # C-prototype: int ins_wstr(const wchar_t *wstr);
  # C-prototype: int ins_nwstr(const wchar_t *wstr, int n);
  # C-prototype: int wins_wstr(WINDOW *win, const wchar_t *wstr);
  # C-prototype: int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n);
  # C-prototype: int mvins_wstr(int y, int x, const wchar_t *wstr);
  # C-prototype: int mvins_nwstr(int y, int x, const wchar_t *wstr, int n);
  # C-prototype: int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr);
  # C-prototype: int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);

  ## insch...
  fun insch(ch : ChType) : CInt
  fun winsch(win : WindowPtr, ch : ChType) : CInt
  fun mvinsch(y : CInt, x : CInt, ch : ChType) : CInt
  fun mvwinsch(y : CInt, x : CInt, win : WindowPtr, ch : ChType) : CInt

  ## insstr...
  fun insstr(str : CString) : CInt
  fun insnstr(str : CString, n : CInt) : CInt
  fun winsstr(win : WindowPtr, str : CString) : CInt
  fun winsnstr(win : WindowPtr, str : CString, n : CInt) : CInt
  fun mvinsstr(y : CInt, x : CInt, str : CString) : CInt
  fun mvinsnstr(y : CInt, x : CInt, str : CString, n : CInt) : CInt
  fun mvwinsstr(win : WindowPtr, y : CInt, x : CInt, str : CString) : CInt
  fun mvwinsnstr(win : WindowPtr, y : CInt, x : CInt, str : CString, n : CInt) : CInt

  ## instr...
  fun instr(str : CString) : CInt
  fun innstr(str : CString, n : CInt) : CInt
  fun winstr(win : WindowPtr, str : CString) : CInt
  fun winnstr(win : WindowPtr, str : CString, n : CInt) : CInt
  fun mvinstr(y : CInt, x : CInt, str : CString) : CInt
  fun mvinnstr(y : CInt, x : CInt, str : CString, n : CInt) : CInt

  ## inwstr...
  # TODO:
  #
  # C-prototype: int inwstr(wchar_t *str);
  # C-prototype: int innwstr(wchar_t *str, int n);
  # C-prototype: int winwstr(WINDOW *win, wchar_t *str);
  # C-prototype: int winnwstr(WINDOW *win, wchar_t *str, int n);
  # C-prototype: int mvinwstr(int y, int x, wchar_t *str);
  # C-prototype: int mvinnwstr(int y, int x, wchar_t *str, int n);
  # C-prototype: int mvwinwstr(WINDOW *win, int y, int x, wchar_t *str);
  # C-prototype: int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *str, int n);

  ## kernel...
  fun def_prog_mode : CInt
  fun def_shell_mode : CInt
  fun reset_prog_mode : CInt
  fun reset_shell_mode : CInt
  fun resetty : CInt
  fun savetty : CInt

  fun curs_set(visibility : CInt) : CInt
  fun napms(ms : CInt) : CInt
  fun keybound(keycode : CInt, count : CInt) : CString
  fun keyok(keycode : CInt, enable : NCBool) : CInt

  ## key_defined...
  # TODO: wrap this function if the local C ncurses library supports EXTENSIONS.
  # C-prototype: int key_defined(const char *definition);
  #(def :int ((definition :cstring))
  #     "key_defined")

  ## mouse...
  # TODO:
  #
  # C-prototype: typedef unsigned long mmask_t;
  #
  # C-prototype: typedef struct
  #        {
  #         short id;         /* ID to distinguish multiple devices */
  #         int x, y, z;      /* event coordinates */
  #         mmask_t bstate;   /* button state bits */
  #        }
  #        MEVENT;
  # C-prototype: int getmouse(MEVENT *event);
  # C-prototype: int ungetmouse(MEVENT *event);
  # C-prototype: mmask_t mousemask(mmask_t newmask, mmask_t *oldmask);
  # C-prototype: bool wenclose(const WINDOW *win, int y, int x);
  # C-prototype: bool mouse_trafo(int* pY, int* pX, bool to_screen);
  # C-prototype: bool wmouse_trafo(const WINDOW* win, int* pY, int* pX, bool to_screen)#
  # C-prototype: int mouseinterval(int erval);

  ## move...
  fun move(y : CInt, x : CInt) : CInt
  fun wmove(win : WindowPtr, y : CInt, x : CInt) : CInt
  fun clearok(win : WindowPtr, bf : NCBool) : CInt
  fun idlok(win : WindowPtr, bf : NCBool) : CInt
  fun leaveok(win : WindowPtr, bf : NCBool) : CInt
  fun scrollok(win : WindowPtr, bf : NCBool) : CInt
  fun idcok(win : WindowPtr, bf : NCBool) : Void
  fun immedok(win : WindowPtr, bf : NCBool) : Void
  fun setscrreg(top : CInt, bot : CInt) : CInt
  fun wsetscrreg(win : WindowPtr, top : CInt, bot : CInt) : CInt
  fun nl : CInt
  fun nonl : CInt

  ## overlay...

  fun overlay(srcwin : WindowPtr, dstwin : WindowPtr) : CInt
  fun overwrite(srcwin : WindowPtr, dstwin : WindowPtr) : CInt

  # TODO:
  #
  # C-prototype: int copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,
  #              int smincol, int dminrow, int dmincol, int dmaxrow,
  #              int dmaxcol, int overlay);

  ## pad...
  fun newpad(nlines : CInt, ncols : CInt) : WindowPtr
  fun subpad(orig : WindowPtr, nlines : CInt, ncols : CInt, beginY : CInt, beginX : CInt) : WindowPtr
  fun prefresh(pad : WindowPtr, pminrow : CInt, pmincol : CInt, sminrow : CInt, smincol : CInt,
               smaxrow : CInt, smaxcol : CInt) : CInt
  fun pnoutrefresh(pad : WindowPtr, pminrow : CInt, pmincol : CInt, sminrow : CInt, smincol : CInt,
                   smaxrow : CInt, smaxcol : CInt) : CInt
  fun pechochar(pad : WindowPtr, ch : ChType) : CInt

  ## print...
  fun mcprint(data : CString, len : CInt) : CInt

  ## printw...
  fun printw(fmt : CString, ...) : CInt
  fun wprintw(win : WindowPtr, fmt : CString, ...) : CInt
  fun mvprintw(y : CInt, x : CInt, fmt : CString, ...) : CInt
  fun mvwprintw(win : WindowPtr, y : CInt, x : CInt, fmt : CString, ...) : CInt

  # TODO:
  #
  # C-prototype: int vwprintw(WINDOW *win, const char *fmt, va_list varglist);
  # C-prototype: int vw_printw(WINDOW *win, const char *fmt, va_list varglist);

  ## refresh...
  fun refresh : CInt
  fun doupdate : CInt
  fun wrefresh(win : WindowPtr) : CInt
  fun wnoutrefresh(win : WindowPtr) : CInt
  fun redrawwin(win : WindowPtr) : CInt
  fun wredrawln(win : WindowPtr, begLine : CInt, numLines : CInt) : CInt

  ## resizeterm...
  fun is_term_resized(lines : CInt, columns : CInt) : NCBool
  fun resize_term(line : CInt, columns : CInt) : CInt
  fun resizeterm(line : CInt, columns : CInt) : CInt

  ## scanw
  # TODO:
  #
  # C-prototype: int scanw(char *fmt, ...);
  # C-prototype: int wscanw(WINDOW *win, char *fmt, ...);
  # C-prototype: int mvscanw(int y, int x, char *fmt, ...);
  # C-prototype: int mvwscanw(WINDOW *win, int y, int x, char *fmt, ...);
  # C-prototype: int vw_scanw(WINDOW *win, char *fmt, va_list varglist);
  # C-prototype: int vwscanw(WINDOW *win, char *fmt, va_list varglist);

  ## scr_dump...
  fun scr_dump(filename : PChar) : CInt
  fun scr_restore(filename : PChar) : CInt
  fun scr_init(filename : PChar) : CInt
  fun scr_set(filename : PChar) : CInt

  ## scroll...
  fun scroll(win : WindowPtr) : CInt
  fun scrl(n : CInt) : CInt
  fun wscrl(win : WindowPtr, n : CInt) : CInt

  ## slk...
  fun slk_init(fmt : CInt) : CInt
  fun slk_set(labnum : CInt, label : CString, fmt : CInt) : CInt
  fun slk_refresh : CInt
  fun slk_noutrefresh : CInt
  fun slk_clear : CInt
  fun slk_restore : CInt
  fun slk_touch : CInt
  fun slk_label(labnum : CInt) : CString
  fun slk_attron(attrs : ChType) : CInt
  fun slk_attroff(attrs : ChType) : CInt
  fun slk_attrset(attrs : ChType) : CInt

  # TODO:
  #
  # C-prototype: int slk_attr_on(attr_t attrs, void* opts);
  # C-prototype: int slk_attr_off(const attr_t attrs, void * opts);
  # C-prototype: int slk_attr_set(const attr_t attrs, short color_pair_number, void* opts);
  # C-prototype: attr_t slk_attr(void);

  fun slk_color(color_pair_number : CShort) : CInt

  ## termattrs...
  fun baudrate : CInt
  fun erasechar : CChar
  fun killchar : CChar

  # TODO:
  #
  # C-prototype: int erasewchar(wchar_t *ch);

  fun has_ic : NCBool
  fun has_il : NCBool

  # TODO:
  #
  # C-prototype: int killwchar(wchar_t *ch);
  # C-prototype: attr_t term_attrs(void);

  fun termattrs : ChType
  fun longname : PChar
  fun termname : PChar

  ## termcap...

  # TODO:
  #
  # C-prototype: extern char PC; extern char *  UP;  extern  char  *  BC;  extern  short ospeed;
  # C-prototype: int tgetent(char *bp, const char *name);

  fun tgetflag(id : PChar) : CInt
  fun tgetnum(id : PChar) : CInt

  # TODO:
  #
  # C-prototype: char *tgetstr(char *id, char **area);
  # C-prototype: char *tgoto(const char *cap, int col, int row);
  # C-prototype: int tputs(const char *str, int affcnt, int (*putc)(int));

  ## terminfo...

  # TODO:
  #
  # C-prototype: int setupterm(char *term, int fildes, int *errret);
  # C-prototype: int setterm(char *term);
  # C-prototype: TERMINAL *set_curterm(TERMINAL *nterm);
  # C-prototype: int del_curterm(TERMINAL *oterm);
  # C-prototype: int restartterm(const char *term, int fildes, int *errret);
  # C-prototype: char *tparm(char *str, ...);
  # C-prototype: int tputs(const char *str, int affcnt, int (*putc)(int));
  # C-prototype: int putp(const char *str);
  # C-prototype: int vidputs(chtype attrs, int (*putc)(int));
  # C-prototype: int vidattr(chtype attrs);
  # C-prototype: int vid_puts(attr_t attrs, short pair, void *opts, int (*putc)(char));
  # C-prototype: int vid_attr(attr_t attrs, short pair, void *opts);
  # C-prototype: int mvcur(int oldrow, int oldcol, int newrow, int newcol);
  # C-prototype: int tigetflag(char *capname);
  # C-prototype: int tigetnum(char *capname);
  # C-prototype: char *tigetstr(char *capname);

  ## touch...
  fun touchwin(win : WindowPtr) : CInt
  fun untouchwin(win : WindowPtr) : CInt
  fun touchline(win : WindowPtr, start : CInt, count : CInt) : CInt
  fun wtouchln(win : WindowPtr, y : CInt, n : CInt, changed : CInt) : CInt
  fun is_wintouched(win : WindowPtr) : NCBool
  fun is_linetouched(win : WindowPtr, line : CInt) : NCBool

  ## util...
  fun unctrl(c : ChType) : PChar
  fun keyname(c : CInt) : PChar
  fun filter : Void
  fun use_env(f : NCBool) : Void
  fun delay_output(ms : CInt) : CInt
  fun flushinp : CInt

  # TODO:
  #
  # C-prototype: char *wunctrl(cchar_t *c);
  # C-prototype: char *key_name(wchar_t w);
  # C-prototype: int putwin(WINDOW *win, FILE *filep);
  # C-prototype: WINDOW *getwin(FILE *filep);

  ## window...
  fun newwin(nlines : CInt, ncols : CInt, beginY : CInt, beginX : CInt) : WindowPtr
  fun delwin(win : WindowPtr) : CInt
  fun wsyncup(win : WindowPtr) : Void
  fun wcursyncup(win : WindowPtr) : Void
  fun wsyncdown(win : WindowPtr) : Void
  fun mvwin(win : WindowPtr, y : CInt, x : CInt) : CInt
  fun mvderwin(win : WindowPtr, y : CInt, x : CInt) : CInt
  fun subwin(orig : WindowPtr, nlines : CInt, ncols : CInt, beginY : CInt, beginX : CInt) : WindowPtr
  fun dupwin(win : WindowPtr) : WindowPtr
  fun syncok(win : WindowPtr, bf : NCBool) : CInt

  ## wresize...
  fun wresize(win : WindowPtr, lines : CInt, columns : CInt) : CInt

  ## mouse...

  # :nodoc:
  fun c_mousemask = "mousemask"(newmask : CULong, oldmask : PVoid) : CULong

  # :nodoc:
  fun c_getmouse = "getmouse"(event : PVoid) : CInt

  # :nodoc:
  fun c_ungetmouse = "ungetmouse"(event : PVoid) : CInt

  fun wenclose(win : WindowPtr, y : CInt, x : CInt) : NCBool
  fun mouse_trafo(py : PVoid, px : PVoid, toScreen : Bool) : NCBool
  fun mouse_wtrafo(win : WindowPtr, py : PVoid, px : PVoid, toScreen : Bool) : NCBool
  fun mouseinterval(erval : CInt) : CInt
  fun has_mouse : NCBool
end
{% end %}

# Low-level bindings to the ncurses library.  This is actually a very, very thin
# wrapper around the `LibNCurses` C bindings.  It is expected that you use this
# module rather than calling directly into `LibNCurses`.
module NCurses
  extend self

  alias WindowPtr = LibNCurses::WindowPtr

  TRUE  = 1u8
  FALSE = 0u8
  ERR   = -1
  OK    = 0

  enum Acs : UInt8
    Ulcorner = 108u8 # Upper left corner
    Llcorner = 109u8 # Lower left corner
    Urcorner = 107u8 # Upper right corner
    Lrcorner = 106u8 # Lower right corner
    Ltee     = 116u8 # Tee pointing right
    Rtee     = 117u8 # Tee pointing left
    Btee     = 118u8 # Tee pointing up
    Ttee     = 119u8 # Tee pointing down
    Hline    = 113u8 # Horizontal line
    Vline    = 120u8 # Vertical line
    Plus     = 110u8 # Large plus or crossover
    S1       = 111u8 # Scan line 1
    S9       = 115u8 # Scan line 9
    Diamond  = 96u8 # Diamond
    Ckboard  = 97u8 # Checker board (stipple)
    Degree   = 102u8 # Degree symbol
    Plminus  = 103u8 # Plus/minus symbol
    Bullet   = 126u8 # Bullet

    # Returns the value of `self` logical OR'ed with `Attribute::AltCharSet`.
    def toBorderChar : LibNCurses::ChType
      Attribute::AltCharSet.value | self.value
    end
  end

  BUTTON1_RELEASED = 0x1
  BUTTON1_PRESSED = 0x2
  BUTTON1_CLICKED = 0x4
  BUTTON1_DOUBLE_CLICKED = 0x8
  BUTTON1_TRIPLE_CLICKED = 0x10

  BUTTON2_RELEASED = 0x40
  BUTTON2_PRESSED = 0x80
  BUTTON2_CLICKED = 0x100
  BUTTON2_DOUBLE_CLICKED = 0x200
  BUTTON2_TRIPLE_CLICKED = 0x400

  BUTTON3_RELEASED = 0x1000
  BUTTON3_PRESSED = 0x2000
  BUTTON3_CLICKED = 0x4000
  BUTTON3_DOUBLE_CLICKED = 0x8000
  BUTTON3_TRIPLE_CLICKED = 0x10000

  BUTTON_CTRL = 0x1000000
  BUTTON_SHIFT = 0x2000000
  BUTTON_ALT = 0x4000000

  ALL_MOUSE_EVENTS = 0x7FFFFFF
  REPORT_MOUSE_POSITION = 0x8000000

  enum Color : Int32 # These were originally constants
    Black   = 0
    Red     = 1
    Green   = 2
    Yellow  = 3
    Blue    = 4
    Magenta = 5
    Cyan    = 6
    White   = 7
  end

  enum KeyCode : Int32
    Break     = 0o401
    SReset    = 0o530
    Reset     = 0o531
    Down      = 0o402
    Up        = 0o403
    Left      = 0o404
    Right     = 0o405
    Home      = 0o406
    Backspace = 0o407
    F0        = 0o410
    F1        = 0o411
    F2        = 0o412
    F3        = 0o413
    F4        = 0o414
    F5        = 0o415
    F6        = 0o416
    F7        = 0o417
    F8        = 0o420
    F9        = 0o421
    F10       = 0o422
    F11       = 0o423
    F12       = 0o424
    Dl        = 0o510
    Il        = 0o511
    Dc        = 0o512
    Ic        = 0o513
    Eic       = 0o514
    Clear     = 0o515
    Eos       = 0o516
    Eol       = 0o517
    Sf        = 0o520
    Sr        = 0o521
    Npage     = 0o522
    Ppage     = 0o523
    STab      = 0o524
    CTab      = 0o525
    CaTab     = 0o526
    Enter     = 0o527
    Print     = 0o532
    Ll        = 0o533
    A1        = 0o534
    A3        = 0o535
    B2        = 0o536
    C1        = 0o537
    C3        = 0o540
    BTab      = 0o541
    Beg       = 0o542
    Cancel    = 0o543
    Close     = 0o544
    Command   = 0o545
    Copy      = 0o546
    Create    = 0o547
    End       = 0o550
    Exit      = 0o551
    Find      = 0o552
    Help      = 0o553
    Mark      = 0o554
    Message   = 0o555
    Move      = 0o556
    Next      = 0o557
    Open      = 0o560
    Options   = 0o561
    Previous  = 0o562
    Redo      = 0o563
    Reference = 0o564
    Refresh   = 0o565
    Replace   = 0o566
    Restart   = 0o567
    Resume    = 0o570
    Save      = 0o571
    SBeg      = 0o572
    SCancel   = 0o573
    SCommand  = 0o574
    SCopy     = 0o575
    SCreate   = 0o576
    Sdc       = 0o577
    Sdl       = 0o600
    Select    = 0o601
    SEnd      = 0o602
    SEol      = 0o603
    SExit     = 0o604
    SFind     = 0o605
    SHelp     = 0o606
    SHome     = 0o607
    Sic       = 0o610
    SLeft     = 0o611
    SMessage  = 0o612
    SMove     = 0o613
    SNext     = 0o614
    SOptions  = 0o615
    SPrevious = 0o616
    SPrint    = 0o617
    SRedo     = 0o620
    SReplace  = 0o621
    SRight    = 0o622
    SRsume    = 0o623
    SSave     = 0o624
    SSuspend  = 0o625
    SUndo     = 0o626
    Suspend   = 0o627
    Undo      = 0o630
    Mouse     = 0o631
    Resize    = 0o632
    Event     = 0o633
  end

  # XSI attributes.  In the ncurses implementation, they are identical to the
  # `A_` attributes.
  @[Flags]
  enum Attribute : UInt32
    Attributes = 0xFFFFFF00
    Normal     = 0x00000000
    Standout   = 0x00010000
    Underline  = 0x00020000
    Reverse    = 0x00040000
    Blink      = 0x00080000
    Dim        = 0x00100000
    Bold       = 0x00200000
    AltCharSet = 0x00400000
    Invis      = 0x00800000
    Protect    = 0x01000000
    Horizontal = 0x02000000 # XSI Curses attr -- not yet used
    Left       = 0x04000000 # XSI Curses attr -- not yet used
    Low        = 0x08000000 # XSI Curses attr -- not yet used
    Right      = 0x10000000 # XSI Curses attr -- not yet used
    Top        = 0x20000000 # XSI Curses attr -- not yet used
    Vertical   = 0x40000000 # XSI Curses attr -- not yet used
  end

  # XSI attributes.  In the ncurses implementation, they are identical to the
  # `A_` attributes.
  @[Flags]
  enum WaAttribute : UInt32
    Attributes = 0xFFFFFF00
    Normal     = 0x00000000
    Standout   = 0x00010000
    Underline  = 0x00020000
    Reverse    = 0x00040000
    Blink      = 0x00080000
    Dim        = 0x00100000
    Bold       = 0x00200000
    AltCharSet = 0x00400000
    Invis      = 0x00800000
    Protect    = 0x01000000
    Horizontal = 0x02000000 # XSI Curses attr -- not yet used
    Left       = 0x04000000 # XSI Curses attr -- not yet used
    Low        = 0x08000000 # XSI Curses attr -- not yet used
    Right      = 0x10000000 # XSI Curses attr -- not yet used
    Top        = 0x20000000 # XSI Curses attr -- not yet used
    Vertical   = 0x40000000 # XSI Curses attr -- not yet used
  end

  def getwch : Tuple(UInt32?, Int32)
    result = c_get_wch(out ch)
    if result == ERR
      {nil, ERR}
    else
      {ch, result}
    end
  end

  def wgetwch(win : WindowPtr) : Tuple(UInt32?, CInt32)
    result = c_wget_wch(win, out ch)
    if result == ERR
      {nil, ERR}
    else
      {ch, result}
    end
  end

  def mvgetwch(y : Int32, x : Int32) : Tuple(UInt32?, Int32)
    result = c_mvget_wch(y, x, out ch)
    if result == ERR
      {nil, ERR}
    else
      {ch, result}
    end
  end

  def mvwgetwch(win : WindowPtr, y : Int32, x : Int32) : Tuple(UInt32?, Int32)
    result = c_mvwget_wch(win, y, x, out ch)
    if result == ERR
      {nil, ERR}
    else
      {ch, result}
    end
  end

  def mousemask(newMask : UInt32) : UInt32
    LibNCurses.c_mousemask(newMask, out oldMask)
    oldMask
  end

  def getmouse : Tuple(UInt64, Int32, Int32, Int32, Int16)
    result = LibNCurses.c_getmouse(out ptr)
    if result == ERR
      raise "Error in curses call getmouse"
    end

    evt = ptr.unsafe_as(Pointer(LibNCurses::MEvent))
    {evt.value.bstate, evt.value.x, evt.value.y, evt.value.z, evt.value.id}
  end

  @[AlwaysInline]
  def border(ls : Int, rs : Int, ts : Int, bs : Int,
             tl : Int, tr : Int, bl : Int, br : Int) : Int32
    LibNCurses.c_border(ls, rs, ts, bs, tl, tr, bl, br)
  end

  @[AlwaysInline]
  def wborder(win : WindowPtr, ls : Int, rs : Int, ts : Int, bs : Int,
              tl : Int, tr : Int, bl : Int, br : Int) : Int32
    LibNCurses.c_wborder(win, ls, rs, ts, bs, tl, tr, bl, br)
  end

  @[AlwaysInline]
  def box(win : WindowPtr, verCh : Int, horCh : Int) : Int32
    LibNCurses.box(win, verCh, horCh)
  end

  @[AlwaysInline]
  def border(ls : Acs, rs : Acs, ts : Acs, bs : Acs,
             tl : Acs, tr : Acs, bl : Acs, br : Acs) : Int32
    altChrSet : UInt32 = Attribute::AltCharSet.value
    border(altChrSet | ls.value,
           altChrSet | rs.value,
           altChrSet | ts.value,
           altChrSet | bs.value,
           altChrSet | tl.value,
           altChrSet | tr.value,
           altChrSet | bl.value,
           altChrSet | br.value)
  end

  @[AlwaysInline]
  def wborder(win : WindowPtr, ls : Acs, rs : Acs, ts : Acs, bs : Acs,
              tl : Acs, tr : Acs, bl : Acs, br : Acs) : Int32
    altChrSet : UInt32 = Attribute::AltCharSet.value
    wborder(win,
            altChrSet | ls.value,
            altChrSet | rs.value,
            altChrSet | ts.value,
            altChrSet | bs.value,
            altChrSet | tl.value,
            altChrSet | tr.value,
            altChrSet | bl.value,
            altChrSet | br.value)
  end

  @[AlwaysInline]
  def box(win : WindowPtr, verCh : Acs, horCh : Acs) : Int32
    altChrSet : UInt32 = Attribute::AltCharSet.value
    box(win, altChrSet | verCh.value, altChrSet | horCh.value)
  end

  @[AlwaysInline]
  def hline(ch : Int, n : Int) : Int32
    LibNCurses.c_hline(ch, n)
  end

  @[AlwaysInline]
  def vline(ch : Int, n : Int) : Int32
    LibNCurses.c_vline(ch, n)
  end

  @[AlwaysInline]
  def whline(win : WindowPtr, ch : Int, n : Int) : Int32
    LibNCurses.c_whline(win, ch, n)
  end

  @[AlwaysInline]
  def wvline(win : WindowPtr, ch : Int, n : Int) : Int32
    LibNCurses.c_wvline(win, ch, n)
  end

  @[AlwaysInline]
  def mvhline(y : Int, x : Int, ch : Int, n : Int) : Int32
    LibNCurses.c_mvhline(y, x, ch, n)
  end

  @[AlwaysInline]
  def mvvline(y : Int, x : Int, ch : Int, n : Int) : Int32
    LibNCurses.c_mvvline(y, x, ch, n)
  end

  @[AlwaysInline]
  def mvwhline(win : WindowPtr, y : Int, x : Int, ch : Int, n : Int) : Int32
    LibNCurses.c_mvwhline(win, y, x, ch, n)
  end

  @[AlwaysInline]
  def mvwvline(win : WindowPtr, y : Int, x : Int, ch : Int, n : Int) : Int32
    LibNCurses.c_mvwvline(win, y, x, ch, n)
  end

  @[AlwaysInline]
  def hline(ch : Acs, n : Int) : Int32
    hline(Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def vline(ch : Acs, n : Int) : Int32
    vline(Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def whline(win : WindowPtr, ch : Acs, n : Int) : Int32
    whline(win, Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def wvline(win : WindowPtr, ch : Acs, n : Int) : Int32
    wvline(win, Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def mvhline(y : Int, x : Int, ch : Acs, n : Int) : Int32
    mvhline(y, x, Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def mvvline(y : Int, x : Int, ch : Acs, n : Int) : Int32
    mvvline(y, x, Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def mvwhline(win : WindowPtr, y : Int, x : Int, ch : Acs, n : Int) : Int32
    mvwhline(win, y, x, Attribute::AltCharSet.value | ch.value, n)
  end

  @[AlwaysInline]
  def mvwvline(win : WindowPtr, y : Int, x : Int, ch : Acs, n : Int) : Int32
    mvwvline(win, y, x, Attribute::AltCharSet.value | ch.value, n)
  end

  {% begin %}
    {% for fn in LibNCurses.methods %}
      {% unless fn.name.stringify.starts_with?("c_") %}
        @[AlwaysInline]
        def {{fn.name}}({{*fn.args}})
          LibNCurses.{{fn.name}}({{*fn.args.map(&.name)}})
        end
      {% end %}
    {% end %}
  {% end %}

  {% begin %}
    {% for i in [[:getyx, :getcury, :getcurx],
                 [:getparyx, :getary, :getparx],
                 [:getmaxyx, :getmaxy, :getmaxx],
                 [:getbegyx, :getbegy, :getbegx]] %}
      @[AlwaysInline]
      def {{i[0].id}}(win : WindowPtr) : Tuple(Int32, Int32)
        %y = {{i[1].id}}(win)
        %x = {{i[2].id}}(win)
        { %y, %x }
      end
    {% end %}
  {% end %}
end