What will give me something like ruby readline with a default value?

What you are asking is possible with Readline. There’s a callback where you can get control after the prompt is displayed and insert some text into the read buffer. This worked for me: Readline.pre_input_hook = -> do Readline.insert_text “hello.txt” Readline.redisplay # Remove the hook right away. Readline.pre_input_hook = nil end input = Readline.readline(“Filename: “, false) … Read more

equivalent of Console.ReadLine() in c++

You are looking for std::getline(). For example: #include <string> std::string str; std::getline(std::cin, str); I’ve little idea what you mean when you say I must also be able to store the value through a pointer. Update: Looking at your updated question, I can imagine what is happening. The code that reads the choice, i.e. the number … Read more

How do I use vi keys in ipython under *nix?

In case someone’s wandering in here recently, IPython 5.0 switched from readline to prompt_toolkit, so an updated answer to this question is to pass an option: $ ipython –TerminalInteractiveShell.editing_mode=vi … or to set it globally in the profile configuration (~/.ipython/profile_default/ipython_config.py; create it with ipython profile create if you don’t have it) with: c.TerminalInteractiveShell.editing_mode=”vi”

How to read utf16 text file to string in golang?

The latest version of golang.org/x/text/encoding/unicode makes it easier to do this because it includes unicode.BOMOverride, which will intelligently interpret the BOM. Here is ReadFileUTF16(), which is like os.ReadFile() but decodes UTF-16. package main import ( “bytes” “fmt” “io/ioutil” “log” “strings” “golang.org/x/text/encoding/unicode” “golang.org/x/text/transform” ) // Similar to ioutil.ReadFile() but decodes UTF-16. Useful when // reading data … Read more

Undo a file readline() operation so file-pointer is back in original state

You have to remember the position by calling file.tell() before the readline and then calling file.seek() to rewind. Something like: fp = open(‘myfile’) last_pos = fp.tell() line = fp.readline() while line != ”: if line == ‘SPECIAL’: fp.seek(last_pos) other_function(fp) break last_pos = fp.tell() line = fp.readline() I can’t recall if it is safe to call … Read more

How to fix column calculation in Python readline if using color prompt

I open info readline and found: — Function: int rl_expand_prompt (char *prompt) Expand any special character sequences in PROMPT and set up the local Readline prompt redisplay variables. This function is called by `readline()’. It may also be called to expand the primary prompt if the `rl_on_new_line_with_prompt()’ function or `rl_already_prompted’ variable is used. It returns … Read more

How to get synchronous readline, or “simulate” it using async, in nodejs?

Just in case someone stumbles upon here in future Node 11.7 added support for this using async await const readline = require(‘readline’); //const fileStream = fs.createReadStream(‘input.txt’); const rl = readline.createInterface({ input: process.stdin, //or fileStream output: process.stdout }); for await (const line of rl) { console.log(line) } Remember to wrap it in async function(){} otherwise you … Read more

Python REPL tab completion on MacOS

Apple does not ship GNU readline with OS X. It does ship BSD libedit which includes a readline compatibility interface. The system Pythons shipped by Apple and the 64-bit/32-bit Pythons from python.org installers are built with libedit. The problem is that the commands supported by libedit are completely different from those of readline (see for … Read more