Comments (5)
Dear @ngw,
Thank you for reporting the issue, we really appreciate it.
You're using version 1.7.8.
Line 45 of lib/highline/simulate.rb
is:
$terminal.instance_variable_set :@input, @input
The message error is RuntimeError: can't modify frozen NilClass
I guess $terminal
global variable is not set when instance_variable_set
is called (for the context you're giving).
So, if $terminal
is nil
then calling instance_variable_set
on it will trigger this can't modify frozen NilClass
error message.
But, the fragment highline.ask(Cobain::Settings::OPTIONS[setting])
may also be problematic as highline
should be equal to $terminal
for HighLine::Simulate.with
to work well.
I was able to set a small snippet to show what I think could be the cause.
require 'highline/simulate'
HighLine::Simulate.with("foo", "bar") { 2.times { puts ask "Say it again" } }
# => RuntimeError: can't modify frozen NilClass
# Now we require 'highline/import' that sets $terminal to a HighLine instance.
# The same line now will work as expected
require 'highline/import'
HighLine::Simulate.with("foo", "bar") { 2.times { puts ask "Say it again" } }
# => Work well
# And it works the same if using `$terminal.ask`
HighLine::Simulate.with("foo", "bar") { 2.times { puts $terminal.ask "Say it again" } }
# => Work well
# But if I create my own HighLine instance, it won't work as expected.
highline = HighLine.new
HighLine::Simulate.with("foo", "bar") { 2.times { puts highline.ask "Say it again" } }
# => It fails
So, my suggestions are:
- Use 'require highline/import' to make sure it correctly sets
$terminal
global var - Just use
ask
instead ofhighline.ask
.
I may agree that this behaviour is weird. We are slowling deprecating this global variable thing. You can se by the docs that we favor using cli = HighLine.new
and cli.ask
flow for the 2.0.0-pre versions.
But, we haven't refactored the HighLine::Simulate class. I'll put this on my priority list.
Please, give us some feedback if you could make your tests pass with the above informations. And feel free to ask any futher question.
from highline.
Unfortunately Thor already has an .ask method: https://github.com/erikhuda/thor/blob/master/lib/thor/shell/basic.rb#L72-L81
Tomorrow I'll try your suggestions and report here what I find out, thanks a lot.
from highline.
Name collisions like this made us rethink the way we have been messing with global namespace. Unfortunately we haven't made all changes we would like to make.
I think there's a better workaround then.
require 'highline'
require 'highline/simulate'
simulator = HighLine::Simulate.new(["foo", "bar"])
cli = HighLine.new(simulator) # Sets HighLine input to the simulator instance
2.times { puts cli.ask "Asking something to the simulator" }
from highline.
It actually worked, I only had to mock HighLine.new to return the new simulator instance.
Some docs about testing would really be useful I guess.
from highline.
I'll close the issue. Feel free to reopen it if you want to add any information. Thanks for contributing opening the issue and discussing it.
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.