What is the underlying library/program to programs like less or top - terminal

Programs like less, top, htop, git-log, man and also editors like vi, vim or nano all open in this well known sort of "window" in the terminal, that is different from the typical prompt you normally work with.
Example:
When using cat it simply prints out the results onto stdout and shows you the prompt again.
On the other hand, when using top it goes into this separate "window" to display the information and even update it dynamically. Obviously it isn't a window as we understand it today, it just seems to be a visual trick where they overwrite the entire terminal screen repeatedly. Still, I think the analogy fits.
I was wondering, what is the underlying library or program that is used here? What is the proper name for such a "window"?
I do know about libraries like ncurses, which do similar stuff to what I am talking about, but I cant find any reference that for example top is using this library specifically. Also it looks quite differently from screenshots I have seen - might just be configuration.

Related

How to open a file in multiple programs as my 'default program'

So I've got a lot of manual HTML checking to do, most of which is just a quick glance at the code and then make sure the page displays correctly.
My thought is that it would be much easier to do this if I could set multiple programs to open when I double click on a .htm file. By this I mean open the file in the programs I specify all at once without multiple "right-click > open with > the program" actions.
So really I'd like for it to open in my HTML editor, Chrome, and Firefox all at once and then I can just glance at them all and move about my business. I figure I'll still have to close all of them manually but at least I can do that every once in a while not EVERY time.
Any ideas? I was thinking about a simple man-in-the middle app to open all of the programs, but that seems like it would be a rather large solution to a small issue, is there a simple (and fairly quick-to-execute) way of doing this in a windows-based fashion, or should I just try and slim down this proposed app as much as possible and maybe it won't be too slow to open?
I was thinking about a simple man-in-the middle app to open all of the programs
That is exactly what you need. And then you can add that app to the "Open With" menu of the file extension(s) you want to process.
that seems like it would be a rather large solution to a small issue
Not really. It would actually be a very small app to implement. All you need is a configuration to specify the target apps, then receive the selected filename(s) as command-line parameters and pass them in a loop to the other apps using ShellExecute/Ex() or CreateProcess()as needed. Not much to it.
is there a simple (and fairly quick-to-execute) way of doing this in a windows-based fashion
Not really. You have to create your own app for it, and then register it so you can invoke it when needed.
should I just try and slim down this proposed app as much as possible and maybe it won't be too slow to open?
It won't be slow at all, unless you make it slow. If you really want to cut down overhead, you could even implement it as a simple .bat script that uses the start command to launch the files, instead of compiling an actual executable.
Looks like you would create something called a Shortcut Menu Handler. Beware, as that involves messing with the registry.

Remap keys in OS X

Specifically I'm attempting to map my MacBook's fn key to left mouse click.
Back in the old days when I was using Windows, I came across a wonderful little utility that let me map anything to anything: http://www.autohotkey.com/
You create a little text file, e.g.
^!s:: ; CTRL + ALT + s
Send Sincerely,{enter}John Smith ; sends keystrokes to active window
return
Creating a simple text file was infinitely better than any GUI based remapper.
I can look through it and see everything that is going on at a glance
I can customise every last detail
I can save / retrieve / post / share my scripts
Really, it's the one thing I really miss about Windows.
So my question is: How do I go about doing this in OS X? Every Google search leads to https://pqrs.org/macosx/keyremap4macbook/ and I dislike this package: it has an insanely cluttered GUI.
I would be very happy if I could do it in a shell script, or even compile code.
HotKeys on OS X
Even though AHK is seemingly absent on Mac, the functionality that AHK provides on Windows can likely be achieved in OS X. It could be a matter of coding your own solution, modifying something that's open-source, or using a combination of applications that will work together. I haven't tried all of the following, but might as well mention them as they might be worth checking out:
Open Source
IronAHK - .NET rewrite of AHK ported to OS X
AHK Forum Thread
Github Project
*the original project might be dead
CliClick - command-line application that will emulate mouse clicks
Github Project
Commercial
TextExpander - scriptable text completion / hotkey / macro app (supports AppleScript, Shell scripts)
Typinator - similar to TextExpander, although some features vary.
KeyMo - mostly for mapping keys exclusively to your mouse.
FastScripts - maps hotkeys/user-definable keyboard shortcuts to AppleScripts
*I use Text Expander and FastScripts together and can't live without them.
Rolling Your Own
It's fairly easy to create something with an AppleScript, or a shell script for just about anything imaginable in OS X. For example, I've seen CliClick used along with a custom AppleScript to achieve a certain functionality that it might not provide otherwise. To find an AHK replacement on Mac it'll probably be through trial and error, patience, and ultimately what ends up working best for you.
It is possible with a program called ControllerMate, instructions here. It is, however, a commercial software. I'm also interested in finding a free alternative.
Sikuli project looks promising. Not sure about your particular problem (e.g. Fn key remapping), but it's definitely a crossplatform alternative to AHK.
Another Open Source solution to this problem not mentioned in l'L'l's answer is Karabiner; I have been looking for a way to remap the key to the left of 1 to Esc for a while, and this worked perfectly. It even resolved an issue I was having where swapping Cmd and Alt using the built in OSX key remapping was breaking terminal Alt shortcuts! Highly recommend it.

Read content of cursor location in terminal/Shell

I'm working on a unique project using terminal/Shell but I've hit a little bit of a roadblock I haven't been able to work around.
I want to be able to read the content of the location of the cursor.
For example, if the cursor is currently located on line 2, column 5 which contains an E, I want to be able to read that E and create a variable with it.
Can you explain what your project entails? It might help if we knew what you're trying to accomplish.
No tools exist to do this in the shell, as far as I know. To actually read a remote screen would require this as a feature of the remote terminal (or emulator).
Neither do any compiled language support this. All applications that appear to do this fake it by keeping an internal copy of what they assume is displayed on the screen.
Lookup the curses* library for more information. This toolkit allows a programmer to address the screen as a random accessible grid, and hides all of the updates to the actual terminal screen.
See also: ncurses

Taking notes to a background text editor without switching windows

I am looking for a solution to a specific use case:
When I read something on my browser or pdf reader, I want to take notes without switching windows. I want to type right on my browser or pdf reader, but the typed text should go to the background text editor like notepad.
Is this possible?
Do you know any existing automation script that handles this use case?
You should create an application that uses some keylogger-like techniques (e.g. global hooks) to monitor the keypresses and, depending on some condition (a setting you may have set, the currenctly active window, ...), it may pass them normally to the application or suppress them to store them in a buffer. Such buffer, then, would be shown to the user as needed.
Still, in my opinion a much more convenient way to perform a similar task would be to create an application consisting of a semitransparent edit box, that could be shown and hide simply with a hotkey. This would avoid all the hooks stuff and the potential problems that may arise from them.
you might try using autohotkey scripting language... I can write a little script that would do exactly what you need and afaik in this particular case it wouldnt need keyboard hooks.
--EDIT--
Autohotkey is VERY simple to use/learn so even if you want to do the script yourself you can do it in a very short time even if you dont have any knowledge of ahk. Then again, I can help you with it.

Creating quick GUI front ends

I wanted to have a GUI front-end for a script that accepts numerous command-line options, most of them are UNIX paths. So I thought rather than typing them in (even with auto-completion) every time, I'd create a GUI front end which contains text boxes with buttons beside them, which when clicked will invoke the file browser dialogue. Later, I thought I'd extend this to other scripts which would sure require a different set of GUI elements. This made me think if there's any existing app that would let me create a GUI dialog, after parsing some kind of description of the items that I want that window should contain.
I know of programs like Zenity, but I think it's doesn't give me what I want. For example, if I were to use it for the first script, it'll end up flashing sequence of windows in succession rather than getting everything done from a single window.
So, basically I'm looking at some corss-platform program that lets me create a window from a text description, probably XML or the like. Please suggest.
Thanks
Jeenu
Mozilla's XUL is a cross platform application framework - . You could write an app as a Firefox plugin or a standalone XUL application.
mono and monodevelop could work for this. Or even something super simple like shoes.

Resources