Comments (14)
Hi @branch14 ,
I don't plan to patch 1.7-stable branch anymore.
I couldn't reproduce the issue at 2.0 branch.
from highline.
@branch14 today we have officially released 2.0.0 version!
I'll close this issue, but feel free to reopen it if you think it's necessary.
Thank you very much for your feedback! 👍
from highline.
Thank you for your work on highline. I never tried the 2.0 branch, but now that it has been release I totally will. :)
from highline.
Thank you! I hope it work well. Give me a feedback as soon as you tested it 👍
from highline.
I tested it and unfortunately I found the same issue in 2.0.0
Luckily the work around still works. :)
Here is how to reproduce it:
#!/usr/bin/env ruby
require 'highline'
h = HighLine.new
h.ask("Default shows if it is a string: ", String) { |q| q.default = "I am a string" }
h.ask("Default doesn't show if it is an int: ", Integer) { |q| q.default = 42 }
h.ask("But strangely this works: ", Integer) { |q| q.default = "42" }
# % ruby test.rb
# Default shows if it is a string: |I am a string|
# Default doesn't show if it is an int:
# But strangely this works: |42|
from highline.
I've reopened the issue.
Could you clone the repo and run rake acceptance
and post the results here?
from highline.
It was correctly reproduced in my enviroment.
from highline.
In a quick look what I see is...
Default value is about the answer gathering part. We should always receive a string by keyboard, although we could have any kind of object as default. This could be useful for several scenarios by passing as default a more meaningful object than nil
.
That Integer
is more about coercion.
I can see that Highline is doing a type check at this part
def build_responses(message_source = answer_type)
append_default if [::String, Symbol].include? default.class
new_hash = build_responses_new_hash(message_source)
# Update our internal responses with the new hash
# generated from the message source
@internal_responses = @internal_responses.merge(new_hash)
end
I would prefer to just cast it into a String and check if it is empty or not (to avoid placing two bars side by side without any content inside it. Like ||).
But, any object in Ruby has a string representation by default. And, at that case that I pass bare object I could have the weird result like this:
"Question: |#<Object:0xXXXXXX>| "
From: TestHighLine#test_default_with_non_String_objects [/Users/abinoam/src/highline/test/test_highline.rb:834
So, perhaps sticking with the type checking thing, although not being the more flexible way, solves your problem without any great change at the behaviour of HighLine.
from highline.
I understand that inputs are always of type string and that the Integer is used for coercion.
I concur that "Question: |#<Object:0xXXXXXX>| "
seems weird. But at least it would follow PLOP. Whereas silently ignoring everything except Strings and Symbols violates PLOP.
Personally I would prefer "Garbage in, Garbage out", as it would have been obvuious that I need to pass something with a meaningful string representation.
With the current solution it took me a while to figure out that I had to cast the Integer to a String to make it work.
from highline.
I may agree with you. But this breaks the current behaviour. We can discuss this to come in a major release.
For now, I think we can ammend the type checking part adding Integer to the list.
This will solve for your specific case without any major break.
What do you think about this?
from highline.
Hi @branch14 what do you think about my last comment 👆
from highline.
from highline.
Hi @branch14
Sorry for taking so long.
I'll add the requested behavior at the same time adding a switch do disable it.
So people can easily transition between the to behaviors (showing or not showing the Question#default value hint).
Code is ready, opening a PR.
from highline.
I'll have to do a major release as this is a breaking change.
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
- 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.