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 *attrs, 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. __display_line

Definition at line 1412 of file view_engine.c.

1412 {
1413 char ln_s[16];
1414
1415 UiSurface *sfc = view->sfc;
1416 if (view->wrap && view->cur.sl_cnt > 0) {
1417 if (view->cur.sl_idx < view->cur.sl_cnt) {
1419 return;
1420 }
1421 }
1422 if (view->cury > view->scroll_lines - 1)
1423 view->cury = view->scroll_lines - 1;
1424 if (view->f_ln) {
1425 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1426 ui_cursor_move(sfc, LNNO, view->cury, 0);
1427 ui_wclrtoeol(sfc, LNNO);
1428 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1429 }
1430 ui_render();
1431 ui_cursor_move(sfc, PAD, view->cury, 0);
1432 ui_wclrtoeol(sfc, PAD);
1433#ifdef UAL_UI
1434 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, view->cmplx_buf);
1435#else
1436 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, (struct nccell *)view->cmplx_buf);
1437#endif
1438 if (view->cury == 0)
1439 view->page_top_ln_no = view->ln_no;
1440 if (view->cury == view->scroll_lines - 1)
1441 view->page_bot_ln_no = view->ln_no;
1442 view->cury++;
1443}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:884
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:666
int ui_wclrtoeol(UiSurface *s, ss_t w)
Clear to the end of the line in a surface window.
int ui_mvwadd_wchstr(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf)
Draw a complex character string at a specific position in a surface window.
int ui_mvwaddstr(UiSurface *s, ss_t w, uint y, uint x, const char *text)
Draw a text string at a specific position in a surface window.
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:390
void display_split_line(View *)
Display Split Line on Pad.

References View::cmplx_buf, View::cur, View::cury, display_split_line(), View::f_ln, View::ln_no, 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_render(), ui_wclrtoeol(), and View::wrap.

Referenced by scroll_next(), scroll_prev(), 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 1503 of file view_engine.c.

1503 {
1504 UiSurface *sfc = view->sfc;
1505 if (view->f_ln) {
1506 ui_cursor_move(sfc, LNNO, view->cury, 0);
1507 ui_wclrtobot(sfc, LNNO);
1508 }
1509 ui_cursor_move(sfc, PAD, view->cury, 0);
1510 ui_wclrtobot(sfc, PAD);
1511 view->page_bot_ln_no = view->ln_no;
1512 view->ln_no_max = view->ln_no;
1513}
int ui_wclrtobot(UiSurface *s, ss_t w)
Set the style of a surface window.

References View::cury, View::f_ln, View::ln_no, View::ln_no_max, 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 2577 of file view_engine.c.

2577 {
2578 char message_str[PAD_COLS + 1];
2579 uint l;
2580 UiSurface *sfc = view->sfc;
2581 l = strnz__cpy(message_str, s, PAD_COLS);
2582 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
2583 if (l != 0) {
2584 ui_wclrtoeol(sfc, CMDLN);
2585 ui_bkgdset(sfc, CMDLN, &cell_nt_rev);
2586 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 0, " ");
2587 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 1, message_str);
2588 ui_waddstr(sfc, CMDLN, " ");
2589 ui_bkgdset(sfc, CMDLN, &cell_nt);
2590 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
2591 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
2592 }
2593 return (view->curx);
2594}
void ui_getyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the current cursor position within a window of a UI surface.
Definition ui_ncurses.c:675
UiCell cell_nt
Definition ui_common.c:106
int ui_bkgdset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:941
UiCell cell_nt_rev
Definition ui_common.c:107
#define PAD_COLS
Definition view.h:39
int ui_waddstr(UiSurface *s, ss_t w, const char *text)
Draw a text string in a surface window.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition whence.c:291

References cell_nt, cell_nt_rev, View::cmd_line, 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 1454 of file view_engine.c.

1454 {
1455 char ln_s[16];
1456 UiSurface *sfc = view->sfc;
1457 if (view->cury > view->scroll_lines - 1)
1458 view->cury = view->scroll_lines - 1;
1459
1460 for (uint i = view->cur.sl_idx; i < view->cur.sl_cnt; i++) {
1461 if (i == 0) {
1462 if (view->f_ln) {
1463 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1464 ui_cursor_move(sfc, LNNO, view->cury, 0);
1465 ui_wclrtoeol(sfc, LNNO);
1466 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1467 }
1468 } else {
1469 if (view->f_ln) {
1470 ui_cursor_move(sfc, LNNO, view->cury, 0);
1471 ui_wclrtoeol(sfc, LNNO);
1472 }
1473 }
1474 ui_cursor_move(sfc, PAD, view->cury, 0);
1475 ui_wclrtoeol(sfc, PAD);
1476 ui_wadd_wchnstr(sfc, PAD, view->cur.sl_cc[i], view->cur.sl_cells[i]);
1477 if (view->cury == 0) {
1478 view->page_top_ln_no = view->ln_no;
1479 view->page_top_sl = true;
1480 view->page_top_sl_idx = i;
1481 view->page_top_sl_cnt = view->cur.sl_cnt;
1482 }
1483 if (view->cury == view->scroll_lines - 1) {
1484 view->page_bot_ln_no = view->ln_no;
1485 view->page_bot_sl = true;
1486 view->page_bot_sl_idx = i;
1487 view->page_bot_sl_cnt = view->cur.sl_cnt;
1488 view->page_bot_ln_no = view->ln_no;
1489 }
1490 view->cury++;
1491 if (view->cury == view->scroll_lines)
1492 break;
1493 }
1494}
int ui_wadd_wchnstr(UiSurface *s, ss_t w, const UiCell *cmplx_buf, uint n)
Draw a complex character string in a surface window, with a maximum length.

References View::cur, View::cury, View::f_ln, View::ln_no, 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. __fmt_line

Definition at line 2109 of file view_engine.c.

2109 {
2110 char ansi_tok[MAXLEN];
2111 uint i = 0, j = 0, x = 0;
2112 uint len = 0;
2113 uint tab_spaces = 0;
2114 uint char_width;
2115 attr_t attrs = WA_NORMAL;
2116 ushort cpx = cp_nt;
2117 UiCell cc = {};
2118 wchar_t wstr[2] = {L'\0', L'\0'};
2119 char *in_str = view->line_in_s;
2120 uint sl_cols = 0;
2121 uint sl_cells = 0;
2122 uint word_cells = 0;
2123 UiCell *cmplx_buf = view->cmplx_buf;
2124 view->cur.sl_idx = 0;
2125 view->cur.sl_cnt = 0;
2126 view->cur.sl_cols[0] = 0;
2127 view->cur.sl_cells[0] = 0;
2128 view->cur.sl_s[0] = nullptr;
2129 view->cur.sl_cc[0] = nullptr;
2130 char *sl_s = view->stripped_line_out;
2131 UiCell *sl_cc = view->cmplx_buf;
2132 rtrim(view->line_out_s);
2133 mbstate_t mbstate;
2134 memset(&mbstate, 0, sizeof(mbstate));
2135 uint word_cols = 0;
2136 uint sl_maxlen = PAD_COLS - 1;
2137 if (view->f_eod) {
2138 view->ln_no_max = view->ln_no;
2139 return 0;
2140 }
2141 if (view->wrap)
2142 sl_maxlen = view->cols;
2143 if (view->f_ln)
2144 sl_maxlen -= view->ln_win_cols;
2145 memset(view->stripped_line_out, 0, sizeof(view->stripped_line_out));
2146 while (in_str[i] != '\0') { // line
2147 while (1) { // ANSI SGR, Character, and Word
2148 if (in_str[i] == '\033') { // ANSI SGR
2149 if (in_str[i + 1] == '[') {
2150 len = strcspn(&in_str[i], "mK ") + 1;
2151 memcpy(ansi_tok, &in_str[i], len + 1);
2152 ansi_tok[len] = '\0';
2153 if (ansi_tok[0] == '\0') {
2154 if (i + 2 < MAXLEN)
2155 i += 2;
2156 continue;
2157 }
2158 if (len == 0 || in_str[i + len - 1] == ' ') {
2159 i += 2;
2160 continue;
2161 } else if (in_str[i + len - 1] == 'K') {
2162 i += len;
2163 continue;
2164 }
2165 parse_ansi_str(ansi_tok, &attrs, &cpx);
2166 i += len;
2167 } else {
2168 i++;
2169 continue;
2170 }
2171 } else { // Character and Word
2172 if (in_str[i] == ' ' || in_str[i] == '-') {
2173 if (view->wrap && (sl_cols + word_cols) > (sl_maxlen - 1))
2174 break;
2175 (in_str[i] == '-') ? (wstr[0] = L'-') : (wstr[0] = L' ');
2176 wstr[1] = L'\0';
2177 ui_set_cell(view->sfc, PAD, &cc, wstr, attrs, cpx, nullptr);
2178 view->stripped_line_out[x++] = in_str[i];
2179 cmplx_buf[j++] = cc;
2180 if (view->wrap) {
2181 sl_cols += word_cols + 1;
2182 word_cols = 0;
2183 sl_cells += word_cells + 1;
2184 word_cells = 0;
2185 }
2186 i++;
2187 continue;
2188 }
2189 if (in_str[i] == '\0') {
2190 if (view->wrap) {
2191 if (sl_cols + word_cols + 1 > sl_maxlen - 1)
2192 break;
2193 sl_cols += word_cols;
2194 word_cols = 0;
2195 sl_cells += word_cells;
2196 word_cells = 0;
2197 }
2198 break;
2199 }
2200 if (in_str[i] == '\t') {
2201 tab_spaces = view->tab_stop - ((sl_cols + word_cols) % view->tab_stop);
2202 if (view->wrap && sl_cols + word_cols + tab_spaces > sl_maxlen - 1)
2203 break;
2204 wstr[0] = L' ';
2205 wstr[1] = L'\0';
2206 ui_set_cell(view->sfc, PAD, &cc, wstr, attrs, cpx, nullptr);
2207 for (uint z = 0; z < tab_spaces; z++) {
2208 view->stripped_line_out[x++] = ' ';
2209 cmplx_buf[j++] = cc;
2210 }
2211 if (view->wrap) {
2212 sl_cols += word_cols + tab_spaces;
2213 word_cols = 0;
2214 sl_cells += word_cells + tab_spaces;
2215 word_cells = 0;
2216 }
2217 i++;
2218 continue;
2219 }
2220 wstr[1] = L'\0';
2221 len = mbrtowc(wstr, &in_str[i], MB_CUR_MAX, &mbstate);
2222 if (len <= 0) {
2223 wstr[0] = L'?';
2224 wstr[1] = L'\0';
2225 len = 1;
2226 }
2227 char_width = wcwidth(wstr[0]);
2228 if (x > PAD_COLS - 1)
2229 return -1;
2230 view->stripped_line_out[x++] = in_str[i];
2231 if (char_width > 1)
2232 for (uint n = 1; n < char_width; n++)
2233 view->stripped_line_out[x++] = ' ';
2234 ui_set_cell(view->sfc, PAD, &cc, wstr, attrs, cpx, nullptr);
2235 if (j > PAD_COLS - 1)
2236 return -1;
2237 cmplx_buf[j++] = cc;
2238 i += len;
2239 if (view->wrap) {
2240 word_cols += char_width;
2241 word_cells++;
2242 }
2243 continue;
2244 } // END Character and Word
2245 } // END WHILE - ANSI SGR, Character, and Word
2246 if (view->wrap) { // handle line wrapping
2247 if (word_cols > 0) { // break line, add last word to next line
2248 if (sl_cols <= sl_maxlen) {
2249 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2250 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2251 view->cur.sl_cols[view->cur.sl_idx] = sl_cols;
2252 view->cur.sl_cells[view->cur.sl_idx] = sl_cells;
2253 view->cur.sl_idx++;
2254 sl_s = &sl_s[sl_cols];
2255 sl_cc = &sl_cc[sl_cells];
2256 sl_cols > view->maxcol ? view->maxcol = sl_cols : 0;
2257 sl_cols = word_cols;
2258 sl_cells = word_cells;
2259 word_cols = 0;
2260 word_cells = 0;
2261 }
2262 }
2263 while (sl_cols > sl_maxlen - 1) { // split long lines
2264 uint safe_cells = 0;
2265 uint safe_cols = 0;
2266 while (safe_cols < sl_maxlen && safe_cells < sl_cells) {
2267 wchar_t wstr_chk[CCHARW_MAX];
2268 attr_t attr_chk;
2269 short cpx_chk;
2270 ui_get_cell(view->sfc, PAD, &sl_cc[safe_cells], wstr_chk, &attr_chk, &cpx_chk, nullptr);
2271 uint cw = wcwidth(wstr_chk[0]);
2272 if (safe_cols + cw > sl_maxlen)
2273 break;
2274 safe_cols += cw;
2275 safe_cells++;
2276 }
2277 if (safe_cells == 0) {
2278 safe_cells = 1;
2279 safe_cols = sl_maxlen;
2280 }
2281 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2282 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2283 view->cur.sl_cols[view->cur.sl_idx] = safe_cols;
2284 view->cur.sl_cells[view->cur.sl_idx] = safe_cells;
2285 view->cur.sl_idx++;
2286 sl_s = &sl_s[safe_cells];
2287 sl_cc = &sl_cc[safe_cells];
2288 sl_cols > view->maxcol ? view->maxcol = sl_cols : 0;
2289 sl_cols -= safe_cols;
2290 sl_cells -= safe_cells;
2291 word_cols = 0;
2292 word_cells = 0;
2293 } // END WHILE - split long lines
2294 } // END IF - handle line wrapping
2295 j > view->maxcol ? view->maxcol = j : 0;
2296 } // END WHILE - line
2297 if (view->wrap) { // finish and commit wrap state
2298 if (view->cur.sl_idx > 0) {
2299 view->cur.sl_s[view->cur.sl_idx] = sl_s;
2300 view->cur.sl_cc[view->cur.sl_idx] = sl_cc;
2301 view->cur.sl_cols[view->cur.sl_idx] = sl_cols;
2302 view->cur.sl_cells[view->cur.sl_idx] = sl_cells;
2303 view->cur.sl_idx++;
2304 view->cur.sl_cc[view->cur.sl_idx] = nullptr;
2305 view->cur.sl_s[view->cur.sl_idx] = nullptr;
2306 view->cur.sl_cnt = view->cur.sl_idx;
2307 view->cur.sl_idx = 0;
2308 }
2309 view->cur.sl_ln_no = view->ln_no;
2310 }
2311#ifdef DEBUG_WRAP
2312 // log_split_lines(view);
2314 // log_stripped_line_out(view);
2315#endif
2316 //-------------------------------------------------------------------------
2317 wstr[0] = '\0';
2318 wstr[1] = '\0';
2319 ui_set_cell(view->sfc, PAD, &cc, wstr, WA_NORMAL, cpx, nullptr);
2320 cmplx_buf[j] = cc;
2321 view->stripped_line_out[x] = '\0';
2322 return j;
2323}
size_t rtrim(char *)
Trims trailing spaces from string s in place.
Definition futil.c:308
ushort cp_nt
Definition ui_common.c:142
uint16_t attr_t
Definition ui_backend.h:417
#define CCHARW_MAX
Definition ui_backend.h:192
#define WA_NORMAL
char in_str[BUFSIZ+1]
Definition iloan.c:32
#define MAXLEN
Definition curskeys.c:15
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_no_max, 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, and View::wrap.

Referenced by page_prev(), scroll_next(), scroll_prev(), 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 2352 of file view_engine.c.

2352 {
2353 char tmp_str[PAD_COLS];
2354
2355 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2356 memset(tmp_str, 0, sizeof(tmp_str));
2357 for (uint c = 0; c < view->cur.sl_cells[k]; c++) {
2358 wchar_t wstr[CCHARW_MAX];
2359 attr_t attrs;
2360 short cpx;
2361 ui_get_cell(view->sfc, PAD, &view->cur.sl_cc[k][c], wstr, &attrs, &cpx, nullptr);
2362 if (wstr[0] == L'\0')
2363 tmp_str[c] = ' ';
2364 else
2365 tmp_str[c] = (char)wstr[0];
2366 }
2367 ui_log(INFO, "%s:", tmp_str);
2368 }
2369}

References View::cur, SplitLine::sl_cc, SplitLine::sl_cells, and SplitLine::sl_cnt.

◆ 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 2391 of file view_engine.c.

2391 {
2392 char tmp_str[MAXLEN];
2393
2394 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2395 if (view->cur.sl_cols[k] > 0) {
2396 memset(tmp_str, 0, sizeof(tmp_str));
2397 char *s = view->cur.sl_s[k];
2398 char *d = tmp_str;
2399 char *e = view->cur.sl_s[k] + view->cur.sl_cols[k];
2400 while (s < e)
2401 *d++ = *s++;
2402 *d = '\0';
2403 ui_log(INFO, "%s:", tmp_str);
2404 }
2405 }
2406}

References View::cur, SplitLine::sl_cnt, SplitLine::sl_cols, and SplitLine::sl_s.

◆ 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 2332 of file view_engine.c.

2332 {
2333 char tmp_str[PAD_COLS];
2334 ui_log(INFO, "%s:", view->stripped_line_out);
2335 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2336 memset(tmp_str, 0, sizeof(tmp_str));
2337 for (uint c = 0; c < view->cur.sl_cols[k]; c++)
2338 tmp_str[c] = view->cur.sl_s[k][c];
2339 ui_log(INFO, "%s:", tmp_str);
2340 }
2341}

References View::cur, SplitLine::sl_cnt, SplitLine::sl_cols, SplitLine::sl_s, and View::stripped_line_out.

◆ 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 2378 of file view_engine.c.

2378 {
2379 char tmp_str[MAXLEN];
2380 strnz__cpy(tmp_str, str, len);
2381 ui_log(INFO, "%s:", tmp_str);
2382}

References strnz__cpy().

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 __pad_refresh

Definition at line 2069 of file view_engine.c.

2069 {
2070#ifdef UAL_UI
2071 int rc = 0;
2072 // touchwin(view->sfc->mwin[WIN2]);
2073 // rc = pnoutrefresh(view->sfc->mwin[WIN2], view->pminrow, view->pmincol,
2074 // view->sminrow,
2075 // view->smincol, view->smaxrow, view->smaxcol);
2076 rc = prefresh(view->sfc->mwin[PAD],
2077 view->pminrow,
2078 view->pmincol,
2079 view->sminrow,
2080 view->smincol,
2081 view->smaxrow,
2082 view->smaxcol);
2083 if (rc == ERR) {
2084 ssnprintf(em0, MAXLEN - 1, _("%s:%d prefresh(view->sfc->mwin[WIN2], pminrow=%d, pmincol=%d, smaxrow=%d, smaxcol=%d) returned %d\n"),
2085 __FILE__, __LINE__ - 1, view->pminrow, view->pmincol, view->smaxrow, view->smaxcol, rc);
2086 ui_perror(em0);
2087 }
2088#else
2089 (void)view;
2090#endif
2091 ui_render();
2092 return 0;
2093}
#define ERR
Definition ui_backend.h:427
char em0[MAXLEN]
Definition ui_common.c:46
#define _(String)
Definition amort.c:23
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition ui_common.c:1257

References em0, View::pmincol, View::pminrow, View::sfc, View::smaxcol, View::smaxrow, View::smincol, View::sminrow, ssnprintf(), ui_perror(), and 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 * attrs,
ushort * cpx )

Parse ANSI SGR Escape Sequence.

Parameters
ansi_stris the ANSI escape sequence string to parse
attrsis 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 ui_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: ui_xterm256_idx_to_rgb(), ui_color_from_rgb(), extended_pair_content(),
ui_add_pair()
__parse_ansi_str

Definition at line 2461 of file view_engine.c.

2461 {
2462 char *tok;
2463 char t0, t1;
2464 char tstr[3];
2465 uint len, x_idx;
2466 uint fg, bg;
2467 uint fg_clr, bg_clr;
2468 char *ansi_p = ansi_str + 2;
2469 ui_pair_content(*cpx, &fg_clr, &bg_clr);
2470 fg = fg_clr;
2471 bg = bg_clr;
2472 RGB rgb;
2473 tok = strtok((char *)ansi_p, ";m");
2474 bool a_toi_error = false;
2475 while (1) {
2476 if (tok == nullptr || *tok == '\0')
2477 break;
2478 len = strlen(tok);
2479 if (len == 2) {
2480 t0 = tok[0];
2481 t1 = tok[1];
2482 if (t0 == '3' || t0 == '4') {
2483 if (t1 == '8') {
2484 tok = strtok(nullptr, ";m");
2485 if (tok != nullptr) {
2486 if (*tok == '5') {
2487 tok = strtok(nullptr, ";m");
2488 if (tok != nullptr) {
2489 x_idx = a_toi(tok, &a_toi_error);
2490 rgb = ui_xterm256_idx_to_rgb(x_idx);
2491 }
2492 } else if (*tok == '2') {
2493 tok = strtok(nullptr, ";m");
2494 rgb.r = a_toi(tok, &a_toi_error);
2495 tok = strtok(nullptr, ";m");
2496 rgb.g = a_toi(tok, &a_toi_error);
2497 tok = strtok(nullptr, ";m");
2498 rgb.b = a_toi(tok, &a_toi_error);
2499 }
2500 }
2501 if (t0 == '3')
2502 fg_clr = ui_color_from_rgb(&rgb);
2503 else if (t0 == '4')
2504 bg_clr = ui_color_from_rgb(&rgb);
2505 } else if (t1 == '9') {
2506 if (t0 == '3')
2507 fg_clr = CLR_NT_FG;
2508 else if (t0 == '4')
2509 bg_clr = CLR_NT_BG;
2510 } else if (t1 >= '0' && t1 <= '7') {
2511 if (t0 == '3') {
2512 tstr[0] = t1;
2513 tstr[1] = '\0';
2514 x_idx = a_toi(tstr, &a_toi_error);
2515 rgb = ui_xterm256_idx_to_rgb(x_idx);
2516 fg_clr = ui_color_from_rgb(&rgb);
2517 } else if (t0 == '4') {
2518 tstr[0] = t1;
2519 tstr[1] = '\0';
2520 x_idx = a_toi(tstr, &a_toi_error);
2521 rgb = ui_xterm256_idx_to_rgb(x_idx);
2522 bg_clr = ui_color_from_rgb(&rgb);
2523 }
2524 }
2525 } else if (t0 == '0') {
2526 *tok = t1;
2527 len = 1;
2528 }
2529 }
2530 if (len == 1) {
2531 if (*tok == '0') {
2532 *attrs = WA_NORMAL;
2533 fg_clr = CLR_NT_FG;
2534 bg_clr = CLR_NT_BG;
2535 } else {
2536 switch (a_toi(tok, &a_toi_error)) {
2537 case 1:
2538 *attrs |= WA_BOLD;
2539 break;
2540 case 2:
2541 *attrs |= WA_DIM;
2542 break;
2543 case 3:
2544 *attrs |= WA_ITALIC;
2545 break;
2546 case 4:
2547 *attrs |= WA_UNDERLINE;
2548 break;
2549 case 5:
2550 *attrs |= WA_BLINK;
2551 break;
2552 case 7:
2553 *attrs |= WA_REVERSE;
2554 break;
2555 case 8:
2556 *attrs |= WA_INVIS;
2557 break;
2558 default:
2559 break;
2560 }
2561 }
2562 } else if (len == 0) {
2563 *attrs = WA_NORMAL;
2564 fg_clr = CLR_NT_FG;
2565 bg_clr = CLR_NT_BG;
2566 }
2567 tok = strtok(nullptr, ";m");
2568 }
2569 if (!a_toi_error && (fg_clr != fg || bg_clr != bg))
2570 *cpx = ui_add_pair(fg_clr, bg_clr);
2571 return;
2572}
@ CLR_NT_FG
Definition ui_backend.h:537
@ CLR_NT_BG
Definition ui_backend.h:538
#define WA_BLINK
#define WA_ITALIC
#define WA_DIM
#define WA_INVIS
#define WA_BOLD
#define WA_REVERSE
#define WA_UNDERLINE
RGB ui_xterm256_idx_to_rgb(uint idx)
Convert XTerm 256 color index to RGB.
Definition ui_common.c:908
int ui_pair_content(uint pair, uint *fg, uint *bg)
Get the foreground and background colors of a specified color pair.
uint ui_add_pair(uint fg, uint bg)
Add a new color pair to the UI, or retrieve the index of an existing pair.
int ui_color_from_rgb(RGB *rgb)
Convert RGB to curses color index, adding new color if necessary.
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:784
uint8_t b
Definition ui_backend.h:308
uint8_t r
Definition ui_backend.h:308
uint8_t g
Definition ui_backend.h:308

References a_toi(), CLR_NT_BG, CLR_NT_FG, ui_add_pair(), ui_color_from_rgb(), ui_pair_content(), and ui_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 2615 of file view_engine.c.

2615 {
2616 char tmp_str[MAXLEN];
2617 uint eargc = 0;
2618 char *eargv[MAXARGS];
2619 View *view = init->view;
2620 if (view->f_help_spec || view->help_spec[0] != '\0')
2621 strnz__cpy(tmp_str, view->help_spec, MAXLEN - 1);
2622 else {
2623 strnz__cpy(tmp_str, init->mapp_help, MAXLEN - 1);
2624 strnz__cat(tmp_str, "/", MAXLEN - 1);
2625 strnz__cat(tmp_str, VIEW_HELP_FILE, MAXLEN - 1);
2626 }
2627 eargv[eargc++] = strdup("view");
2628 eargv[eargc++] = strdup("-N");
2629 eargv[eargc++] = strdup(tmp_str);
2630 eargv[eargc] = nullptr;
2631 init->lines = 48;
2632 init->cols = 72;
2633 init->begy = 0;
2634 init->begx = 0;
2635 strnz__cpy(init->title, "View Help", MAXLEN - 1);
2636 popup_view(init, eargc, eargv, init->lines, init->cols, init->begy,
2637 init->begx);
2639 init->view->f_redisplay_page = true;
2640}
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:38
#define MAXARGS
Definition cm.h:64
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 whence.c:320
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:468
char title[MAXLEN]
Definition common.h:132
char mapp_help[MAXLEN]
Definition common.h:152
int begx
Definition common.h:121
int cols
Definition common.h:119
int begy
Definition common.h:120
View * view
Definition common.h:193
int lines
Definition common.h:118
Definition view.h:59
bool f_redisplay_page
Definition view.h:104

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 __display_page

Definition at line 1364 of file view_engine.c.

1364 {
1365 view->cury = 0;
1366 view->page_top_sl = false;
1367 view->page_bot_sl = false;
1368 UiSurface *sfc = view->sfc;
1369 ui_cursor_move(sfc, PAD, 0, 0);
1370 if (view->f_ln)
1371 ui_cursor_move(sfc, LNNO, 0, 0);
1372 view->ln_no = view->page_top_ln_no;
1373 view->page_top_ln_no = 0;
1374 view->page_bot_ln_no = 0;
1375 while (view->cury < view->scroll_lines) {
1376 get_line(view, view->ln_no);
1377 if (view->f_eod) {
1378 view->ln_no_max = view->ln_no;
1379 break;
1380 }
1381 fmt_line(view);
1382 if (view->wrap && view->cury == 0)
1383 view->cur.sl_idx = view->page_top_sl_idx;
1385 ui_render();
1386 view->ln_no++;
1387 }
1388 if (view->f_eod) {
1389 view->ln_no_max = view->ln_no;
1391 }
1392 view->ln_no--;
1393 view->page_bot_end_pos = view->file_pos - 1;
1394 view->page_bot_pos = view->file_pos;
1395 view->page_bot_ln_no = view->ln_no;
1396}
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, View::ln_no_max, 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 page_next(), and view_cmd_processor().

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