Skip to content

Commit

Permalink
fix(display_format): allow interrupting DisplayCell function
Browse files Browse the repository at this point in the history
Fixes #1324
  • Loading branch information
Nelson-numerical-software committed Jan 3, 2025
1 parent f97cbe3 commit e0b4eba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Advanced terminal updated (common for all platforms without GUI, auto completion, search history).
- Python 3.13.1 supported.

### Fixed

- [#1324](http://github.com/nelson-lang/nelson/issues/1324) Cell display could not be interrupted.

## 1.10.0 (2024-12-14)

### Added
Expand Down
23 changes: 19 additions & 4 deletions modules/display_format/src/cpp/DisplayCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "NelsonConfiguration.hpp"
#include "DisplayVariableHelpers.hpp"
#include "FormatHelpers.hpp"
#include "nlsBuildConfig.h"
//=============================================================================
namespace Nelson {
//=============================================================================
Expand Down Expand Up @@ -81,7 +82,10 @@ Display2dCell(size_t evaluatorID, Interface* io, const ArrayOf& A, const std::ws

indexType v = 0;
bool isColumnsVector = A.isColumnVector();
for (indexType k = 0; k < nbElements; ++k) {
#if WITH_OPENMP
#pragma omp parallel for
#endif
for (ompIndexType k = 0; k < (ompIndexType)nbElements; ++k) {
if (v >= columns) {
v = 0;
}
Expand Down Expand Up @@ -169,7 +173,12 @@ DisplayNdCell(size_t evaluatorID, Interface* io, const ArrayOf& A, const std::ws
if (currentLineSpacing == NLS_LINE_SPACING_LOOSE) {
io->outputMessage(L"\n");
}
while (wdims.inside(dims)) {
bool continueDisplay = true;
while (wdims.inside(dims) && continueDisplay) {
if (NelsonConfiguration::getInstance()->getInterruptPending(evaluatorID)) {
continueDisplay = false;
break;
}
if (offset != 0) {
if (currentLineSpacing == NLS_LINE_SPACING_LOOSE) {
io->outputMessage(L"\n");
Expand All @@ -191,7 +200,11 @@ DisplayNdCell(size_t evaluatorID, Interface* io, const ArrayOf& A, const std::ws
std::vector<size_t> vSize(columns, (size_t)0);
indexType nbElements = rows * columns;
wstringVector cellSummarize(nbElements, L"");
for (indexType k = 0; k < nbElements; ++k) {

#if WITH_OPENMP
#pragma omp parallel for
#endif
for (ompIndexType k = 0; k < (ompIndexType)nbElements; ++k) {
cellSummarize[k] = getAsFormattedString(
elements, k + offset, currentNumericFormat, termWidth, false);
vSize[k / rows] = std::max(vSize[k / rows], cellSummarize[k].length());
Expand All @@ -218,7 +231,9 @@ DisplayNdCell(size_t evaluatorID, Interface* io, const ArrayOf& A, const std::ws
}
io->outputMessage(msg);
}
for (indexType i = 0; i < rows; i++) {
for (indexType i = 0;
i < rows && !NelsonConfiguration::getInstance()->getInterruptPending(evaluatorID);
i++) {
for (indexType j = 0; j < colsInThisPage
&& !NelsonConfiguration::getInstance()->getInterruptPending(evaluatorID);
j++) {
Expand Down
20 changes: 20 additions & 0 deletions modules/display_format/tests/bug_github_issue_#1324.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%=============================================================================
% Copyright (c) 2017 Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
% <-- Issue URL -->
% https://github.com/nelson-lang/nelson/issues/1324
% <-- Short Description -->
% Cell display could not be interrupted.
%=============================================================================
% <--INTERACTIVE TEST-->
%=============================================================================
A = 1:10
cell(A)
% and press Ctrl+C
%=============================================================================

0 comments on commit e0b4eba

Please sign in to comment.