Skip to content

Commit 731a50a

Browse files
committed
[terminfo] fix tiparm_s()
1 parent 17028b8 commit 731a50a

6 files changed

Lines changed: 45 additions & 7 deletions

File tree

src/third-party/notcurses/include/notcurses/notcurses.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include <notcurses/nckeys.h>
1717
#include <notcurses/ncseqs.h>
1818

19+
#include "terminfo/terminfo.h"
20+
21+
extern Terminfo* notcurses_terminfo;
22+
1923
#ifdef __cplusplus
2024
extern "C" {
2125
#define RESTRICT

src/third-party/notcurses/include/terminfo/terminfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include <stdint.h>
55

6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
610
#define TERMINFO_MAGIC 0x011A
711
#define TERMINFO_MAGIC_32BIT 0x021E
812

@@ -74,4 +78,8 @@ tiparm_str(const char* value)
7478
return v;
7579
}
7680

81+
#ifdef __cplusplus
82+
}
83+
#endif
84+
7785
#endif

src/third-party/notcurses/src/lib/internal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,16 +1937,14 @@ encoding_is_utf8(const char *enc){
19371937
// tell ncmetric that utf8 is available. should be per-context, but isn't.
19381938
void ncmetric_use_utf8(void);
19391939

1940-
extern Terminfo* notcurses_terminfo;
1941-
19421940
#ifdef __cplusplus
19431941
extern "C" {
19441942
#define NCURSES_CAST(type,value) static_cast<type>(value)
19451943
#else
19461944
#define NCURSES_CAST(type,value) (type)(value)
19471945
#endif
19481946

1949-
typedef unsigned chtype;
1947+
typedef int32_t chtype;
19501948

19511949
#define NCURSES_ATTR_SHIFT 8
19521950
#define NCURSES_BITS(mask,shift) (NCURSES_CAST(chtype,(mask)) << ((shift) + NCURSES_ATTR_SHIFT))

src/third-party/notcurses/src/lib/terminfo.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,16 @@ tiparm_s(const char* fmt, int argc, TiparmValue* argv)
440440
int skip = 0; // skip logic block
441441
int cond_level = 0;
442442
int exec = 1; // whether we're in an active (true) branch
443+
int cond_execed = 0;
443444

444445
while (*p) {
445446
if (*p == '%') {
446447
p++;
447448
switch (*p) {
448449
case '%':
449-
if (exec && out_len + 1 < out_cap)
450+
if (exec && out_len + 1 < out_cap) {
450451
out[out_len++] = '%';
452+
}
451453
p++;
452454
break;
453455
case 'p': {
@@ -554,21 +556,31 @@ tiparm_s(const char* fmt, int argc, TiparmValue* argv)
554556
break;
555557
}
556558
case '?': // start conditional
559+
exec = 1;
560+
cond_execed = 0;
557561
cond_level++;
558562
p++;
559563
break;
560564
case 't': {
561565
StackVal v = pop(&stack);
562-
exec = (v.type == STK_INT && v.i);
566+
exec = exec && (v.type == STK_INT && v.i);
567+
if (exec) {
568+
cond_execed = 1;
569+
}
563570
p++;
564571
break;
565572
}
566573
case 'e': // else
567-
exec = !exec;
574+
if (cond_execed) {
575+
exec = 0;
576+
} else {
577+
exec = !exec;
578+
}
568579
p++;
569580
break;
570581
case ';': // end if
571582
cond_level--;
583+
cond_execed = 0;
572584
exec = 1;
573585
p++;
574586
break;

src/view_curses.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "view_curses.hh"
3838

39-
#include <curses.h>
4039
#include <zlib.h>
4140

4241
#include "base/ansi_scrubber.hh"
@@ -49,6 +48,7 @@
4948
#include "config.h"
5049
#include "lnav_config.hh"
5150
#include "shlex.hh"
51+
#include "terminfo/terminfo.h"
5252
#include "uniwidth.h"
5353
#include "xterm_mouse.hh"
5454

test/lnav_doctests.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "shlex.hh"
4545
#include "unique_path.hh"
4646

47+
#include "terminfo/terminfo.h"
48+
4749
using namespace std;
4850

4951
#if 0
@@ -81,6 +83,20 @@ TEST_CASE("shlex::eval")
8183
CHECK(rc);
8284
CHECK(out == "foo");
8385
}
86+
#if 0
87+
TEST_CASE("tiparm_s")
88+
{
89+
const auto* path = terminfo_find_path_for_term("xterm-256color");
90+
auto* ti = terminfo_load(path);
91+
92+
TiparmValue argv[] = {tiparm_int(5)};
93+
const auto* fmt = terminfo_get_string_by_name(ti, "setab");
94+
auto_mem<char> ab1;
95+
ab1 = tiparm_s(fmt, 1, argv);
96+
fprintf(stderr, "ab = %s", &(ab1.in()[1]));
97+
terminfo_free(ti);
98+
}
99+
#endif
84100

85101
TEST_CASE("lnav::command::parse_for_prompt")
86102
{

0 commit comments

Comments
 (0)