Skip to content

Commit

Permalink
Sheet update 20241009 v2 (#215)
Browse files Browse the repository at this point in the history
* sheet/display_cell(): simplify

---------

Co-authored-by: Azeem Sajid <[email protected]>
  • Loading branch information
liquidaty and iamazeem authored Oct 10, 2024
1 parent ae83b79 commit 3d67fc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
17 changes: 5 additions & 12 deletions app/sheet.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE_EXTENDED
#endif
Expand Down Expand Up @@ -448,18 +450,9 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
const char *display_cell(struct zsv_sheet_buffer *buff, size_t data_row, size_t data_col, int row, int col) {
char *str = (char *)zsv_sheet_buffer_cell_display(buff, data_row, data_col);
size_t len = str ? strlen(str) : 0;
if (len == 0 || has_multibyte_char(str, len < ZTV_CELL_DISPLAY_WIDTH ? len : ZTV_CELL_DISPLAY_WIDTH) == 0) {
// temporarily add a NULL delimiter
int ch = str[ZTV_CELL_DISPLAY_WIDTH - 1];
str[ZTV_CELL_DISPLAY_WIDTH - 1] = '\0'; // ensure a blank space between cells
mvprintw(row, col * ZTV_CELL_DISPLAY_WIDTH, "%-*s", ZTV_CELL_DISPLAY_WIDTH, str);
str[ZTV_CELL_DISPLAY_WIDTH - 1] = ch;
/*
mvprintw(row, col * ZTV_CELL_DISPLAY_WIDTH, "%-*.*s", ZTV_CELL_DISPLAY_WIDTH,
len < ZTV_CELL_DISPLAY_WIDTH ? len : ZTV_CELL_DISPLAY_WIDTH - 1,
str);
*/
} else {
if (len == 0 || has_multibyte_char(str, len < ZTV_CELL_DISPLAY_WIDTH ? len : ZTV_CELL_DISPLAY_WIDTH) == 0)
mvprintw(row, col * ZTV_CELL_DISPLAY_WIDTH, "%-*.*s", ZTV_CELL_DISPLAY_WIDTH, ZTV_CELL_DISPLAY_WIDTH - 1, str);
else {
size_t used_width;
int err = 0;
unsigned char *s = (unsigned char *)str;
Expand Down
6 changes: 1 addition & 5 deletions app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,12 @@ test-compare: test-%: ${BUILD_DIR}/bin/zsv_%${EXE}
test-sheet: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} worldcitiespop_mil.csv test-sheet-all

test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4
@(! tmux kill-session -t $@ 2>/dev/null && ${TEST_PASS} || ${TEST_FAIL})
@(for SESSION in $^; do ! tmux kill-session -t "$$SESSION" 2>/dev/null; done && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-1: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@echo 'set-option default-terminal "tmux-256color"' > ~/.tmux.conf
@(tmux new-session -x 1000 -y 5 -d -s $@ "${PREFIX} $< worldcitiespop_mil.csv" && \
tmux set-window-option -t test-sheet prefix none && \
sleep 0.5 && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
Expand All @@ -574,7 +573,6 @@ test-sheet-1: ${BUILD_DIR}/bin/zsv_sheet${EXE}
test-sheet-2: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@(tmux new-session -x 1000 -y 5 -d -s $@ "${PREFIX} $< worldcitiespop_mil.csv" && \
tmux set-window-option -t test-sheet prefix none && \
sleep 0.5 && \
tmux send-keys -t $@ "C-F" && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
Expand All @@ -584,7 +582,6 @@ test-sheet-2: ${BUILD_DIR}/bin/zsv_sheet${EXE}
test-sheet-3: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@(tmux new-session -x 1000 -y 5 -d -s $@ "${PREFIX} $< worldcitiespop_mil.csv" && \
tmux set-window-option -t test-sheet prefix none && \
sleep 0.5 && \
tmux send-keys -t $@ "f" "sarmaj" Enter && \
sleep 0.5 && \
Expand All @@ -595,7 +592,6 @@ test-sheet-3: ${BUILD_DIR}/bin/zsv_sheet${EXE}
test-sheet-4: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@(tmux new-session -x 1000 -y 5 -d -s $@ "${PREFIX} $< worldcitiespop_mil.csv" && \
tmux set-window-option -t test-sheet prefix none && \
sleep 0.5 && \
tmux send-keys -t $@ "C-F" "C-F" "C-B" && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
Expand Down
5 changes: 0 additions & 5 deletions app/test/expected/test-sheet4.out

This file was deleted.

0 comments on commit 3d67fc3

Please sign in to comment.