diff options
author | Andrés <andmarti@gmail.com> | 2021-04-19 10:02:58 -0300 |
---|---|---|
committer | Andrés <andmarti@gmail.com> | 2021-04-19 10:02:58 -0300 |
commit | 4c0d857e02ab9b14e50866b76ae681baac6acafc (patch) | |
tree | 13c2f9e5f1a588052bcb5f6d251b1c81a871ae4e | |
parent | 6428e7d4cd7a2e2e794585e36e1231812f123e4c (diff) |
handle \n when entering strings
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | src/cmds.c | 13 | ||||
-rwxr-xr-x | src/doc | 9 | ||||
-rw-r--r-- | src/interp.c | 4 | ||||
-rw-r--r-- | src/tui.c | 13 | ||||
-rwxr-xr-x | src/utils/string.c | 2 |
6 files changed, 34 insertions, 13 deletions
@@ -26,17 +26,17 @@ store frozen rows and cols when saving file added :formatcol command (handling its undo as well) added :formatrow command (handling its undo as well) undo of freeze row and col +handle \n in cell input, and with autowrap Pending ------- remove old references to freezer / freezec test calc_offscr_rows and calc_offscr_cols -handle \n in cell input change input bar from window to pad check all cmds movement functions after new frozen mods save offscr_sc_rows, offscr_sc_cols, COLS and LINES values when saving file - +handle \n inside csv files to increase rows height show_shorthelp show_cmd notimeout @@ -47,7 +47,7 @@ restore comments handle content alignment over multiple lines in cmds.c:pad_and_align handle mouse clicks in edition mode. -Rethink LUA evaluation +Rethink LUA evaluation! -- Thanks to all that helped and created PR. @@ -2464,6 +2464,7 @@ int calc_offscr_sc_cols() { * \param[in] align * \param[in] padding * \param[in] str_out + * \param[in] rowfmt: rowheight * * \return resulting string to be printed to the screen */ @@ -2502,7 +2503,8 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a } // If content exceedes column width, outputs n number of '*' needed to fill column width - if (str_len + num_len + padding > col_width * rowfmt && !get_conf_int("truncate") && !get_conf_int("overlap") ) { + if (str_len + num_len + padding > col_width * rowfmt && ! get_conf_int("truncate") && + ! get_conf_int("overlap") && ! get_conf_int("autowrap")) { if (padding) wmemset(str_out + wcslen(str_out), L'#', padding); wmemset(str_out + wcslen(str_out), L'*', col_width - padding); return; @@ -2547,6 +2549,15 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a str_out[col_width] = '\0'; } + // on each \n chars, replace with n number of L' ' to complete column width + int posnl, leftnl = 0; + while ((posnl = wstr_in_wstr(str_out, L"\\n")) != -1) { + del_range_wchars(str_out, posnl, posnl+1); + if (posnl < col_width) leftnl = col_width - posnl; + else leftnl = col_width - posnl % col_width; + while (leftnl-- > 0) add_wchar(str_out, L' ', posnl); + } + return; } @@ -249,6 +249,15 @@ Commands for handling cell content: < Enter a left justified string or string expression. \ Enter a centered label. > Enter a right justified string or string expression. + > + NOTE: if entering strings that exceed column width, you + can make them show truncated, overlapping to adjacent column, or to + wrap it increasing the rows height. + Please see :set overlap, :set truncate, :set autowrap + options. + You can also type \n when entering strings and sc-im will increase + row height accordangly. + <TAB> Return to Edit mode from Insert mode. <LEFT>, <RIGHT> Move the cursor with the arrow keys. diff --git a/src/interp.c b/src/interp.c index d28c022..96c9c4c 100644 --- a/src/interp.c +++ b/src/interp.c @@ -2615,10 +2615,6 @@ void slet(struct ent * v, struct enode * se, int flushdir) { } else if (constant(se)) { label(v, p, flushdir); - // auto wrap - if (! get_conf_int("truncate") && ! get_conf_int("overlap") && get_conf_int("autowrap")) - row_format[v->row] = ceil(strlen(p) * 1.0 / fwidth[v->col]); - if (p) scxfree(p); efree(se); if (v->flags & is_strexpr) { @@ -81,6 +81,7 @@ #include <stdarg.h> #include "main.h" +#include "macros.h" #include "conf.h" #include "input.h" #include "tui.h" @@ -311,8 +312,8 @@ void ui_do_welcome() { int mxcol = offscr_sc_cols + calc_offscr_sc_cols() - 1; int mxrow = offscr_sc_rows + calc_offscr_sc_rows() - 1; ui_show_sc_col_headings(main_win, mxcol); - ui_show_sc_row_headings(main_win, mxrow); ui_show_content(main_win, mxrow, mxcol); + ui_show_sc_row_headings(main_win, mxrow); // schow_sc_row_headings must be after show_content #ifdef USECOLORS ui_set_ucolor(main_win, &ucolors[WELCOME], DEFAULT_COLOR); @@ -430,13 +431,13 @@ void ui_update(int header) { // Show sc_col headings: A, B, C, D.. ui_show_sc_col_headings(main_win, mxcol); - // Show sc_row headings: 0, 1, 2, 3.. - ui_show_sc_row_headings(main_win, mxrow); - // Show the content of the cells // Numeric values, strings. ui_show_content(main_win, mxrow, mxcol); + // Show sc_row headings: 0, 1, 2, 3.. + ui_show_sc_row_headings(main_win, mxrow); // schow_sc_row_headings must be after show_content + if (status_line_empty && get_conf_int("show_cursor")) { // Leave cursor on selected cell when no status message wmove(main_win, curwinrow, curwincol); @@ -971,6 +972,10 @@ void ui_show_content(WINDOW * win, int mxrow, int mxcol) { // } pad_and_align(text, num, fieldlen, align, (*p)->pad, out, row_format[row]); + // auto wrap + if (! get_conf_int("truncate") && ! get_conf_int("overlap") && get_conf_int("autowrap")) + row_format[row] = ceil(wcslen(out) * 1.0 / fwidth[col]); + #ifdef USECOLORS if (has_colors() && get_conf_int("underline_grid")) { attr_t attr; diff --git a/src/utils/string.c b/src/utils/string.c index 6cc52aa..c6c583c 100755 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -171,7 +171,7 @@ int add_char(char * str, char c, int posicion) { } /** - * \brief Add a C character to a cell in POSICION. Wade char version. + * \brief Add a C character to a cell in POSICION. Wide char version. * * \details STR should be previously allocated with enough memory. * |