Comments (13)
That sounds right to me. Please prepare a patch and I'll take a look at it.
from highline.
That said, I think the old behavior does have some merit. Perhaps we could have an option to go either way?
from highline.
Can you come up with an example where the old behavior would be preferable? I'm sure one exists just at a loss for it right now, especially if we have a padding option.
from highline.
The current behavior would be preferable when the columns have similar max element widths. In that case, having columns with widths of [8, 9, 7, 9, 7, 8]
might be a little distracting, while forcing the widths to [9, 9, 9, 9, 9, 9]
might be less distracting.
However, where the columns have rather different max element widths - [8, 36, 1, 1, 10]
- it is better to keep the widths rather than to force them to [36, 36, 36, 36, 36]
.
from highline.
The example of [8, 36, 1, 1, 10]
is based on a real-world example from the knife-rackspace
gem for the command knife rackspace server list
(the ui
method returns a HighLine
instance).
from highline.
Yeah, I think it's mostly taste. I fine the equal widths easier to grok quickly. Also, if it was numerical spreadsheet like data, lining up the numbers might look more natural.
from highline.
Taste plays a big factor. But what tends to happen in my example is that, because one column is wide (30+ characters wide, multiple times wider than any other column) and the rest are narrow, each line of the grid wraps around and fills up its own line plus half of the next line in the terminal.
My terminal window is decently wide. But this makes the grid unreadable anyway. Not because there's too much data to fit in the grid, but because the grid is so sparse - because one column is multiple times wider than any other column, making every column in the grid display equally wide. I've got multiple columns which should be two characters wide each actually taking up 30-40 characters of screen real-estate simply because one of the columns is that wide.
It's taste up until it forces a sparse grid to wrap.
from highline.
I totally agree with Greg, there's no reason we shouldn't patch it. I'm just suggesting we, go the distance. With one simple if, we can have it both ways, right?
from highline.
Having it both ways, controlled by an option of some kind, would be fantastic.
That way, the default strategy for most programs would be to continue to assume the current behavior.
But programs such as knife rackspace server list
that know their grid columns can have highly variable widths can customize the behavior to suit.
Best of both worlds.
from highline.
Agreed. It's an easy patch. Can you put it together for us?
from highline.
I added :uneven_columns_across
and :uneven_columns_down
as modes for list()
.
from highline.
This patch seems to work fine in the usual case.
ruby-1.9.2-p180 :007 > a = %w(Blah a b c ad e fs f g)
=> ["Blah", "a", "b", "c", "ad", "e", "fs", "f", "g"]
ruby-1.9.2-p180 :008 > puts ui.list(a, :uneven_columns_across, 3)
Blah a b
c ad e
fs f g
=> nil
However, when there's bold formatting on the first row, it doesn't seem to work right:
ruby-1.9.2-p180 :009 > a = [ui.color("Blah", :bold), ui.color("a", :bold), ui.color("b", :bold), "c", "ad", "e", "fs", "f", "g"]
=> ["\e[1mBlah\e[0m", "\e[1ma\e[0m", "\e[1mb\e[0m", "c", "ad", "e", "fs", "f", "g"]
ruby-1.9.2-p180 :010 > puts ui.list(a, :uneven_columns_across, 3)
Blah a b
c ad e
fs f g
=> nil
from highline.
One specific use case for this issue is the knife-rackspace
library. Example.
from highline.
Related Issues (20)
- Docs not on RubyDoc.info as README states HOT 2
- Proc validation displays ruby object on invalid HOT 8
- Incosistent behavior when ask with a validator and readline=true HOT 9
- undefined method 'default_instance' HOT 3
- Default Highline Example on GithubGives Error HOT 5
- HighLine Terminal::IOConsole#restore_mode does not work with StringIO HOT 3
- System extensions depend on now-internalized JRuby dependencies HOT 14
- consider exposing Readline.completion_proc via HighLine::Question#selection HOT 3
- default value has to be a string HOT 14
- Ctrl-C improperly handled when q.echo = false HOT 6
- Issues with echo: false and not on TTY HOT 7
- Can't get terminal_size HOT 11
- echo=false or echo='*' requires extra character after enter on Windows HOT 6
- Possible to accept multiple selections with `.in` and `.default`? HOT 5
- test failing when ruby is built against libedit instead of readline HOT 3
- Have to set convert type in order for `.in` to work with array
- 2.1.0 was released, but tag is missing in repository HOT 2
- Make Highline Ruby 3.3 and reline compatible HOT 1
- Update tests for Reline (as the substitute of Readline)
- Add `abbrev` to gemspec HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from highline.