From 6c7dad0a4251dfea364f57cfd60c04d7d860db1b Mon Sep 17 00:00:00 2001 From: Allan CORNET Date: Sat, 4 Jan 2025 09:32:43 +0100 Subject: [PATCH] fix(display_format): allow interrupting DisplayCell function Fixes #1324 (#1326) --- CHANGELOG.md | 4 ++++ .../display_format/src/cpp/DisplayCell.cpp | 23 +++++++++++++++---- .../tests/bug_github_issue_#1324.m | 20 ++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 modules/display_format/tests/bug_github_issue_#1324.m diff --git a/CHANGELOG.md b/CHANGELOG.md index df7961ba2b..663684812c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/modules/display_format/src/cpp/DisplayCell.cpp b/modules/display_format/src/cpp/DisplayCell.cpp index 2c54a686ed..be0eeb4d57 100644 --- a/modules/display_format/src/cpp/DisplayCell.cpp +++ b/modules/display_format/src/cpp/DisplayCell.cpp @@ -17,6 +17,7 @@ #include "NelsonConfiguration.hpp" #include "DisplayVariableHelpers.hpp" #include "FormatHelpers.hpp" +#include "nlsBuildConfig.h" //============================================================================= namespace Nelson { //============================================================================= @@ -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; } @@ -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"); @@ -191,7 +200,11 @@ DisplayNdCell(size_t evaluatorID, Interface* io, const ArrayOf& A, const std::ws std::vector 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()); @@ -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++) { diff --git a/modules/display_format/tests/bug_github_issue_#1324.m b/modules/display_format/tests/bug_github_issue_#1324.m new file mode 100644 index 0000000000..02ca27c205 --- /dev/null +++ b/modules/display_format/tests/bug_github_issue_#1324.m @@ -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 +%=============================================================================