Skip to content

Commit

Permalink
strings.tables: right-align cells if contents are starting with a digit
Browse files Browse the repository at this point in the history
This should work great for the cells that contain numerical data. The patch
is submitted by @mrjbq7 in GitHub issue factor#1840.
  • Loading branch information
alex-ilin committed Apr 13, 2020
1 parent 98b039d commit b6f33e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ are swapped compared to the original Factor implementation. I think my
version makes the usage simpler, requiring less stack shuffling for typical
usage, but the upstream developers decided they don't want to break
compatibility by introducing this change;
* a patch for strings.tables suggested by @mrjbq7 in issue
[1840](https://github.com/factor/factor/issues/1840) is applied, so now the
table cells containing numeric data are right-aligned;
* other changes may be developed and contributed to upstream when ready,
but the ones listed above represent either things not meant for general
distribution or things already rejected.
Expand Down
9 changes: 7 additions & 2 deletions basis/strings/tables/tables.factor
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
! Copyright (C) 2009, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences fry math.order math.ranges splitting ;
USING: ascii fry kernel math.order math.ranges sequences
splitting ;
IN: strings.tables

<PRIVATE

: format-row ( seq -- seq )
dup longest length '[ _ "" pad-tail ] map! ;

: pad-column ( str n -- str' )
CHAR: \s pick ?first [ digit? ] [ f ] if*
[ pad-head ] [ pad-tail ] if ;

: format-column ( seq -- seq )
dup longest length '[ _ CHAR: \s pad-tail ] map! ;
dup longest length '[ _ pad-column ] map! ;

PRIVATE>

Expand Down

0 comments on commit b6f33e0

Please sign in to comment.