Something like getch(), textcolor() and gotoxy() in Ruby - ruby

I want to use these functions from the conio.c library (Borland) in Ruby, specially getch().
getch() gets a key from the keyboard without press enter.
textcolor() changes the color of the text in the terminal.
gotoxy() moves the cursor to other position of the terminal.
Someone knows the equivalents?
Thanks.

On ruby-forum I found a discussion about this, see Ncurses like library. There are both Ncurses and Curses. Not sure if there are other libs.

Related

how do I control where text is printed to console via fmt?

When running vim if I type : the input cursor goes to bottom row of the screen and I can type a command, then go back to the top of the screen. Arrow keys let me move around, all that jazz. In Golang using the fmt package how can I do this?
I think you're kind of confused. What fmt is essentially equivalent to are C's printf and scanf family of functions. The complexity of controlling the screen buffer is quite a bit more complex than just printing some stuff in a terminal output.
The behavior you're talking about is a result of vim's integration with the ncurses library (or something similar to it). Haven't ever used this, but here's a link to an ncurses wrapper in cgo, which you could probably use to do something like vim does.

Using Alt Key in FakeVim mode of Qt Creator?

It's really handy when you work with VIM text editor to use Alt key to execute normal mode commands in insert mode, for example when you are in insert mode you can press Alt + j to go one line down. But in FakeVim mode of Qt creator this couldn't be done. Any suggestion is welcome.
Pressing Esc each time you want to go to normal mode really sucks.
(not a fix to your problem, just discussing it in a properly formatted text)
I never hit <ESC> as well, and this is a deal breaker for me. Note that it's not a vim feature, though : this behavior occurs because using Alt with an other key in terminals generates an escape sequence. So there's nothing wrong with FakeVim regarding Alt implementation, the problem is related to the IDE being a QT window. You can't use Alt sequence in GTK's Gvim as well, for the same reason, last time I checked.
A possible easy fix on the QCreator part : provide an option to not pass Alt combinations, like the one existing for Ctrl. That is, if QT allows that. We could then at the very least define vim bindings using Alt key to simulate the terminal behavior.
In the list of others exotic combinations from terminals that quickly lead to form habits in vim, I also use C-j in place of <return>, and C-h instead of <backspace>. Those would really be nice to have too :)

Lightweight event wrapper for the terminal

I believe this is the realm of the ncurses library. I'm trying to avoid having to get down and dirty with it though.
I'm looking for a program that I can configure to run a command while performing terminal mouse reporting translation to keypresses.
This is for use with pagers like less.
For example the MouseTerm SIMBL plugin for Terminal.app does exactly this.
But iTerm2 does not. And I want it.
I think the answer may be as simple as directly remapping the codes.
It looks like there are escape codes to switch the terminal into and out of mouse-listening mode, and mouse click escape codes actually seem to include the character coordinates. I can look at them with Ctrl+V inside of Vim because I have told vim to turn on the mouse.
It looks like this:
Note ^[ denotes escape (you can type escape by typing ctrl+[)
left click: ^[[M !!
right click: ^[[M"!!
middle click: ^[[M!!!
scroll up: ^[[M`!!
scroll down: ^[[Ma!!
So that does match up with the mouse wheel button codes being 64 more than the mouse button ones according to documentation (I like this page).
Now that I'm armed with the knowledge of what codes I need to map to what I just need to find out how to get a layer that lets me filter the input.
This has apparently led me to an epiphany. I simply need a simple non-line-buffering program that listens for mouse escape codes and replaces them with key codes. Surely Perl Term::ReadKey will let me set raw mode and do this nearly trivial task.
This stuff is difficult. I've been making do by configuring Tmux to handle things.

Prefered keystroke for ending NSTextView edit

Is there prefered keystroke for ending edit of an NSTextVIew? Obvious candidates are ESCape and Return with modifier key. I'd like this to be fairly intuitive and easy to type. Of course for people raised on Vim, Escape is the obvious choice.
Since I mentioned Vim, I thought I'd add my emacsish version:
For emacs I guess it might be C-x C-S. I would find this more convenient typing than ESC. But what would be the cocoa way?
Command+return is quite common for confirming multi-line input (this is used for example in Apple's iWork when editing a text frame).
In standard Cocoa text views, Esc triggers auto-completion suggestions (when applicable).
tab is the most popular to switch between different textfields and textviews and is considered as end of editing.
Also you can use any combination as per your likings, e.g. cmd+enter etc to move out of the textView.
But no to esc, it sends as something you are cancelling. However this is used in CUI as vim, but surely not in GUI for OSX and even for Windows.

How Do ncurses et. al. Work?

There are several libraries like ncurses that assist in making command-line GUIs.
Simply put, how do they work?
My first thought was that ncurses intercepts all keyboard input, and draws each "frame" by outputting it line-by-line normally. Closer inspection, however, reveals that each new frame overwrites the previous one. How does it modify lines that have already been outputted? Furthermore, how does it handle color?
EDIT: The same question applies to anything with a "fancy" interface, like vim and emacs.
Text terminals have command sequences that do things like move the cursor to a particular position on the screen, insert characters, delete lines etc.
Each terminal type is different and has its own set of command sequences. ncurses has a databse (see terminfo for details)
Internally ncurses maintains 2 views of the screen: the current contents and what the screen should look like after the current pending changes are applied. Once the program requests a screen redraw, ncurses calculates an efficient way to update the screen to look like the desired view. The exact characters/command sequences output depend on what terminal type is in use.
curses (and ncurses, too, I think) works by moving the cursor around on the screen. There are control sequences to do such things. Take a look at the code again and you'll see them. These sequences are not ASCII control characters, they are strings starting with (umm...) ESC, maybe. Have a look here for a higher-level explanation.

Resources