Making string output to terminal undeletable in Ruby - ruby

I'm working on making a ruby cli project. Was trying to make a nice prompt to user just like the once we see in windows and Linux terminals like
ruby-docs>>
using print works fine but the line printed can be deleted by user, is there any way to freeze this line so it can't be modified when printed to terminal

Related

Run Shell Commands in iPython in Windows

I am following the example code from the book "Python Data Science Handbook", and it asked me to type ! to type the shell commands in iPython, however as I was trying to follow along in my Windows laptop this just didn't work. Here's the example code.example code
I have also tried to enter the shell command without having the "!" in the front, but even though it can print the current working directory, I cannot assign the directory to the left hand variable. Could someone tell me how to use this in Windows?

Fish shell startup command prints � characters on Hyper

I have the following problem with the fish shell on my mac. I recently figured how to modify the ~/.config/fish/config.fish to automatically run a command upon starting the terminal.
Now, I want to run a particular script that prints some ASCII art, and it works just fine on the regular terminal app (so it shouldn't be a problem with fish or the script, I think) but prints only the � character in the Hyper terminal (Hyper.is). Now the trick is, if I just run the script in the shell, it works just fine.
My question is ; does anyone know why it doesn't work when launched on startup by fish, but works fine when I launch it ?
Solved the problem - I added a very small delay to the script before printing the ASCII art, and now everything works. I think it may be because executing this immediately upon launching of Hyper messed up with a plugin I used (I'm thinking about the hyper full plugin)

Rubyinstaller for Windows - ruby does nothing

I've tried using Ruby 2.0 x64 and Ruby 1.9.3 for Windows using RubyInstaller. Entering ruby -v works as expected, and running gem gives me the expected usage docs. Running and using the Interactive Ruby application works as expected. I am running Windows 8.1 Update.
However, for both installations, running ruby from cmd gives me a blank prompt where I can type, but nothing is executed when I press enter. If I attempt to install a gem, there is a similar issue where the program is running, but there is absolutely no output, and nothing happens.
I can't seem to be able to find a similar issue elsewhere. Does anyone know what might be wrong, and how I could fix it?
What did you expect to happen? ruby.exe is the ruby interpreter, meant for running ruby scripts. Normally, to use it you would create a file containing valid ruby commands with your favorite text editor (but not a word processor). If you save the file as foobar.rb, typing ruby foobar.rb (or if you told the installer to associate .rb files with ruby, typing just foobar.rb) will execute the commands in the file as a script/program. If you don't supply a script file name, ruby goes into input mode and expects you to type in a program on the spot. It won't give any feedback until you indicate end-of-file by typing CTRL-z, at which point it will process what you typed and most likely tell you about all the errors you made. If you want line-by-line interactive feedback, use irb.

How to disable stdin echo in windows console

I'm writting a Ruby program for windows, and I need to read user input from keyboard (stdin).
However, it's needed that the user key-presses are not automatically displayed in the windows console, and behave like "silent key presses"
This problem in Ruby over linux, can be solved using the "stty" linux command:
%x{stty -icanon -echo}
because it is the linux terminal who automatically outputs the user-keys into the terminal, so running the "stty" command tells the terminal to stop showing the user-key-presses.
But my program must run in windows, so I tried searching for a "stty" equivalent command for windows console, but still found nip...
?any suggestions, pointers ?
Look at Highline gem. To clarify, look at ask method and provide a block to silence it's output. It is well exemplified in their documentation

Start script on login

I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).
There's an option to add applications etc that need to start at login, you could try writing a shell script or an apple script thing that launches terminal and runs ruby my_ruby_script.rb, or possibly even just add my_ruby_script.rb to this list after adding a #!/bin/env ruby line to the top of that file. http://support.apple.com/kb/HT2602?viewlocale=en_US gives precise instructions as to how to add an application to be started at login.
If you need to use AppleScript to actually start a terminal application (I believe this is not the case, but I am not in front of my mac now and hence can't test), just create an applescript file with something like
do shell script "ruby <path>/my_ruby_script.rb"
Hope this helps
As Panda said, add:
#!/bin/env ruby
to the begining of the file, and then you could add a reference to your file inside ~/.bashrc or ~/.profile or even /etc/profile , depending on your needs.
Check this out: https://stackoverflow.com/questions/3484429/profile-and-bashrc-doesnt-work-on-my-mac/3484472#3484472

Resources