Skip to content

Commit

Permalink
Console: Fix column width and wrap in some cases. Fixed in most cases…
Browse files Browse the repository at this point in the history
… (many equals candidates or very long names). Not all case, terminal with no wrapping is always better.

(cherry picked from commit ef3f264)
  • Loading branch information
julien-boudry committed Dec 7, 2021
1 parent 1e013a1 commit 8636a4b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ CHANGELOG
=========
All notable changes to this project will be documented in this file.

## [v3.1.3] - 2021-12-07
### Changed
Console: Improve column width, prevent most of table cuts depending on the width of the terminal.

## [v3.1.2] - 2021-11-23
### Changed
Bug fix: Command-line fatal error on NULL natural Condorcet winner / loser #72
Expand Down
2 changes: 1 addition & 1 deletion lib/Condorcet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class Condorcet
{

/////////// CONSTANTS ///////////
public const VERSION = '3.1.2';
public const VERSION = '3.1.3';

public const CONDORCET_BASIC_CLASS = Algo\Methods\CondorcetBasic::class;

Expand Down
14 changes: 11 additions & 3 deletions lib/Console/Commands/ElectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use \Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Terminal;
use Symfony\Component\Yaml\Yaml;

class ElectionCommand extends Command
Expand All @@ -42,8 +43,9 @@ class ElectionCommand extends Command
protected bool $pairwiseIsWrite = false;
public ?string $SQLitePath = null;

// TableFormat
// TableFormat & Terminal
protected TableStyle $centerPadTypeStyle;
protected Terminal $terminal;

protected function configure (): void
{
Expand Down Expand Up @@ -122,8 +124,9 @@ protected function configure (): void

protected function initialize (InputInterface $input, OutputInterface $output): void
{
// Initialize Style
// Initialize Style & Terminal
$this->centerPadTypeStyle = (new TableStyle())->setPadType(STR_PAD_BOTH);
$this->terminal = new Terminal;

// Setup Memory
if ($input->getOption('votes-per-mb') && ($NewVotesPerMB = (int) $input->getOption('votes-per-mb')) >= 1 ) :
Expand Down Expand Up @@ -321,8 +324,11 @@ protected function execute (InputInterface $input, OutputInterface $output): int
->setRows($this->formatResultTable($result))

->setColumnStyle(0,$this->centerPadTypeStyle)
->setColumnWidth(0, 20)

->setColumnWidth(0, 10)
->setColumnWidth(1, 20)
->setColumnMaxWidth(1, ($this->terminal->getWidth() - 20))

->render()
;

Expand Down Expand Up @@ -416,6 +422,8 @@ public function displayVotesList (OutputInterface $output): void
($votesTable = new Table($output))
->setHeaderTitle('Registered votes list')
->setHeaders(['Vote Num.', 'Vote', 'Vote Weight', 'Vote Tags'])

->setColumnMaxWidth(1, ($this->terminal->getWidth() - 50))
;

foreach ($this->election->getVotesValidUnderConstraintGenerator() as $voteKey => $oneVote) :
Expand Down

0 comments on commit 8636a4b

Please sign in to comment.