C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Manage View Display

Manage the View Display. More...

Functions

void display_line (View *view)
 Display Line on Padparam View *view data structure.
void display_line_eod (View *view)
 Display End of Data.
int display_prompt (View *view, char *s)
 Display Command Line Prompt.
void display_split_line (View *view)
 Display Split Line on Pad.
int fmt_line (View *view)
 Format Line for Display.
void log_cc_buf (View *view)
 Log Complex Character Buffer.
void log_split_lines (View *view)
 Log Split Lines.
void log_stripped_line_out (View *view)
 Log Stripped Line Output.
void log_strnz (char *str, uint len)
 Log String with Specified Length.
int pad_refresh (View *view)
 Refresh Pad and Line Number Window.
void parse_ansi_str (char *ansi_str, attr_t *attr, ushort *cpx)
 Parse ANSI SGR Escape Sequence.
void view_display_help (Init *init)
 Display View Help File.
void view_display_page (View *view)
 Display Current Page.

Detailed Description

Manage the View Display.

Function Documentation

◆ display_line()

void display_line ( View * view)

Display Line on Padparam View *view data structure.

This function displays a single line of text on the ncurses pad. If line numbering is enabled (view->f_ln), it is formatted and displayed at the beginning of the line with the specified attributes and color pair.

Because get_next_char calls increment_ln upon encountering a line feed and increment_ln advances view->ln_no after updating the line table, the line number displayed is one greater than the index to the line table. That means the line counter begins with 1, while the table origin is 0.

Definition at line 1395 of file view_engine.c.

1395 {
1396 char ln_s[16];
1397
1398 UiSurface *sfc = view->sfc;
1399 if (view->wrap && view->cur.sl_cnt > 0) {
1400 if (view->cur.sl_idx < view->cur.sl_cnt) {
1402 return;
1403 }
1404 }
1405 if (view->cury > view->scroll_lines - 1)
1406 view->cury = view->scroll_lines - 1;
1407 if (view->f_ln) {
1408 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1409 ui_cursor_move(sfc, LNNO, view->cury, 0);
1410 ui_wclrtoeol(sfc, LNNO);
1411 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1412 }
1413 ui_cursor_move(sfc, PAD, view->cury, 0);
1414 ui_wclrtoeol(sfc, PAD);
1415#ifdef UAL_UI
1416 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, view->cmplx_buf);
1417#else
1418 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, (struct nccell *)view->cmplx_buf);
1419#endif
1420 if (view->cury == 0)
1421 view->page_top_ln_no = view->ln_no;
1422 if (view->cury == view->scroll_lines - 1)
1423 view->page_bot_ln_no = view->ln_no;
1424 view->cury++;
1425}
int ui_mvwadd_wchstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:727
int ui_mvwaddstr(UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_wclrtoeol(UiSurface *s, uint w)
View * view
Definition mem.c:38
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:413
void display_split_line(View *)
Display Split Line on Pad.
A drawable surface in the NotCurses backend.
Definition nccell.h:3

References View::cmplx_buf, View::cur, View::cury, display_split_line(), View::f_ln, View::ln_no, LNNO, PAD, View::page_bot_ln_no, View::page_top_ln_no, View::scroll_lines, View::sfc, SplitLine::sl_cnt, SplitLine::sl_idx, ssnprintf(), ui_cursor_move(), ui_mvwadd_wchstr(), ui_mvwaddstr(), ui_wclrtoeol(), and View::wrap.

Referenced by scroll_down(), scroll_up(), search(), and view_display_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_line_eod()

void display_line_eod ( View * view)

Display End of Data.

Parameters
viewdata structure

This function is called when the end of the file is reached and there are no more lines to display. It clears the remaining lines in the pad and line number window (if line numbering is enabled) to ensure that no residual content from previous lines is displayed.

Definition at line 1485 of file view_engine.c.

1485 {
1486 UiSurface *sfc = view->sfc;
1487 if (view->f_ln) {
1488 ui_cursor_move(sfc, LNNO, view->cury, 0);
1489 ui_wclrtobot(sfc, LNNO);
1490 }
1491 ui_cursor_move(sfc, PAD, view->cury, 0);
1492 ui_wclrtobot(sfc, PAD);
1493 view->page_bot_ln_no = view->ln_no;
1494}
int ui_wclrtobot(UiSurface *s, uint w)

References View::cury, View::f_ln, View::ln_no, LNNO, PAD, View::page_bot_ln_no, View::sfc, ui_cursor_move(), and ui_wclrtobot().

Referenced by view_display_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_prompt()

int display_prompt ( View * view,
char * s )

Display Command Line Prompt.

Parameters
viewis the current view data structure
sis the prompt string

Definition at line 2538 of file view_engine.c.

2538 {
2539 char message_str[PAD_COLS + 1];
2540 uint l;
2541 UiSurface *sfc = view->sfc;
2542 l = strnz__cpy(message_str, s, PAD_COLS);
2543 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
2544 if (l != 0) {
2545 ui_wclrtoeol(sfc, CMDLN);
2547 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 0, " ");
2548 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 1, message_str);
2549 ui_waddstr(sfc, CMDLN, " ");
2550 ui_bkgdset(sfc, CMDLN, &cell_nt);
2551 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
2552 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
2553 }
2554 return (view->curx);
2555}
void ui_getyx(UiSurface *s, uint w, uint *lines, uint *cols)
Definition ui_ncurses.c:668
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
Definition ui_ncurses.c:760
int ui_waddstr(UiSurface *s, uint w, const char *text)
#define PAD_COLS
Definition view.h:41
UiCell cell_nt
Definition dwin.c:94
UiCell cell_nt_rev
Definition dwin.c:95
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537

References cell_nt, cell_nt_rev, View::cmd_line, CMDLN, View::curx, View::sfc, strnz__cpy(), ui_bkgdset(), ui_cursor_move(), ui_getyx(), ui_mvwaddstr(), ui_waddstr(), and ui_wclrtoeol().

Referenced by get_cmd_char(), lp(), new_view_file(), and view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_split_line()

void display_split_line ( View * view)

Display Split Line on Pad.

Parameters
viewdata structure

This function is used to display a line that has been split into multiple segments due to wrapping. It iterates through the segments of the current line (stored in view->cur.sl_cc and view->cur.sl_cells) and displays each segment on the pad, along with the corresponding line number if line numbering is enabled. The function also updates the top and bottom line numbers of the page based on the current position in the split line.

Definition at line 1436 of file view_engine.c.

1436 {
1437 char ln_s[16];
1438 UiSurface *sfc = view->sfc;
1439 if (view->cury > view->scroll_lines - 1)
1440 view->cury = view->scroll_lines - 1;
1441
1442 for (uint i = view->cur.sl_idx; i < view->cur.sl_cnt; i++) {
1443 if (i == 0) {
1444 if (view->f_ln) {
1445 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1446 ui_cursor_move(sfc, LNNO, view->cury, 0);
1447 ui_wclrtoeol(sfc, LNNO);
1448 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1449 }
1450 } else {
1451 if (view->f_ln) {
1452 ui_cursor_move(sfc, LNNO, view->cury, 0);
1453 ui_wclrtoeol(sfc, LNNO);
1454 }
1455 }
1456 ui_cursor_move(sfc, PAD, view->cury, 0);
1457 ui_wclrtoeol(sfc, PAD);
1458 ui_wadd_wchnstr(sfc, PAD, view->cur.sl_cc[i], view->cur.sl_cells[i]);
1459 if (view->cury == 0) {
1460 view->page_top_ln_no = view->ln_no;
1461 view->page_top_sl = true;
1462 view->page_top_sl_idx = i;
1463 view->page_top_sl_cnt = view->cur.sl_cnt;
1464 }
1465 if (view->cury == view->scroll_lines - 1) {
1466 view->page_bot_ln_no = view->ln_no;
1467 view->page_bot_sl = true;
1468 view->page_bot_sl_idx = i;
1469 view->page_bot_sl_cnt = view->cur.sl_cnt;
1470 view->page_bot_ln_no = view->ln_no;
1471 }
1472 view->cury++;
1473 if (view->cury == view->scroll_lines)
1474 break;
1475 }
1476}
int ui_wadd_wchnstr(UiSurface *s, uint w, const UiCell *cell, uint m)

References View::cur, View::cury, View::f_ln, View::ln_no, LNNO, PAD, View::page_bot_ln_no, View::page_bot_sl, View::page_bot_sl_cnt, View::page_bot_sl_idx, View::page_top_ln_no, View::page_top_sl, View::page_top_sl_cnt, View::page_top_sl_idx, View::scroll_lines, View::sfc, SplitLine::sl_cc, SplitLine::sl_cells, SplitLine::sl_cnt, SplitLine::sl_idx, ssnprintf(), ui_cursor_move(), ui_mvwaddstr(), ui_wadd_wchnstr(), and ui_wclrtoeol().

Referenced by display_line().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fmt_line()

int fmt_line ( View * view)

Format Line for Display.

Parameters
viewpointer to View structure containing line input and output buffers
Returns
length of formatted line in characters

This function processes the input line from view->line_in_s, handling ANSI escape sequences for text attributes and colors, as well as multi-byte characters. It converts the input line into a formatted line suitable for display in the terminal, storing the result in view->cmplx_buf and view->stripped_line_out. The function returns the length of the formatted line in characters, which may be used for tracking the maximum column width of the displayed content.

Definition at line 2073 of file view_engine.c.

2073 {
2074 char ansi_tok[MAXLEN];
2075 uint i = 0, j = 0, x = 0;
2076 uint len = 0;
2077 uint tab_spaces = 0;
2078 uint char_width;
2079 attr_t attr = WA_NORMAL;
2080 ushort cpx = cp_nt;
2081 UiCell cc = {0};
2082 wchar_t wstr[2] = {L'\0', L'\0'};
2083 char *in_str = view->line_in_s;
2084 uint sl_cols = 0;
2085 uint sl_cells = 0;
2086 uint word_cells = 0;
2087 UiCell *cmplx_buf = view->cmplx_buf;
2088 view->cur.sl_idx = 0;
2089 view->cur.sl_cnt = 0;
2090 view->cur.sl_cols[0] = 0;
2091 view->cur.sl_cells[0] = 0;
2092 view->cur.sl_s[0] = nullptr;
2093 view->cur.sl_cc[0] = nullptr;
2094 char *sl_s = view->stripped_line_out;
2095 UiCell *sl_cc = view->cmplx_buf;
2096 rtrim(view->line_out_s);
2097 mbstate_t mbstate;
2098 memset(&mbstate, 0, sizeof(mbstate));
2099 uint word_cols = 0;
2100 uint sl_maxlen = PAD_COLS - 1;
2101 if (view->f_eod)
2102 return 0;
2103 if (view->wrap)
2104 sl_maxlen = view->cols;
2105 if (view->f_ln)
2106 sl_maxlen -= view->ln_win_cols;
2107 memset(view->stripped_line_out, 0, sizeof(view->stripped_line_out));
2108 while (in_str[i] != '\0') { // line
2109 while (1) { // ANSI SGR, Character, and Word
2110 if (in_str[i] == '\033') { // ANSI SGR
2111 if (in_str[i + 1] == '[') {
2112 len = strcspn(&in_str[i], "mK ") + 1;
2113 memcpy(ansi_tok, &in_str[i], len + 1);
2114 ansi_tok[len] = '\0';
2115 if (ansi_tok[0] == '\0') {
2116 if (i + 2 < MAXLEN)
2117 i += 2;
2118 continue;
2119 }
2120 if (len == 0 || in_str[i + len - 1] == ' ') {
2121 i += 2;
2122 continue;
2123 } else if (in_str[i + len - 1] == 'K') {
2124 i += len;
2125 continue;
2126 }
2127 parse_ansi_str(ansi_tok, &attr, &cpx);
2128 i += len;
2129 } else {
2130 i++;
2131 continue;
2132 }
2133 } else { // Character and Word
2134 if (in_str[i] == ' ' || in_str[i] == '-') {
2135 if (view->wrap && (sl_cols + word_cols) > (sl_maxlen - 1))
2136 break;
2137 (in_str[i] == '-') ? (wstr[0] = L'-') : (wstr[0] = L' ');
2138 wstr[1] = L'\0';
2139 ui_setcchar(&cc, wstr, attr, cpx, nullptr);
2140 view->stripped_line_out[x++] = in_str[i];
2141 cmplx_buf[j++] = cc;
2142 if (view->wrap) {
2143 sl_cols += word_cols + 1;
2144 word_cols = 0;
2145 sl_cells += word_cells + 1;
2146 word_cells = 0;
2147 }
2148 i++;
2149 continue;
2150 }
2151 if (in_str[i] == '\0') {
2152 if (view->wrap) {
2153 if (sl_cols + word_cols + 1 > sl_maxlen - 1)
2154 break;
2155 sl_cols += word_cols;
2156 word_cols = 0;
2157 sl_cells += word_cells;
2158 word_cells = 0;
2159 }
2160 break;
2161 }
2162 if (in_str[i] == '\t') {
2163 tab_spaces = view->tab_stop - ((sl_cols + word_cols) % view->tab_stop);
2164 if (view->wrap && sl_cols + word_cols + tab_spaces > sl_maxlen - 1)
2165 break;
2166 wstr[0] = L' ';
2167 wstr[1] = L'\0';
2168 ui_setcchar(&cc, wstr, attr, cpx, nullptr);
2169 for (uint z = 0; z < tab_spaces; z++) {
2170 view->stripped_line_out[x++] = ' ';
2171 cmplx_buf[j++] = cc;
2172 }
2173 if (view->wrap) {
2174 sl_cols += word_cols + tab_spaces;
2175 word_cols = 0;
2176 sl_cells += word_cells + tab_spaces;
2177 word_cells = 0;
2178 }
2179 i++;
2180 continue;
2181 }
2182 wstr[1] = L'\0';
2183 len = mbrtowc(wstr, &in_str[i], MB_CUR_MAX, &mbstate);
2184 if (len <= 0) {
2185 wstr[0] = L'?';
2186 wstr[1] = L'\0';
2187 len = 1;
2188 }
2189 char_width = wcwidth(wstr[0]);
2190 view->stripped_line_out[x++] = in_str[i];
2191 if (char_width > 1)
2192 for (uint n = 1; n < char_width; n++)
2193 view->stripped_line_out[x++] = ' ';
2194 ui_setcchar(&cc, wstr, attr, cpx, nullptr);
2195 cmplx_buf[j++] = cc;
2196 i += len;
2197 if (view->wrap) {
2198 word_cols += char_width;
2199 word_cells++;
2200 }
2201 continue;
2202 } // END Character and Word
2203 } // END WHILE - ANSI SGR, Character, and Word
2204 if (view->wrap) { // handle line wrapping
2205 if (word_cols > 0) { // break line, add last word to next line
2206 if (sl_cols <= sl_maxlen) {
2207 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2208 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2209 view->cur.sl_cols[view->cur.sl_idx] = sl_cols;
2210 view->cur.sl_cells[view->cur.sl_idx] = sl_cells;
2211 view->cur.sl_idx++;
2212 sl_s = &sl_s[sl_cols];
2213 sl_cc = &sl_cc[sl_cells];
2214 sl_cols > view->maxcol ? view->maxcol = sl_cols : 0;
2215 sl_cols = word_cols;
2216 sl_cells = word_cells;
2217 word_cols = 0;
2218 word_cells = 0;
2219 }
2220 }
2221 while (sl_cols > sl_maxlen - 1) { // split long lines
2222 uint safe_cells = 0;
2223 uint safe_cols = 0;
2224 while (safe_cols < sl_maxlen && safe_cells < sl_cells) {
2225 wchar_t wstr_chk[CCHARW_MAX];
2226 attr_t attr_chk;
2227 ushort cpx_chk;
2228 ui_getcchar(&sl_cc[safe_cells], wstr_chk, &attr_chk, &cpx_chk, nullptr);
2229 uint cw = wcwidth(wstr_chk[0]);
2230 if (safe_cols + cw > sl_maxlen)
2231 break;
2232 safe_cols += cw;
2233 safe_cells++;
2234 }
2235 if (safe_cells == 0) {
2236 safe_cells = 1;
2237 safe_cols = sl_maxlen;
2238 }
2239 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2240 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2241 view->cur.sl_cols[view->cur.sl_idx] = safe_cols;
2242 view->cur.sl_cells[view->cur.sl_idx] = safe_cells;
2243 view->cur.sl_idx++;
2244 sl_s = &sl_s[safe_cells];
2245 sl_cc = &sl_cc[safe_cells];
2246 sl_cols > view->maxcol ? view->maxcol = sl_cols : 0;
2247 sl_cols -= safe_cols;
2248 sl_cells -= safe_cells;
2249 word_cols = 0;
2250 word_cells = 0;
2251 } // END WHILE - split long lines
2252 } // END IF - handle line wrapping
2253 j > view->maxcol ? view->maxcol = j : 0;
2254 } // END WHILE - line
2255 if (view->wrap) { // finish and commit wrap state
2256 if (view->cur.sl_idx > 0) {
2257 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2258 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2259 view->cur.sl_cols[view->cur.sl_idx] = sl_cols;
2260 view->cur.sl_cells[view->cur.sl_idx] = sl_cells;
2261 view->cur.sl_idx++;
2262 view->cur.sl_cc[view->cur.sl_idx] = nullptr;
2263 view->cur.sl_s[view->cur.sl_idx] = nullptr;
2264 view->cur.sl_cnt = view->cur.sl_idx;
2265 view->cur.sl_idx = 0;
2266 }
2267 view->cur.sl_ln_no = view->ln_no;
2268 }
2269#ifdef DEBUG_WRAP
2270 // log_split_lines(view);
2272 // log_stripped_line_out(view);
2273#endif
2274 //-------------------------------------------------------------------------
2275 wstr[0] = '\0';
2276 wstr[1] = '\0';
2277 ui_setcchar(&cc, wstr, WA_NORMAL, cpx, nullptr);
2278 cmplx_buf[j] = cc;
2279 view->stripped_line_out[x] = '\0';
2280 return j;
2281}
size_t rtrim(char *)
Trims trailing spaces from string s in place.
Definition futil.c:331
uint16_t attr_t
Definition ui_backend.h:256
int ui_getcchar(const UiCell *uc, wchar_t *wstr, attr_t *attrs, ushort *pair, void *opts)
int ui_setcchar(UiCell *wch, const wchar_t *wc, const attr_t attrs, short pair, const void *opts)
#define CCHARW_MAX
Definition ui_backend.h:248
#define WA_NORMAL
char in_str[BUFSIZ+1]
Definition iloan.c:20
#define MAXLEN
Definition curskeys.c:15
ushort cp_nt
Definition dwin.c:151
void log_cc_buf(View *)
Log Complex Character Buffer.
void parse_ansi_str(char *, attr_t *, ushort *)
Parse ANSI SGR Escape Sequence.

References View::cmplx_buf, View::cols, cp_nt, View::cur, View::f_eod, View::f_ln, View::line_in_s, View::line_out_s, View::ln_no, View::ln_win_cols, View::maxcol, parse_ansi_str(), rtrim(), SplitLine::sl_cc, SplitLine::sl_cells, SplitLine::sl_cnt, SplitLine::sl_cols, SplitLine::sl_idx, SplitLine::sl_ln_no, SplitLine::sl_s, View::stripped_line_out, View::tab_stop, ui_getcchar(), ui_setcchar(), and View::wrap.

Referenced by prev_page(), scroll_down(), scroll_up(), search(), and view_display_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_cc_buf()

void log_cc_buf ( View * view)

Log Complex Character Buffer.

Parameters
viewpointer to View structure containing complex character buffer (view->cmplx_buf)

This function logs the contents of the complex character buffer (view->cmplx_buf) for debugging purposes. It iterates through the split lines (if any) and logs each line to the cmenu log, converting wide characters to their corresponding single-byte representation for easier viewing.

Definition at line 2312 of file view_engine.c.

2312 {
2313 char tmp_str[PAD_COLS];
2314
2315 write_cmenu_log("");
2316 write_cmenu_log("cc_buf");
2317 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2318 memset(tmp_str, 0, sizeof(tmp_str));
2319 for (uint c = 0; c < view->cur.sl_cells[k]; c++) {
2320 wchar_t wstr[CCHARW_MAX];
2321 attr_t attr;
2322 ushort cpx;
2323 ui_getcchar(&view->cur.sl_cc[k][c], wstr, &attr, &cpx, nullptr);
2324 if (wstr[0] == L'\0')
2325 tmp_str[c] = ' ';
2326 else
2327 tmp_str[c] = (char)wstr[0];
2328 }
2329 write_cmenu_log(tmp_str);
2330 }
2331}
void write_cmenu_log(char *)
Write message to C-Menu log file without timestamp.
Definition futil.c:1684

References View::cur, SplitLine::sl_cc, SplitLine::sl_cells, SplitLine::sl_cnt, ui_getcchar(), and write_cmenu_log().

Here is the call graph for this function:

◆ log_split_lines()

void log_split_lines ( View * view)

Log Split Lines.

Parameters
viewpointer to View structure containing split line information

This function logs the contents of the split lines stored in the view structure for debugging purposes. It iterates through the split lines and logs each line to the cmenu log, converting wide characters to their corresponding single-byte representation for easier viewing.

Definition at line 2353 of file view_engine.c.

2353 {
2354 char tmp_str[MAXLEN];
2355
2356 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2357 if (view->cur.sl_cols[k] > 0) {
2358 memset(tmp_str, 0, sizeof(tmp_str));
2359 char *s = view->cur.sl_s[k];
2360 char *d = tmp_str;
2361 char *e = view->cur.sl_s[k] + view->cur.sl_cols[k];
2362 while (s < e)
2363 *d++ = *s++;
2364 *d = '\0';
2365 write_cmenu_log(tmp_str);
2366 }
2367 }
2368}

References View::cur, SplitLine::sl_cnt, SplitLine::sl_cols, SplitLine::sl_s, and write_cmenu_log().

Here is the call graph for this function:

◆ log_stripped_line_out()

void log_stripped_line_out ( View * view)

Log Stripped Line Output.

Parameters
viewpointer to View structure containing stripped line output buffer

This function logs the contents of the stripped line output buffer (view->stripped_line_out) for debugging purposes. It iterates through the split lines (if any) and logs each line to the cmenu log.

Definition at line 2290 of file view_engine.c.

2290 {
2291 char tmp_str[PAD_COLS];
2292
2293 write_cmenu_log("");
2294 write_cmenu_log("stripped_line_out");
2295 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2296 memset(tmp_str, 0, sizeof(tmp_str));
2297 for (uint c = 0; c < view->cur.sl_cols[k]; c++)
2298 tmp_str[c] = view->cur.sl_s[k][c];
2299 write_cmenu_log(tmp_str);
2300 }
2301}

References View::cur, SplitLine::sl_cnt, SplitLine::sl_cols, SplitLine::sl_s, and write_cmenu_log().

Here is the call graph for this function:

◆ log_strnz()

void log_strnz ( char * str,
uint len )

Log String with Specified Length.

Parameters
strpointer to the string to log
lenlength of the string to log

This function logs a specified number of characters from a given string to the cmenu log. It copies the specified length of the string into a temporary buffer and then writes it to the log.

Definition at line 2340 of file view_engine.c.

2340 {
2341 char tmp_str[MAXLEN];
2342 strnz__cpy(tmp_str, str, len);
2343 write_cmenu_log(tmp_str);
2344}

References strnz__cpy(), and write_cmenu_log().

Here is the call graph for this function:

◆ pad_refresh()

int pad_refresh ( View * view)

Refresh Pad and Line Number Window.

Parameters
viewdata structure
Returns
OK on success, ERR on failure

Definition at line 2034 of file view_engine.c.

2034 {
2035#ifdef UAL_UI
2036 int rc = 0;
2037 // touchwin(view->sfc->mwin[WIN2]);
2038 // rc = pnoutrefresh(view->sfc->mwin[WIN2], view->pminrow, view->pmincol,
2039 // view->sminrow,
2040 // view->smincol, view->smaxrow, view->smaxcol);
2041 rc = prefresh(view->sfc->mwin[PAD],
2042 view->pminrow,
2043 view->pmincol,
2044 view->sminrow,
2045 view->smincol,
2046 view->smaxrow,
2047 view->smaxcol);
2048 if (rc == ERR) {
2049 ssnprintf(em0, MAXLEN - 1, "%s:%d prefresh(view->sfc->mwin[WIN2], pminrow=%d, pmincol=%d, smaxrow=%d, smaxcol=%d) returned %d\n",
2050 __FILE__, __LINE__ - 1, view->pminrow, view->pmincol, view->smaxrow, view->smaxcol, rc);
2051 Perror(em0);
2052 }
2053#else
2054 (void)view;
2055#endif
2056 ui_render();
2057 return 0;
2058}
void ui_render()
Definition ui_ncurses.c:800
#define ERR
Definition ui_backend.h:249
char em0[MAXLEN]
Definition dwin.c:142
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841

References ui_render().

Referenced by get_cmd_arg(), get_cmd_char(), and new_view_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_ansi_str()

void parse_ansi_str ( char * ansi_str,
attr_t * attr,
ushort * cpx )

Parse ANSI SGR Escape Sequence.

Parameters
ansi_stris the ANSI escape sequence string to parse
attris a pointer to an attr_t variable where the parsed attributes will be stored
cpxis a pointer to an int variable where the parsed color pair index will be stored

This function parses ANSI escape sequences, which it converts to color pairs and attributes used to construct complex character cells or extended grapheme clusters.

Note
ANSI Select Graphics Rendition (SGR), ECMA-48, (ISO/IEC 6429)
Extends Color Pair and Color arrays as necessary
SGR specification types:

 RGB:

     foreground \033[38;2;r;g;bm
     background \033[48;2;r;g;bm

     Where r, g, b are the red, green, and blue color components (0-255)

 XTERM 256-color:

     foreground \033[38;5;xm
     background \033[48;5;xm

     Where x is the 256-color index (0-255)
     uses xterm256_idx_to_rgb() to convert the 256-color index to RGB

 8-color:

     foreground \033[3cm
     background \033[4cm

     Where c is the color code (0 for black, 1 for red, 2 for green, 3
for yellow, 4 for blue, 5 for magenta, 6 for cyan, 7 for white).

 Attributes:

     \033[am

     Where a is the attribute code (1 for bold, 2 for dim, 3 for italic,
4 for underline, 5 for blink, 7 for reverse, 8 for invis). The function
also supports resetting attributes and colors to default using \033[0m.

 see also: xterm256_idx_to_rgb(), ui_add_color_rgb(), extended_pair_content(),
ui_add_pair()

Definition at line 2422 of file view_engine.c.

2422 {
2423 char *tok;
2424 char t0, t1;
2425 char tstr[3];
2426 uint len, x_idx;
2427 uint fg, bg;
2428 uint fg_clr, bg_clr;
2429 char *ansi_p = ansi_str + 2;
2430 ui_pair_content(*cpx, &fg_clr, &bg_clr);
2431 fg = fg_clr;
2432 bg = bg_clr;
2433 RGB rgb;
2434 tok = strtok((char *)ansi_p, ";m");
2435 bool a_toi_error = false;
2436 while (1) {
2437 if (tok == nullptr || *tok == '\0')
2438 break;
2439 len = strlen(tok);
2440 if (len == 2) {
2441 t0 = tok[0];
2442 t1 = tok[1];
2443 if (t0 == '3' || t0 == '4') {
2444 if (t1 == '8') {
2445 tok = strtok(nullptr, ";m");
2446 if (tok != nullptr) {
2447 if (*tok == '5') {
2448 tok = strtok(nullptr, ";m");
2449 if (tok != nullptr) {
2450 x_idx = a_toi(tok, &a_toi_error);
2451 rgb = xterm256_idx_to_rgb(x_idx);
2452 }
2453 } else if (*tok == '2') {
2454 tok = strtok(nullptr, ";m");
2455 rgb.r = a_toi(tok, &a_toi_error);
2456 tok = strtok(nullptr, ";m");
2457 rgb.g = a_toi(tok, &a_toi_error);
2458 tok = strtok(nullptr, ";m");
2459 rgb.b = a_toi(tok, &a_toi_error);
2460 }
2461 }
2462 if (t0 == '3')
2463 fg_clr = ui_add_color_rgb(&rgb);
2464 else if (t0 == '4')
2465 bg_clr = ui_add_color_rgb(&rgb);
2466 } else if (t1 == '9') {
2467 if (t0 == '3')
2468 fg_clr = CLR_NT_FG;
2469 else if (t0 == '4')
2470 bg_clr = CLR_NT_BG;
2471 } else if (t1 >= '0' && t1 <= '7') {
2472 if (t0 == '3') {
2473 tstr[0] = t1;
2474 tstr[1] = '\0';
2475 x_idx = a_toi(tstr, &a_toi_error);
2476 rgb = xterm256_idx_to_rgb(x_idx);
2477 fg_clr = ui_add_color_rgb(&rgb);
2478 } else if (t0 == '4') {
2479 tstr[0] = t1;
2480 tstr[1] = '\0';
2481 x_idx = a_toi(tstr, &a_toi_error);
2482 rgb = xterm256_idx_to_rgb(x_idx);
2483 bg_clr = ui_add_color_rgb(&rgb);
2484 }
2485 }
2486 } else if (t0 == '0') {
2487 *tok = t1;
2488 len = 1;
2489 }
2490 }
2491 if (len == 1) {
2492 if (*tok == '0') {
2493 *attr = WA_NORMAL;
2494 fg_clr = CLR_NT_FG;
2495 bg_clr = CLR_NT_BG;
2496 } else {
2497 switch (a_toi(tok, &a_toi_error)) {
2498 case 1:
2499 *attr |= WA_BOLD;
2500 break;
2501 case 2:
2502 *attr |= WA_DIM;
2503 break;
2504 case 3:
2505 *attr |= WA_ITALIC;
2506 break;
2507 case 4:
2508 *attr |= WA_UNDERLINE;
2509 break;
2510 case 5:
2511 *attr |= WA_BLINK;
2512 break;
2513 case 7:
2514 *attr |= WA_REVERSE;
2515 break;
2516 case 8:
2517 *attr |= WA_INVIS;
2518 break;
2519 default:
2520 break;
2521 }
2522 }
2523 } else if (len == 0) {
2524 *attr = WA_NORMAL;
2525 fg_clr = CLR_NT_FG;
2526 bg_clr = CLR_NT_BG;
2527 }
2528 tok = strtok(nullptr, ";m");
2529 }
2530 if (!a_toi_error && (fg_clr != fg || bg_clr != bg))
2531 *cpx = ui_add_pair(fg_clr, bg_clr);
2532 return;
2533}
@ CLR_NT_FG
Definition cm.h:198
@ CLR_NT_BG
Definition cm.h:199
int ui_add_color_rgb(RGB *rgb)
Definition ui_ncurses.c:138
int ui_pair_content(uint pair, uint *fg, uint *bg)
Definition ui_ncurses.c:194
uint ui_add_pair(uint fg, uint bg)
Definition ui_ncurses.c:105
#define WA_BLINK
#define WA_ITALIC
#define WA_DIM
#define WA_INVIS
#define WA_BOLD
#define WA_REVERSE
#define WA_UNDERLINE
RGB xterm256_idx_to_rgb(uint idx)
Convert XTerm 256 color index to RGB.
Definition dwin.c:274
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:762

References a_toi(), CLR_NT_BG, CLR_NT_FG, ui_add_color_rgb(), ui_add_pair(), ui_pair_content(), and xterm256_idx_to_rgb().

Referenced by fmt_line().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_display_help()

void view_display_help ( Init * init)

Display View Help File.

Parameters
initis the current initialization data structure.

The current View context is set aside by assigning the view structure to "view_save" while the help file is displayed using a new, separate view structure. The help file is specified by the VIEW_HELP_FILE macro can be set to a default help file path or overridden by the user through an environment variable. After the help file is closed, the original view is restored and the page is redisplayed. It may be necessary to reassign view after calling this function because the init->view pointer is temporarily set to nullptr during the help file display, and the original view is restored afterward. The default screen size for help can be set in the code below. If set to 0, popup_view will determine reasonable maximal size based on the terminal dimensions. The help file may contain Unicode characters and ANSI escape sequences for formatting, which will be properly handled and displayed by popup_view.

Definition at line 2576 of file view_engine.c.

2576 {
2577 char tmp_str[MAXLEN];
2578 uint eargc = 0;
2579 char *eargv[MAXARGS];
2580 View *view = init->view;
2581 if (view->f_help_spec || view->help_spec[0] != '\0')
2582 strnz__cpy(tmp_str, view->help_spec, MAXLEN - 1);
2583 else {
2584 strnz__cpy(tmp_str, init->mapp_help, MAXLEN - 1);
2585 strnz__cat(tmp_str, "/", MAXLEN - 1);
2586 strnz__cat(tmp_str, VIEW_HELP_FILE, MAXLEN - 1);
2587 }
2588 eargv[eargc++] = strdup("view");
2589 eargv[eargc++] = strdup("-N");
2590 eargv[eargc++] = strdup(tmp_str);
2591 eargv[eargc] = nullptr;
2592 init->lines = 48;
2593 init->cols = 72;
2594 init->begy = 0;
2595 init->begx = 0;
2596 strnz__cpy(init->title, "View Help", MAXLEN - 1);
2597 popup_view(init, eargc, eargv, init->lines, init->cols, init->begy,
2598 init->begx);
2600 init->view->f_redisplay_page = true;
2601}
int popup_view(Init *, int, char **, uint, uint, uint, uint)
instantiate a view popup window
Definition popups.c:145
#define VIEW_HELP_FILE
Definition common.h:35
#define MAXARGS
Definition cm.h:50
char * eargv[MAXARGS]
Definition futil.c:51
int eargc
Definition futil.c:50
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:566
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:487
char title[MAXLEN]
Definition common.h:129
char mapp_help[MAXLEN]
Definition common.h:149
int begx
Definition common.h:118
int cols
Definition common.h:116
int begy
Definition common.h:117
View * view
Definition common.h:189
int lines
Definition common.h:115
Definition view.h:61
bool f_redisplay_page
Definition view.h:116

References Init::begx, Init::begy, Init::cols, destroy_argv(), View::f_help_spec, View::f_redisplay_page, View::help_spec, Init::lines, Init::mapp_help, popup_view(), strnz__cat(), strnz__cpy(), Init::title, and Init::view.

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_display_page()

void view_display_page ( View * view)

Display Current Page.

Parameters
viewdata structure

Definition at line 1352 of file view_engine.c.

1352 {
1353 view->cury = 0;
1354 view->page_top_sl = false;
1355 view->page_bot_sl = false;
1356 UiSurface *sfc = view->sfc;
1357 ui_cursor_move(sfc, PAD, 0, 0);
1358 if (view->f_ln)
1359 ui_cursor_move(sfc, LNNO, 0, 0);
1360 view->ln_no = view->page_top_ln_no;
1361 view->page_top_ln_no = 0;
1362 view->page_bot_ln_no = 0;
1363 while (view->cury < view->scroll_lines) {
1364 get_line(view, view->ln_no);
1365 if (view->f_eod)
1366 break;
1367 fmt_line(view);
1368 if (view->wrap && view->cury == 0)
1369 view->cur.sl_idx = view->page_top_sl_idx;
1371 ui_render();
1372 view->ln_no++;
1373 }
1374 if (view->f_eod)
1376 view->ln_no--;
1377 view->page_bot_end_pos = view->file_pos - 1;
1378 view->page_bot_pos = view->file_pos;
1379 view->page_bot_ln_no = view->ln_no;
1380}
void get_line(View *, off_t)
void display_line(View *)
Display Line on Padparam View *view data structure.
void display_line_eod(View *)
Display End of Data.
int fmt_line(View *)
Format Line for Display.

References View::cur, View::cury, display_line(), display_line_eod(), View::f_eod, View::f_ln, View::file_pos, fmt_line(), get_line(), View::ln_no, LNNO, PAD, View::page_bot_end_pos, View::page_bot_ln_no, View::page_bot_pos, View::page_bot_sl, View::page_top_ln_no, View::page_top_sl, View::page_top_sl_idx, View::scroll_lines, View::sfc, SplitLine::sl_idx, ui_cursor_move(), ui_render(), and View::wrap.

Referenced by next_page(), and view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function: