|
@@ -2,6 +2,7 @@
|
2
|
2
|
#include <malloc.h>
|
3
|
3
|
#include <stddef.h>
|
4
|
4
|
#include <vsprintf.h>
|
|
5
|
+#include <string.h>
|
5
|
6
|
|
6
|
7
|
/** @file
|
7
|
8
|
*
|
|
@@ -25,6 +26,26 @@ struct cursor_pos {
|
25
|
26
|
unsigned int y, x;
|
26
|
27
|
};
|
27
|
28
|
|
|
29
|
+struct _softlabel {
|
|
30
|
+ /* Format of soft label
|
|
31
|
+ 0: left justify
|
|
32
|
+ 1: centre justify
|
|
33
|
+ 2: right justify
|
|
34
|
+ */
|
|
35
|
+ int fmt;
|
|
36
|
+ // label string
|
|
37
|
+ char *label;
|
|
38
|
+};
|
|
39
|
+
|
|
40
|
+struct _softlabelkeys {
|
|
41
|
+ struct _softlabel fkeys[12];
|
|
42
|
+ attr_t attrs;
|
|
43
|
+ unsigned int fmt;
|
|
44
|
+ unsigned int maxlablen;
|
|
45
|
+};
|
|
46
|
+
|
|
47
|
+struct _softlabelkeys *slks;
|
|
48
|
+
|
28
|
49
|
WINDOW _stdscr = {
|
29
|
50
|
.attrs = A_DEFAULT,
|
30
|
51
|
.ori_y = 0,
|
|
@@ -146,7 +167,7 @@ int wmove ( WINDOW *win, int y, int x ) {
|
146
|
167
|
* @ret bps return baud rate in bits per second
|
147
|
168
|
*/
|
148
|
169
|
int baudrate ( void ) {
|
149
|
|
- return 0;
|
|
170
|
+ return OK;
|
150
|
171
|
}
|
151
|
172
|
|
152
|
173
|
/**
|
|
@@ -286,6 +307,177 @@ WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
|
286
|
307
|
return win;
|
287
|
308
|
}
|
288
|
309
|
|
|
310
|
+/**
|
|
311
|
+ * Return the attribute used for the soft function keys
|
|
312
|
+ *
|
|
313
|
+ * @ret attrs the current attributes of the soft function keys
|
|
314
|
+ */
|
|
315
|
+attr_t slk_attr ( void ) {
|
|
316
|
+ return ( slks == NULL ? 0 : slks->attrs );
|
|
317
|
+}
|
|
318
|
+
|
|
319
|
+/**
|
|
320
|
+ * Turn off soft function key attributes
|
|
321
|
+ *
|
|
322
|
+ * @v attrs attribute bit mask
|
|
323
|
+ * @ret rc return status code
|
|
324
|
+ */
|
|
325
|
+int slk_attroff ( const chtype attrs ) {
|
|
326
|
+ if ( slks == NULL )
|
|
327
|
+ return ERR;
|
|
328
|
+ slks->attrs &= ~( attrs & A_ATTRIBUTES );
|
|
329
|
+ return OK;
|
|
330
|
+}
|
|
331
|
+
|
|
332
|
+/**
|
|
333
|
+ * Turn on soft function key attributes
|
|
334
|
+ *
|
|
335
|
+ * @v attrs attribute bit mask
|
|
336
|
+ * @ret rc return status code
|
|
337
|
+ */
|
|
338
|
+int slk_attron ( const chtype attrs ) {
|
|
339
|
+ if ( slks == NULL )
|
|
340
|
+ return ERR;
|
|
341
|
+ slks->attrs |= ( attrs & A_ATTRIBUTES );
|
|
342
|
+ return OK;
|
|
343
|
+}
|
|
344
|
+
|
|
345
|
+/**
|
|
346
|
+ * Set soft function key attributes
|
|
347
|
+ *
|
|
348
|
+ * @v attrs attribute bit mask
|
|
349
|
+ * @ret rc return status code
|
|
350
|
+ */
|
|
351
|
+int slk_attrset ( const chtype attrs ) {
|
|
352
|
+ if ( slks == NULL )
|
|
353
|
+ return ERR;
|
|
354
|
+ slks->attrs = ( attrs & A_ATTRIBUTES );
|
|
355
|
+ return OK;
|
|
356
|
+}
|
|
357
|
+
|
|
358
|
+/**
|
|
359
|
+ * Turn off soft function key attributes
|
|
360
|
+ *
|
|
361
|
+ * @v attrs attribute bit mask
|
|
362
|
+ * @v *opts undefined (for future implementation)
|
|
363
|
+ * @ret rc return status code
|
|
364
|
+ */
|
|
365
|
+int slk_attr_off ( const attr_t attrs, void *opts __unused ) {
|
|
366
|
+ return slk_attroff( attrs );
|
|
367
|
+}
|
|
368
|
+
|
|
369
|
+/**
|
|
370
|
+ * Turn on soft function key attributes
|
|
371
|
+ *
|
|
372
|
+ * @v attrs attribute bit mask
|
|
373
|
+ * @v *opts undefined (for future implementation)
|
|
374
|
+ * @ret rc return status code
|
|
375
|
+ */
|
|
376
|
+int slk_attr_on ( attr_t attrs, void *opts __unused ) {
|
|
377
|
+ return slk_attron( attrs );
|
|
378
|
+}
|
|
379
|
+
|
|
380
|
+/**
|
|
381
|
+ * Set soft function key attributes
|
|
382
|
+ *
|
|
383
|
+ * @v attrs attribute bit mask
|
|
384
|
+ * @v colour_pair_number colour pair integer
|
|
385
|
+ * @v *opts undefined (for future implementation)
|
|
386
|
+ * @ret rc return status code
|
|
387
|
+ */
|
|
388
|
+int slk_attr_set ( const attr_t attrs, short colour_pair_number,
|
|
389
|
+ void *opts __unused ) {
|
|
390
|
+ if ( slks == NULL )
|
|
391
|
+ return ERR;
|
|
392
|
+
|
|
393
|
+ if ( ( unsigned short )colour_pair_number > COLORS )
|
|
394
|
+ return ERR;
|
|
395
|
+
|
|
396
|
+ slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT ) |
|
|
397
|
+ ( attrs & A_ATTRIBUTES );
|
|
398
|
+ return OK;
|
|
399
|
+}
|
|
400
|
+
|
|
401
|
+/**
|
|
402
|
+ * Clear the soft function key labels from the screen
|
|
403
|
+ *
|
|
404
|
+ * @ret rc return status code
|
|
405
|
+ */
|
|
406
|
+int slk_clear ( void ) {
|
|
407
|
+ if ( slks == NULL )
|
|
408
|
+ return ERR;
|
|
409
|
+
|
|
410
|
+ wmove(stdscr,stdscr->height-1,0);
|
|
411
|
+ wclrtoeol(stdscr);
|
|
412
|
+ return 0;
|
|
413
|
+}
|
|
414
|
+
|
|
415
|
+/**
|
|
416
|
+ * Initialise the soft function keys
|
|
417
|
+ *
|
|
418
|
+ * @v fmt format of keys
|
|
419
|
+ * @ret rc return status code
|
|
420
|
+ */
|
|
421
|
+int slk_init ( int fmt ) {
|
|
422
|
+ if ( (unsigned)fmt > 3 ) {
|
|
423
|
+ return ERR;
|
|
424
|
+ }
|
|
425
|
+
|
|
426
|
+ slks = malloc(sizeof(struct _softlabelkeys));
|
|
427
|
+ slks->attrs = A_DEFAULT;
|
|
428
|
+ slks->fmt = fmt;
|
|
429
|
+ slks->maxlablen = 5;
|
|
430
|
+ return OK;
|
|
431
|
+}
|
|
432
|
+
|
|
433
|
+/**
|
|
434
|
+ * Return the label for the specified soft key
|
|
435
|
+ *
|
|
436
|
+ * @v labnum soft key identifier
|
|
437
|
+ * @ret label return label
|
|
438
|
+ */
|
|
439
|
+char* slk_label ( int labnum ) {
|
|
440
|
+ if ( slks == NULL )
|
|
441
|
+ return NULL;
|
|
442
|
+
|
|
443
|
+ return slks->fkeys[labnum].label;
|
|
444
|
+}
|
|
445
|
+
|
|
446
|
+/**
|
|
447
|
+ * Restore soft function key labels to the screen
|
|
448
|
+ *
|
|
449
|
+ * @ret rc return status code
|
|
450
|
+ */
|
|
451
|
+int slk_restore ( void ) {
|
|
452
|
+ if ( slks == NULL )
|
|
453
|
+ return ERR;
|
|
454
|
+
|
|
455
|
+ return OK;
|
|
456
|
+}
|
|
457
|
+
|
|
458
|
+/**
|
|
459
|
+ * Configure specified soft key
|
|
460
|
+ *
|
|
461
|
+ * @v labnum soft label position to configure
|
|
462
|
+ * @v *label string to use as soft key label
|
|
463
|
+ * @v fmt justification format of label
|
|
464
|
+ * @ret rc return status code
|
|
465
|
+ */
|
|
466
|
+int slk_set ( int labnum, const char *label, int fmt ) {
|
|
467
|
+ if ( slks == NULL )
|
|
468
|
+ return ERR;
|
|
469
|
+ if ( labnum == 0 || (unsigned)labnum > 12 )
|
|
470
|
+ return ERR;
|
|
471
|
+ if ( (unsigned)fmt >= 3 )
|
|
472
|
+ return ERR;
|
|
473
|
+ if ( strlen(label) > slks->maxlablen )
|
|
474
|
+ return ERR;
|
|
475
|
+
|
|
476
|
+ strcpy( slks->fkeys[labnum].label, label );
|
|
477
|
+ slks->fkeys[labnum].fmt = fmt;
|
|
478
|
+
|
|
479
|
+ return OK;
|
|
480
|
+}
|
289
|
481
|
|
290
|
482
|
struct printw_context {
|
291
|
483
|
struct printf_context ctx;
|
|
@@ -369,7 +561,7 @@ int waddnstr ( WINDOW *win, const char *str, int n ) {
|
369
|
561
|
*/
|
370
|
562
|
int wattroff ( WINDOW *win, int attrs ) {
|
371
|
563
|
win->attrs &= ~attrs;
|
372
|
|
- return 0;
|
|
564
|
+ return OK;
|
373
|
565
|
}
|
374
|
566
|
|
375
|
567
|
/**
|