How to get Mouse support for dtterm terminal in solaris - terminal

When i run vim inside screen, with TERM set to dtterm, there is no mouse support. How do i enable mouse support for dtterm TERMINAL.
Running TERM with xtermc is not feasible as this garbles the background color in vim when running inside screen.

There is more than one problem:
xtermc does not match any terminal that you are likely to encounter (noted in xterm FAQ What $TERM should I use?
dtterm does not match xtermc either (use infocmp xtermc dtterm to see).
Sun stopped providing up-to-date terminal entries about 20 years ago. Perhaps the last change was related to dtterm. At the time, their /etc/termcap file had an incorrectly-formatted entry for dtterm.
dtterm does not support xterm-style mouse functionality. As I recall it, the mindset of its developers was that no one used it. So all you can get is GUI-style (non-programmatic) mouse select/paste.
dtterm does attempt to emulate VT220 (which had no mouse), but has some problems in that (a bug in scrolling).
ncurses has an improved terminal description for dtterm, but that bug in scrolling cannot be described in terminfo (other than pretending that dtterm cannot scroll).
dtterm was part of CDE, which Sun deprecated as of Solaris 10. Oracle still provides documentation. Earlier, they dropped OpenWindows in favor of CDE (see transition guide).
the escape sequences manual for dtterm does not mention "mouse".
So: you should set TERM to dtterm if you are using that program. vim will not know anything about its mouse capabilities.

Related

Customize word boundaries of Option-Delete (and other word related shortcuts) in macOS?

Is it possible to change the behavior of ⌥⌫ (option+delete) to include certain characters, like a period, as a word boundary?
For example, in some.variable, I would like ⌥⌫ to delete up to the period but it currently deletes the entire string. The screencast below shows the behavior using ⌥⇧←.
Screencast GIF
I've looked high and low for a solution to this issue since the Cocoa-era, as far as I can tell there isn't a way to customize the "Option-Delete" word-delimiter (word-boundary) list. In addition to my own experiments, I'm basing this conclusion largely on the enormous number of MacOS keybinding modifications that can be found at the following 3 URLs (from oldest to most recently updated):
Customizing the Cocoa Text System (circa 2006)
DefaultKeybinding.dict (circa 2016, some info previously at the URL "lri.me")
Keybindings -- BrettTerpstra.com (last updated 2018)
AFAIK, word-boundaries on MacOS default to whitespace and can't be changed. [This conclusion is invalid if there have been recent radical changes to MacOS text-input system].
It's no secret that many of the MacOS keyboard shortcuts are based upon eMacs-style 'keyboard-chording', as opposed to Vim-style 'modal-editing'. Indeed much of the Keybinding work cited above deals with remapping these chords. Vim of course is well-known for having a customizable delimiter list, it's the basis for differential word-movements between (for example) w, W and b and B (see vimhelp.org).
There have been a few extensions that have tried to bring 'Vim-style' editing to the MacOS, one of which is Karabiner. Karabiner (now re-written/updated to Karabiner-Elements) used to have a mode called "Ubiquitous_Vim". However without an OS-level 'hook' personal tests indicate that (for example) moving backwards via b and B works identically (i.e. there's no difference between a Vim word and a Vim WORD, see this StackOverflow post).
While I'm unable to find a way to modify the MacOS default 'word-boundary' list, if Vim-style editing does appeal to you, then you might try installing a project such as Vim-Anywhere, which enables you to 1. use a MacOS keyboard shortcut to open a Vim window whenever you need to enter text, and 2. will automatically copy your text to the MacOS System Clipboard when you close the Vim window. See this OSTechNix article: "How To Use Vim Editor To Input Text Anywhere" for more information.

How can I set tmux vi-mode highlight color

Looking for a way to control text/cursor highlighting colors when in vi-mode in tmux. I can not seem to find many answers from googling around. I love tmux and use this feature quite a bit, and I have been living with this flaw for some time and still have not been able to find a solution. You can view my dotfiles here. Keep in mind that my master branch is my OSX setup, and I have an "arch" branch for my Arch linux setup. The issues occurs on both systems. Though the colors are slightly different, but not by much.
Here is current symptoms: (both systems) I am in a tmux session, I want to enter into vi-mode for either searching or copying some text. When copying text (hitting v while in vi-mode for visual) the highlighted text and background are both black. So I can't see the text I am highlighting. Or while searching (hit "/" while in vi-mode for searching) my background and text on the entire line where my prompt is for typing the text I want to search is all black. So I have no idea what text is actually in the search. If I mis-type something due to fat fingers and nothing returns in my search, it can be frustrating. One last symptom (which is a minor one, but would be nice to solve) When I do search, I get absolutely no highlighting over than my normal cursor. Not like my vim set up where it highlights currently found, and all other matches.
Here is what the desired fix would look like: Searches would highlight in some shade of yellow or orange on all matched text. Searching prompt to type in search text would be at least readable. Anything but Black on Black. Highlighting text while selecting what to copy in visual mode again anything readable, no Black on Black.
Other things to note: I typically have mouse-mode on in tmux to promote keyboard-driven approach and not allow any selection of text via mouse selection. But when I do toggle this feature off and can then select text via mouse, the highlighted text background is white and text is black. While readable, would still wish to know how to control this color as well. Also (not sure any vim settings actually carry over to tmux) but everything works as desired while actually in vim. Just in case vim settings here. Same note about branches.
Most of my tools are latest versions afaik. This includes Tmux 2.1. I do not have full list of versions of my tools as of right now. If this may play a part in debugging let me know and I'll reply with versions. For what its worth other tools that might be in conflict is my shell I use zsh with on-my-zsh. On my mac I am using iTerm2, on arch I'm using URxvt. Doubt any of my .Xresources matter since it also happens on OSX.
Any help is greatly appreciated. Thanks in advance.

how to get current terminal color pair in bash

I would like to query and store the current terminal color pair in BASH e.g.:
#!/bin/bash
#some ANSI colour escape sequences
red="\033[0;31m"
grn="\033[0;32m"
blu="\033[0;34m"
def="\033[0;00m" # default
echo -e "Change to ${red} red to ${def} default to ${blu} blue."
# now store the current color (which happens to be blue) e.g.:
cur=????
echo -e "Change to ${grn} green and back to what I had before ${cur}"
echo -e "This would be in blue if variable cur contained e.g.: 0;34m."
echo -e "Back to default${def}"
exit 0
The answer that eludes me is how to capture the current color
cur=????
The question was about the current color, not the cursor position.
Both are "nonstandard" (though the latter, cursor position report is implemented by anything which has a valid claim to "VT100 emulator").
However, xterm implements a set of escape sequences referred to as dynamic colors, which predate the ANSI color functionality. Those set the working colors including text foreground and background. I modified this in 2002 to allow an application to send the sequence with a "?" rather than a color to tell xterm to return the color value, e.g.,
OSC 1 1 ? ST
using the notation given in XTerm Control Sequences
You can't; there is no standard control sequence to report the current cursor attributes.
What does exist, however, is a sequence to save and restore the current cursor position and attributes:
\e7 (DECSC) will save the cursor position and attributes.
\e8 (DECRC) will restore the saved cursor position and attributes.
There is no standard way to restore only the cursor attributes; however, as rici mentioned, you can get a report of the current position using \e[6n (DSR), then use the response to manually "un-restore" the cursor position after restoring its position and attributes.
Again, though, it's probably easier (and better) to just keep track of the colors in your application, rather than making the terminal responsible for that.
It's important to understand that the terminal state has nothing to do with bash. Bash doesn't care. It simply reads from stdin and writes to stdout and stderr. (See Note 1)
All terminal effects are implemented by the terminal emulator you happen to be using, of which there are many. In a graphical environment, you might be using, for example, xterm or konsole. You'll need to search the documentation for those emulators for specific terminal control codes which they interpret.
As far as I know, there is no standard code to get a report of the current terminal state, other than the cursor position (ESC[6n).
So your best bet is to remember the changes you made when you make them.
You can find a list of the standard codes implemented by the Linux console using man console_codes (although few people use the Linux console these days); most of those are also interpreted by xterm and other graphical consoles. There's an list of xterm sequences in Thomas Dickey's xterm site; it's a more or less de facto standard for terminal emulators but, as I said, you'll need to search in each emulator's documentation for idiosyncratic control sequences.
Notes
In interactive mode, bash uses a library called readline to help it handle some terminal effects. In particular, readline tries to maintain the current console cursor position, although it is easy to fool it. In PS1 you need to surround console control sequences with \[ and \] precisely because readline does not know that they are control sequences.
What I understood, is that u are asking to to get the default profile color of the user, of which u have change color of!
Eg: User is using 'Bright Green font color on Black background', you change it to 'Red font color on White background'. Now how to get/know the default colors and set them back to it!
You can use the sequence \033[0m in bash [also for command prompt (batch scripting) / powershell (ps scripting)]

Unable to turn off automatic margins by termcap in Mac

I need to turn automatic margins off according the following statement from Screen's manual in my Mac
If your terminal is a "true"
auto-margin terminal (it doesn't allow
the last position on the screen
to be updated without scrolling the screen) consider using a version
of your terminal's termcap that
has automatic margins turned off.
How can you turn automatic margins off by your terminal's termcap?
Most terminal emulators, including the mac default terminal, are not "true auto-margin terminals" in the sense being discussed here - they emulate a vt100-series terminal, which had "smart" wraparound. You can check by running cat and typing to the end of the last line - after you type the last character, the cursor remains at the end of the line (highlighting the character you just typed) until you type another character.
The only consequence of a 'true auto-margin terminal' is that a character cannot be displayed in the lower right hand corner (though some programs are able to work around that by shifting a character into place with ich/ich1)
According to XTerm Control Sequences, this sequence should do what was asked:
CSI ? 7 l
That is,
printf '\033[?7l'
The 7 is documented as
Ps = 7 -> Wraparound Mode (DECAWM).
and the final character l (lowercase L) denotes this as a reset rather than a set control.
For whatever reason, the terminfo name for this is more obscure: "automatic margins". These terminfo capabilities deal with the feature (see terminfo(5)):
auto_right_margin am am terminal has auto‐
matic margins
enter_am_mode smam SA turn on automatic
margins
exit_am_mode rmam RA turn off automatic
margins
Interestingly, the vt100-nam terminal description in ncurses (which apparently no one uses) initializes the terminal to use automargins margins using this string:
rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h,
(the \E[?7h sets it), and asserts that the terminal does not use automatic margins by cancelling am. It also has the terminfo capabilities rmam and smam. So you could do this to prove that it works:
tput rmam
stty columns 999
ps -efwwwwwl
and (for the ordinary user) see the ps listing nicely truncated against the right margin of the terminal window.
The other variants vt220-nam and vt320-nam appear correct...
By the way, for Mac, you would use the terminfo names such as rmcup rather than the termcap RA, because OSX uses ncurses' tput (terminfo) rather than the BSD variant.
Further reading:
tput, reset - initialize a terminal or query terminfo
database
history section for tput
history section for tset
Occasionally someone asks about suppressing automargins because they suppose that terminals can pan/scroll left/right to show the information which was not wrapped to a new line. Terminals which do this are rare, and OSX Terminal is not one of those. It behaves like a subset of xterm, which itself emulates the series of DEC terminals vt52/vt100/vt220/etc. In this question, OP is concerned/confused about this paragraph from the screen manual:
If your terminal is a "true" auto-margin terminal (it doesn't allow the
last position on the screen to be updated without scrolling the screen)
consider using a version of your terminal's termcap that has automatic
margins turned off. This will ensure an accurate and optimal update of
the screen in all circumstances. Most terminals nowadays have "magic"
margins (automatic margins plus usable last column). This is the VT100
style type and perfectly suited for screen. If all you've got is a
"true" auto-margin terminal screen will be content to use it, but
updating a character put into the last position on the screen may not
be possible until the screen scrolls or the character is moved into a
safe position in some other way. This delay can be shortened by using a
terminal with insert-character capability.
That last position on the screen refers to the lower-right corner of the terminal. In the normal case, if your cursor is on the lower-right corner and you print a character, you would expect the display to scroll up by one line and show the character on the next line. Also (because terminals can be implemented in different ways), some could scroll up when you print a character in the last position. The VT100 does not do this. Not only does it not scroll up in that case, but it ignores non-printing characters while on the margin (see xterm FAQ That description of wrapping is odd, say more?). There is a terminfo flag xenl which is set to show when the terminal does this special behavior. About a third of the terminal descriptions in the terminal database have this flag. While most of those are for terminals which you likely will never encounter, keep in mind that the advice in the manual page was written back in an era when those other terminals were as likely to be found as a VT100-lookalike. The early change-history for screen is poor, but the text was in screen's second posting to Usenet in 1992. The initial posting in 1987 said something similar:
Screen
never writes in the last position of the screen, unless the boolean
capability LP is found in the termcap entry of the terminal.
Usually,
screen
cannot predict whether or not a particular terminal scrolls when
a character is written in the last column of the last line;
LP indicates that it is safe to write in this position.
Note that the LP capability is independent of am (automatic
margins); for certain terminals, such as the VT100, it is reasonable
to set am as well as LP in the corresponding termcap entry
(the VT100 does not move the cursor when a character is written in
the last column of each line).
The later wording reflects the fact that the terminfo system was prevalent, and the name LP was not termcap name chosen for corresponding with xenl (it is xn).
The point of all of this is that screen attempts to convert between programs writing to different terminal types and make them all appear like one type of terminal — which means that it tries to put text on the terminal's display in all of the locations. The lower-right corner is a problem because some terminals would scroll up, spoiling the attempt to write there. As a workaround, some terminals provided an alternative:
using a different mode (insert),
put the cursor on the next to last position of the display,
write characters to fill in, pushing a character into the last position, and
turn insert-mode off once it is done (otherwise a nuisance).
About two thirds of the descriptions in the terminal database have the capability to do this insert-mode (smir). That still was not perfect, but it certainly was worth mentioning in 1992. About a quarter implement a similar similar feature ich1. Some implement both (and vi could get confused by those, by trying to do both methods).
VT100-lookalikes provide a third way to write that last position; screen checks for and uses whatever is there.
If I understand you correctly you're looking to set the autowrap feature to NO using terminfo database. If so I believe you can use the -nam flag to turn it off - something like vt100-nam should do it. You can also check by looking at the man pages for terminfo.
If this solves your question, mark this up. (^_^) If not... well comment back and I'll check again for you. Cheers!
Update: There's also a shortcut that may apply to you to toggle the wrap off and on. Check out the shortcut sheet here. And additional information for Screen can be found here (search for wrap). You can also check here on how to use setterm (section 17.14 Changing the Terminal Settings). Also check here for examples of changing settings.
Good luck again. (^_^)

How do shell text editors work?

I'm fairly new at programming, but I've wondered how shell text editors such as vim, emacs, nano, etc are able to control the command-line window. I'm primarily a Windows programmer, so maybe it's different on *nix. As far as I know, it's only possible to print text to a console, and ask for input. How do text editors create a navigable, editable window in a command line environment?
By using libraries such as the following which, in turn, use escape character sequences
NAME
ncurses - CRT screen handling and optimization package
SYNOPSIS
#include
DESCRIPTION
The ncurses library routines give the user a terminal-independent
method of updating character screens with reasonable optimization. This
implementation is ‘‘new curses’’ (ncurses) and is the approved replacement
for 4.4BSD classic curses, which has been discontinued.
[...snip....]
The ncurses package supports: overall screen, window and pad
manipulation; output to windows and pads; reading terminal input; control
over terminal and curses input and output options; environment query
routines; color manipulation; use of soft label keys; terminfo capabilities;
and access to low-level terminal-manipulation routines.
Short answer: there are libraries for it (like curses, slang).
Longer answer: doing things like jumping around with the cursor or changing colors are done by printing special character sequences (called escape-secquences, because they start with the ESC character).
Learning about ncurses might be a good starting point.
There is an old protocol called vt100 based on a "VT100" terminal. It used codes starting with escape to control cursor position, color, clearing the screen, etc.
It's also how you get colored prompts.
Google VT100 or "terminal escape codes"
edit: I Googled it for you: http://www.termsys.demon.co.uk/vtansi.htm
You will also notice this if you type "edit" in a Windows command line console. This "feature" is not unique to unix-like systems, though the concepts for manipulating the windows console in that way are quite different to in unix.
On Unix systems, a console window emulates an ancient serial terminal (usually a VT100). You can print special control characters and escape sequences to move the cursor around, change colors, and do other special effects. There are libraries to help handle the details; ncurses is the most popular.
On Windows, the [Win32 Console API](http://msdn.microsoft.com/en-us/library/ms682073(VS.85%29.aspx) provides similar functionality, but in a rather different manner.
Type "c:\winnt\system32\edit" or "c:\windows\system32\edit" at the command line, and you'll be shown a command line text editor.
People are mostly right about the ESC character being used to control the command screen, but some older programs also write characters directly to the memory space used by the Windows Command Line screen.
In order to control the command line window, you used to have to write your own windowing forms, entry box, menus, etc. You'd also have to wrap all that up in a big loop for handling events.
More Windows command line specific, the app typically calls DOS or BIOS functions that do the same. Sometimes ANSI command code support is available, sometimes it isn't (depending on exact MS OS version and whether or not it's configured to load it).

Resources