Matthew Wild
a669ffb5a2
util.human.io: Don't accept ambiguous durations by default
...
The new method parse_duration_lax() exports the old behaviour, mainly for
compatibility purposes.
2 years ago
Kim Alvefur
c222b08005
util.human.io: Fix stray 'stty' error by only querying width of real ttys
...
This adds a dependency on a binary and *nix-specific module but then
stty is probably *nix-specific anyway so maybe that's fine.
3 years ago
Kim Alvefur
bb760b1363
util.human.io: Fix pattern in parse_duration() to cover all used letters
...
Notably 'h' was missing. Awkwardly, 'hour' would result in 'ho' which
was missing from table.
3 years ago
Kim Alvefur
06450fb65b
util.human.io: Fix column width miscalculation
...
Fixes that the more fixed width columns there are, the narrower the
resulting table becomes. A right-aligned variable-width column at the
last position should always be flush to the right side of the terminal.
3 years ago
Kim Alvefur
7100d58828
util.human.io: Fix error with ellipsis to negative length
...
Can happen if you resize the terminal too narrow that the space left for
variable width columns end up negative.
3 years ago
Matthew Wild
7dc9f9ab2a
util.human.io: Add parse_duration() method to parse a duration string
...
Similar logic occurs throughout various modules in the codebase. We might even
want a module:get_option_duration()??
3 years ago
Kim Alvefur
d458a42c61
util.human.io: Coerce $COLUMNS to number
...
os.getenv() returns a string but term_width() should return a number
3 years ago
Matthew Wild
7153f4e40a
util.human.io: table: don't read $COLUMNS directly, just use term_width()
...
...which now reads $COLUMNS for us and does the right thing.
3 years ago
Matthew Wild
f842e05e95
util.human.io: table: Return determined width as a second result
...
This allows callers to adjust other things based on the width of the rows
(such as header lines).
3 years ago
Kim Alvefur
9760019a25
util.human.io: Prefer using the $COLUMNS environment variable if set (by readline)
...
Feels like it should be faster.
3 years ago
Matthew Wild
b5ff6256b6
util.human.io: table: use term_width() to discover terminal width
3 years ago
Matthew Wild
403acbb836
util.human.io: Add term_width() method to discover the terminal width
...
This is not standard POSIX, but apparently very widely supported. For
reference: https://www.austingroupbugs.net/view.php?id=1053
3 years ago
Kim Alvefur
08c0557093
util.human.io: Pass the whole column definition to mapper function
...
I forget why I wanted this, but it may allow doing things like pull
settings from the column, especially when the mapper function is reused
among many columns.
3 years ago
Kim Alvefur
41be222478
util.human.io: Allow defining per column ellipsis function
...
As an alternative to doing it in the mapper function. Could be useful in
cases where one may want to put the ellipsis in the middle or beginning
instead of the start.
3 years ago
Kim Alvefur
8b33e79fdb
util.human.io: Pass expected width to mapper function
...
In order to allow it to adjust its output to available space, apply its
own ellipsis method or other compacting method.
3 years ago
Matthew Wild
7e50781f51
util.human.io: Fix pattern to support fractional proportions
3 years ago
Matthew Wild
bc7277bd01
util.human.io: Support for dynamic "proportional" columns
...
Instead of a percentage, this allows you to specify e.g. `width="[N]p"`, where
a width="2p" will be twice the width of a width="1p" column.
Compatibility with the old %-based widths is preserved, and percentages adding
up to more than 100 are handled more gracefully.
3 years ago
Kim Alvefur
43531740f9
util: Prefix module imports with prosody namespace
3 years ago
Kim Alvefur
1acd5e0474
util.human.io: Fix handling of os.execute() return values in Lua 5.2+
...
Wrong part of Lua 5.1 compat removed in 0f4feaf9ca64
3 years ago
Kim Alvefur
49a9a1e76a
util: Remove various Lua 5.1 compatibility hacks
...
Part of #1600
4 years ago
Kim Alvefur
d6b3625be2
util.human.io: Use UTF-8-aware length check in padding functions
4 years ago
Kim Alvefur
d1144a7ede
util.human.io: Fix cutting of UTF-8 into pieces
...
Down the rabbit hole we go...
4 years ago
Kim Alvefur
b9837e2d99
util.human.io: Trim any broken UTF-8 from ellipsis
...
This should fix basic problems with multi-byte UTF-8 sequences getting
cut in the middle.
Down the rabbit hole we go...
4 years ago
Kim Alvefur
f8afa0807b
util.human.io: Factor out ellipsis function
...
Could be useful elsewhere
4 years ago
Kim Alvefur
e162a73d73
util.human.io: Support specifying column defaults in tables
4 years ago
Kim Alvefur
c9479cbb69
util.human.io: Pass nil to cell mapper to signal missing value
...
Seems more like conventional Lua than passing an empty string to signal
lack of value.
4 years ago
Kim Alvefur
4a0cb5a306
util.human.io: Fix right-alignment
6 years ago
Kim Alvefur
9b70ffb0ca
util.human.io.table: Allow a map callaback per column
...
This allows e.g. mapping booleans to "yes" or "no", specific number
formatting or generating virtual columns. All while not mutating the
underlying data or creating additional temporary tables.
6 years ago
Kim Alvefur
4e554bc4d1
util.human.io: Consider separator when calculating remaining width
6 years ago
Kim Alvefur
87777b26af
util.human.io: Use literal ellipsis instead of \u escape
...
For compat with Lua 5.2 and before
6 years ago
Kim Alvefur
435cd19373
util.human.io: Replace overflow with ellipsis
6 years ago
Kim Alvefur
ad3d047685
util.human.io: Draw a separator between columns
6 years ago
Matthew Wild
1b30a8e979
util.human.io: Remove padding option and use $COLUMNS as default width
6 years ago
Matthew Wild
19b7e38e1c
util.human.io: table: Fix title printing when columns use named keys
6 years ago
Matthew Wild
7b7084ad68
util.human.io: table: Return title row when no row data passed
6 years ago
Matthew Wild
8467f4f9ea
util.human.io: table: switch row function to simply returning prepared row string
6 years ago
Matthew Wild
baf9f5aeef
util.human.io: Add padleft, padright and a table printing function
6 years ago
Matthew Wild
01f780eef1
util.human.io: Fix variable name [luacheck]
6 years ago
Matthew Wild
e2b8325088
util.human.io: New central place for UI helpers
6 years ago