Skip to content

Commit

Permalink
Merge pull request andmarti1424#354 from ayroblu/add_truncate_cells
Browse files Browse the repository at this point in the history
Option to truncate cells rather than showing asterisks
  • Loading branch information
andmarti1424 authored Apr 10, 2020
2 parents 7f01c44 + e215a1b commit 00eb219
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void int_deletecol(int col, int mult) {
* with the "pt" command. r1, c1, r2, and c2 define the range in which the
* dr and dc values should be used. Special =='u' means special copy from
* spreadsheet to undo struct. Since its mandatory to make isolated copies
* of p->expr->e.o.right.e.v.vp and p->expr->e.o.right.e.v.vp
* of p->expr->e.o.right.e.v.vp and p->expr->e.o.right.e.v.vp
*
* \param[in] n
* \param[in] p
Expand Down Expand Up @@ -655,7 +655,7 @@ struct enode * copye(register struct enode *e, int Rdelta, int Cdelta, int r1, i
}

/**
* \brief TODO Write brief function description
* \brief TODO Write brief function description
*
* \details Note: Modified 9/17/90 THA to handle more formats.
*
Expand Down Expand Up @@ -963,7 +963,7 @@ void int_deleterow(int row, int mult) {
* \param[in] sc
* \param[in] er
* \param[in] ec
*
*
* \return none
*/

Expand Down Expand Up @@ -996,7 +996,7 @@ void ljustify(int sr, int sc, int er, int ec) {

/**
* \brief TODO Document rjustify()
*
*
* \param[in] sr
* \param[in] sc
* \param[in] er
Expand Down Expand Up @@ -2010,7 +2010,7 @@ void valueize_area(int sr, int sc, int er, int ec) {
* \param[in] vir_tlcol
* \param[in] vir_brrow
* \param[in] vir_brcol
*
*
* \return none
*/

Expand Down Expand Up @@ -2529,7 +2529,7 @@ 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 && ( (! atoi(get_conf_value("overlap"))) || align == 1) ) {
if (str_len + num_len + padding > col_width && !atoi(get_conf_value("truncate")) && ( (! atoi(get_conf_value("overlap"))) || align == 1) ) {
if (padding) wmemset(str_out + wcslen(str_out), L'#', padding);
wmemset(str_out + wcslen(str_out), L'*', col_width - padding);
return;
Expand Down Expand Up @@ -2569,6 +2569,11 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a
swprintf(str_out + wcslen(str_out), BUFFERSIZE, L"%s", numeric_value);
}

// Similar condition to max width '*' condition above, but just trims instead
if (str_len + num_len + padding > col_width && atoi(get_conf_value("truncate"))) {
str_out[col_width] = '\0';
}

return;
}

Expand Down Expand Up @@ -2746,7 +2751,7 @@ int is_single_command (struct block * buf, long timeout) {
else if (buf->value == L'd' && bs == 2 && // cuts a cell
buf->pnext->value == L'd') res = EDITION_CMD;

else if (buf->value == L'\'' && bs == 2 && // tick
else if (buf->value == L'\'' && bs == 2 && // tick
((buf->pnext->value - (L'a' - 1)) < 1 ||
buf->pnext->value > 26)) res = MOVEMENT_CMD;

Expand Down
1 change: 1 addition & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void store_default_config_values() {
put(user_conf_d, "numeric_zero", "1");
put(user_conf_d, "numeric_decimal", "1");
put(user_conf_d, "overlap", "0");
put(user_conf_d, "truncate", "0");
put(user_conf_d, "debug", "0");
put(user_conf_d, "ignorecase", "0");
put(user_conf_d, "trigger", "1");
Expand Down
4 changes: 4 additions & 0 deletions src/doc
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,10 @@ Commands for handling cell content:
If cell content exceedes column width it gets cut off to fit the column
width. If overlap is set, the content overflows into the next column.

'truncate' [default off]
If cell content exceedes column width it gets replaced by asterisks '*'.
If truncate is set, the content is cut off at the end of the cell.

'debug' [default off]
set this to see debug messages in screen

Expand Down
6 changes: 6 additions & 0 deletions src/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ token S_YANKCOL
%token K_NONUMERIC_ZERO
%token K_OVERLAP
%token K_NOOVERLAP
%token K_TRUNCATE
%token K_NOTRUNCATE
%token K_QUIT_AFTERLOAD
%token K_NOQUIT_AFTERLOAD
%token K_XLSX_READFORMULAS
Expand Down Expand Up @@ -1047,6 +1049,10 @@ setitem :
else parse_str(user_conf_d, "overlap=1", TRUE); }
| K_OVERLAP { parse_str(user_conf_d, "overlap=1", TRUE); }
| K_NOOVERLAP { parse_str(user_conf_d, "overlap=0", TRUE); }
| K_TRUNCATE '=' NUMBER { if ($3 == 0) parse_str(user_conf_d, "truncate=0", TRUE);
else parse_str(user_conf_d, "truncate=1", TRUE); }
| K_TRUNCATE { parse_str(user_conf_d, "truncate=1", TRUE); }
| K_NOTRUNCATE { parse_str(user_conf_d, "truncate=0", TRUE); }
| K_AUTOBACKUP '=' NUMBER {
char cmd[MAXCMD];
sprintf(cmd, "autobackup=%d", $3);
Expand Down

0 comments on commit 00eb219

Please sign in to comment.