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

1420 {
1421 char ln_s[16];
1422
1423 UiSurface *sfc = view->sfc;
1424 if (view->wrap && view->cur.sl_cnt > 0) {
1425 if (view->cur.sl_idx < view->cur.sl_cnt) {
1427 return;
1428 }
1429 }
1430 if (view->cury > view->scroll_lines - 1)
1431 view->cury = view->scroll_lines - 1;
1432 if (view->f_ln) {
1433 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1434 ui_cursor_move(sfc, LNNO, view->cury, 0);
1435 ui_wclrtoeol(sfc, LNNO);
1436 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1437 }
1438 ui_cursor_move(sfc, PAD, view->cury, 0);
1439 ui_wclrtoeol(sfc, PAD);
1440#ifdef UAL_UI
1441 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, view->cmplx_buf);
1442#else
1443 ui_mvwadd_wchstr(sfc, PAD, view->cury, 0, (struct nccell *)view->cmplx_buf);
1444#endif
1445 if (view->cury == 0)
1446 view->page_top_ln_no = view->ln_no;
1447 if (view->cury == view->scroll_lines - 1)
1448 view->page_bot_ln_no = view->ln_no;
1449 view->cury++;
1450}
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:698
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 *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398
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_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 1510 of file view_engine.c.

1510 {
1511 UiSurface *sfc = view->sfc;
1512 if (view->f_ln) {
1513 ui_cursor_move(sfc, LNNO, view->cury, 0);
1514 ui_wclrtobot(sfc, LNNO);
1515 }
1516 ui_cursor_move(sfc, PAD, view->cury, 0);
1517 ui_wclrtobot(sfc, PAD);
1518 view->page_bot_ln_no = view->ln_no;
1519 view->ln_no_max = view->ln_no;
1520}
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 2613 of file view_engine.c.

2613 {
2614 char message_str[PAD_COLS + 1];
2615 uint l;
2616 UiSurface *sfc = view->sfc;
2617 l = strnz__cpy(message_str, s, PAD_COLS);
2618 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
2619 if (l != 0) {
2620 ui_wclrtoeol(sfc, CMDLN);
2621 ui_bkgdset(sfc, CMDLN, &cell_nt_rev);
2622 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 0, " ");
2623 ui_mvwaddstr(sfc, CMDLN, view->cmd_line, 1, message_str);
2624 ui_waddstr(sfc, CMDLN, " ");
2625 ui_bkgdset(sfc, CMDLN, &cell_nt);
2626 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
2627 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
2628 }
2629#ifdef DEBUG_IMMED_UI
2630 ui_render();
2631#endif
2632 return (view->curx);
2633}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:931
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:707
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:988
#define PAD_COLS
Definition view.h:39
UiCell cell_nt
Definition ui_common.c:123
UiCell cell_nt_rev
Definition ui_common.c:124
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 lf.c:2299

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

1461 {
1462 char ln_s[16];
1463 UiSurface *sfc = view->sfc;
1464 if (view->cury > view->scroll_lines - 1)
1465 view->cury = view->scroll_lines - 1;
1466
1467 for (uint i = view->cur.sl_idx; i < view->cur.sl_cnt; i++) {
1468 if (i == 0) {
1469 if (view->f_ln) {
1470 ssnprintf(ln_s, 8, "%7jd", view->ln_no);
1471 ui_cursor_move(sfc, LNNO, view->cury, 0);
1472 ui_wclrtoeol(sfc, LNNO);
1473 ui_mvwaddstr(sfc, LNNO, view->cury, 0, ln_s);
1474 }
1475 } else {
1476 if (view->f_ln) {
1477 ui_cursor_move(sfc, LNNO, view->cury, 0);
1478 ui_wclrtoeol(sfc, LNNO);
1479 }
1480 }
1481 ui_cursor_move(sfc, PAD, view->cury, 0);
1482 ui_wclrtoeol(sfc, PAD);
1483 ui_wadd_wchnstr(sfc, PAD, view->cur.sl_cc[i], view->cur.sl_cells[i]);
1484 if (view->cury == 0) {
1485 view->page_top_ln_no = view->ln_no;
1486 view->page_top_sl = true;
1487 view->page_top_sl_idx = i;
1488 view->page_top_sl_cnt = view->cur.sl_cnt;
1489 }
1490 if (view->cury == view->scroll_lines - 1) {
1491 view->page_bot_ln_no = view->ln_no;
1492 view->page_bot_sl = true;
1493 view->page_bot_sl_idx = i;
1494 view->page_bot_sl_cnt = view->cur.sl_cnt;
1495 view->page_bot_ln_no = view->ln_no;
1496 }
1497 view->cury++;
1498 if (view->cury == view->scroll_lines)
1499 break;
1500 }
1501}
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 2120 of file view_engine.c.

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

2377 {
2378 char tmp_str[PAD_COLS];
2379
2380 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2381 memset(tmp_str, 0, sizeof(tmp_str));
2382 for (uint c = 0; c < view->cur.sl_cells[k]; c++) {
2383 wchar_t wstr[CCHARW_MAX];
2384 attr_t attrs;
2385 short cpx;
2386 ui_get_cell(view->sfc, PAD, &view->cur.sl_cc[k][c], wstr, &attrs, &cpx, nullptr);
2387 if (wstr[0] == L'\0')
2388 tmp_str[c] = ' ';
2389 else
2390 tmp_str[c] = (char)wstr[0];
2391 }
2392 ui_log(INFO, "%s:", tmp_str);
2393 }
2394}

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

2416 {
2417 char tmp_str[MAXLEN];
2418
2419 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2420 if (view->cur.sl_cols[k] > 0) {
2421 memset(tmp_str, 0, sizeof(tmp_str));
2422 char *s = view->cur.sl_s[k];
2423 char *d = tmp_str;
2424 char *e = view->cur.sl_s[k] + view->cur.sl_cols[k];
2425 while (s < e)
2426 *d++ = *s++;
2427 *d = '\0';
2428 ui_log(INFO, "%s:", tmp_str);
2429 }
2430 }
2431}

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

2357 {
2358 char tmp_str[PAD_COLS];
2359 ui_log(INFO, "%s:", view->stripped_line_out);
2360 for (uint k = 0; k < view->cur.sl_cnt; k++) {
2361 memset(tmp_str, 0, sizeof(tmp_str));
2362 for (uint c = 0; c < view->cur.sl_cols[k]; c++)
2363 tmp_str[c] = view->cur.sl_s[k][c];
2364 ui_log(INFO, "%s:", tmp_str);
2365 }
2366}

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

2403 {
2404 char tmp_str[MAXLEN];
2405 strnz__cpy(tmp_str, str, len);
2406 ui_log(INFO, "%s:", tmp_str);
2407}

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

2083 {
2084 int rc = 0;
2085 // touchwin(view->sfc->mwin[WIN2]);
2086 // rc = pnoutrefresh(view->sfc->mwin[WIN2], view->pminrow, view->pmincol,
2087 // view->sminrow,
2088 // view->smincol, view->smaxrow, view->smaxcol);
2089 rc = ui_prefresh(view->sfc,
2090 PAD,
2091 view->pminrow,
2092 view->pmincol,
2093 view->sminrow,
2094 view->smincol,
2095 view->smaxrow,
2096 view->smaxcol);
2097 if (rc == ERR) {
2098 ui_log(ERROR, _("%s:%d prefresh(view->sfc->mwin[WIN2], pminrow=%d, pmincol=%d, smaxrow=%d, smaxcol=%d) returned %d\n"), __FILE__, __LINE__ - 1, view->pminrow, view->pmincol, view->smaxrow, view->smaxcol, rc);
2099 }
2100#ifdef IMMEDOK
2101 ui_render();
2102#endif
2103 return 0;
2104}
#define ERR
Definition ui_backend.h:468
int ui_prefresh(UiSurface *s, ss_t w, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol)
Definition ui_ncurses.c:923
#define _(String)
Definition amort.c:23

References View::pmincol, View::pminrow, View::sfc, View::smaxcol, View::smaxrow, View::smincol, View::sminrow, ui_log_write(), and ui_prefresh().

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

2486 {
2487 char *tok;
2488 char t0, t1;
2489 char tstr[3];
2490 uint len, x_idx;
2491 uint fg, bg;
2492 uint fg_clr, bg_clr;
2493 char *ansi_p = ansi_str + 2;
2494 ui_pair_content(*cpx, &fg_clr, &bg_clr);
2495 bool f_rgb = false;
2496 fg = fg_clr;
2497 bg = bg_clr;
2498 RGB rgb;
2499 tok = strtok((char *)ansi_p, ";m");
2500 bool a_toi_error = false;
2501 while (1) {
2502 if (tok == nullptr || *tok == '\0')
2503 break;
2504 len = strlen(tok);
2505 if (len == 2) {
2506 t0 = tok[0];
2507 t1 = tok[1];
2508 if (t0 == '3' || t0 == '4') {
2509 if (t1 == '8') {
2510 tok = strtok(nullptr, ";m");
2511 if (tok != nullptr) {
2512 if (*tok == '5') {
2513 tok = strtok(nullptr, ";m");
2514 if (tok != nullptr) {
2515 x_idx = a_toi(tok, &a_toi_error);
2516 rgb = ui_xterm256_idx_to_rgb(x_idx);
2517 f_rgb = true;
2518 }
2519 } else if (*tok == '2') {
2520 tok = strtok(nullptr, ";m");
2521 if (tok != nullptr) {
2522 rgb.r = a_toi(tok, &a_toi_error);
2523 tok = strtok(nullptr, ";m");
2524 if (tok != nullptr) {
2525 rgb.g = a_toi(tok, &a_toi_error);
2526 tok = strtok(nullptr, ";m");
2527 if (tok != nullptr) {
2528 rgb.b = a_toi(tok, &a_toi_error);
2529 f_rgb = true;
2530 }
2531 }
2532 }
2533 }
2534 }
2535 if (f_rgb) {
2536 if (t0 == '3')
2537 fg_clr = ui_color_from_rgb(&rgb);
2538 else if (t0 == '4')
2539 bg_clr = ui_color_from_rgb(&rgb);
2540 }
2541 } else if (t1 == '9') {
2542 if (t0 == '3')
2543 fg_clr = CLR_NT_FG;
2544 else if (t0 == '4')
2545 bg_clr = CLR_NT_BG;
2546 } else if (t1 >= '0' && t1 <= '7') {
2547 if (t0 == '3') {
2548 tstr[0] = t1;
2549 tstr[1] = '\0';
2550 x_idx = a_toi(tstr, &a_toi_error);
2551 rgb = ui_xterm256_idx_to_rgb(x_idx);
2552 fg_clr = ui_color_from_rgb(&rgb);
2553 } else if (t0 == '4') {
2554 tstr[0] = t1;
2555 tstr[1] = '\0';
2556 x_idx = a_toi(tstr, &a_toi_error);
2557 rgb = ui_xterm256_idx_to_rgb(x_idx);
2558 bg_clr = ui_color_from_rgb(&rgb);
2559 }
2560 }
2561 } else if (t0 == '0') {
2562 *tok = t1;
2563 len = 1;
2564 }
2565 }
2566 if (len == 1) {
2567 if (*tok == '0') {
2568 *attrs = WA_NORMAL;
2569 fg_clr = CLR_NT_FG;
2570 bg_clr = CLR_NT_BG;
2571 } else {
2572 switch (a_toi(tok, &a_toi_error)) {
2573 case 1:
2574 *attrs |= WA_BOLD;
2575 break;
2576 case 2:
2577 *attrs |= WA_DIM;
2578 break;
2579 case 3:
2580 *attrs |= WA_ITALIC;
2581 break;
2582 case 4:
2583 *attrs |= WA_UNDERLINE;
2584 break;
2585 case 5:
2586 *attrs |= WA_BLINK;
2587 break;
2588 case 7:
2589 *attrs |= WA_REVERSE;
2590 break;
2591 case 8:
2592 *attrs |= WA_INVIS;
2593 break;
2594 default:
2595 break;
2596 }
2597 }
2598 } else if (len == 0) {
2599 *attrs = WA_NORMAL;
2600 fg_clr = CLR_NT_FG;
2601 bg_clr = CLR_NT_BG;
2602 }
2603 tok = strtok(nullptr, ";m");
2604 }
2605 if (!a_toi_error && (fg_clr != fg || bg_clr != bg))
2606 *cpx = ui_add_pair(fg_clr, bg_clr);
2607 return;
2608}
@ CLR_NT_FG
Definition ui_backend.h:583
@ CLR_NT_BG
Definition ui_backend.h:584
#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:969
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:806
uint8_t b
Definition ui_backend.h:349
uint8_t r
Definition ui_backend.h:349
uint8_t g
Definition ui_backend.h:349

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

2654 {
2655 char tmp_str[MAXLEN];
2656 uint eargc = 0;
2657 char *eargv[MAXARGS];
2658 View *view = init->view;
2659 if (view->f_help_spec || view->help_spec[0] != '\0')
2660 strnz__cpy(tmp_str, view->help_spec, MAXLEN - 1);
2661 else {
2662 strnz__cpy(tmp_str, init->mapp_help, MAXLEN - 1);
2663 strnz__cat(tmp_str, "/", MAXLEN - 1);
2664 strnz__cat(tmp_str, VIEW_HELP_FILE, MAXLEN - 1);
2665 }
2666 eargv[eargc++] = strdup("view");
2667 eargv[eargc++] = strdup("-N");
2668 eargv[eargc++] = strdup(tmp_str);
2669 eargv[eargc] = nullptr;
2670 init->lines = 48;
2671 init->cols = 72;
2672 init->begy = 0;
2673 init->begx = 0;
2674 strnz__cpy(init->title, "View Help", MAXLEN - 1);
2675 popup_view(init, eargc, eargv, init->lines, init->cols, init->begy,
2676 init->begx);
2678 init->view->f_redisplay_page = true;
2679}
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:67
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 lf.c:2330
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:474
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 1367 of file view_engine.c.

1367 {
1368 view->cury = 0;
1369 view->page_top_sl = false;
1370 view->page_bot_sl = false;
1371 UiSurface *sfc = view->sfc;
1372 ui_cursor_move(sfc, PAD, 0, 0);
1373 if (view->f_ln)
1374 ui_cursor_move(sfc, LNNO, 0, 0);
1375 view->ln_no = view->page_top_ln_no;
1376 view->page_top_ln_no = 0;
1377 view->page_bot_ln_no = 0;
1378 while (view->cury < view->scroll_lines) {
1379 get_line(view, view->ln_no);
1380 if (view->f_eod) {
1381 view->ln_no_max = view->ln_no;
1382 break;
1383 }
1384 fmt_line(view);
1385 if (view->wrap && view->cury == 0)
1386 view->cur.sl_idx = view->page_top_sl_idx;
1388#ifdef DEBUG_IMMED_UI
1389 ui_render();
1391#endif
1392 view->ln_no++;
1393 }
1394 if (view->f_eod) {
1395 view->ln_no_max = view->ln_no;
1397 }
1398 view->ln_no--;
1399 view->page_bot_end_pos = view->file_pos - 1;
1400 view->page_bot_pos = view->file_pos;
1401 view->page_bot_ln_no = view->ln_no;
1402 // ui_render();
1403 // pad_refresh(view);
1404}
void get_line(View *, off_t)
void display_line(View *)
Display Line on Padparam View *view data structure.
int pad_refresh(View *)
Refresh Pad and Line Number Window.
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(), 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: