顯示包含「cygwin」標籤的文章。顯示所有文章
顯示包含「cygwin」標籤的文章。顯示所有文章

2010年12月18日星期六

[Console2 + Cygwin + bash + Mercurial + style template] to support ANSI escape code

As I find some nice looking hg log style template, I want to use them in my environment.
After spending sometime in trial and error, I figure out a way to support it.
Here are the necessary settings:

Console2 setting:

Title: cygwin
Icon: C:\cygwin\Cygwin.ico
Shell: C:\WINDOWS\system32\ansicon.exe C:\WINDOWS\system32\startbash.bat
Startup dir: C:\cygwin\home\kip

For ansicon.exe, please refer to other post: ANSICON provides ANSI escape sequences for Windows console programs 

startbash.bat is just two lines:

@echo off
C:\cygwin\bin\bash.exe --login -i


Cygwin setting:

.bash_profile:
export TERM=ansi



Mercurial setting:


.hgrc:
[extensions ]
color =


[color]
mode = ansi




The right click context menu "Open cygwin here" cannot be use after these changes, but you can still add "Open cygwin" in context menu by adding following in registry:


open_cygwin.reg

Windows Registry Editor Version 5.00


[HKEY_CLASSES_ROOT\Directory\shell\Open cygwin\command]
@="C:\\Program Files\\Console2\\Console.exe -t cygwin"

After completed all these steps, you can try hg slog, nlog, sglog.
Please refer to previous post: [Mercurial] Enhance hg log with nice coloring 

[Mercurial] Enhance hg log with nice coloring

<read [Console2 + Cygwin + bash + Mercurial + style template] to support ANSI escape code to setup the environment first>


Now, I use Console2 + cygwin + ansicon + bash for my Mercurial operation.
There are several hg command that support --style STYLE formatting, e.g. log, outgoing, incoming, tip, parents, heads, glog and serve.
The most useful common with styling is hg log.


I find a good website written by Steve Losh : Styling Mercurial’s CLI, which provide several good style template for hg log, includes "slog", "nlog" and "sglog".

Styling Mercurial’s CLI

posted by Steve Losh on
January 15, 2010


Mercurial has a great command line interface and many people use it without 
ever feeling the need for a GUI to manage their 
repositories. However, we can make it even better by taking advantage of 
Mercurial’s templating features.


In this tip I’m going to post some of the templates I use and show you how to 
use them yourself. Check out hg help templating if you want more 
details on how the templating actually works.


If you like what you see you can grab my templates by cloning their repository
from BitBucket:


hg clone http://bitbucket.org/sjl/mercurial-cli-templates/


NOTE: I’ve customized the colors of 
my Terminal, so the colors will look different for you. If you like the colors 
I’m using you can read the blog entry
I wrote about it.

Short Log

In a previous tip I described how to create an hg slog alias that can be very useful for counting changesets. With the right styling it can be useful in your day-to-day work. Here’s what the output of my hg slog command looks like:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
slog = log --style=/full/path/to/map-cmdline.slog

Nice Log

The short log is great a quick review of the past few changesets, but for a much more detailed view of a particular changeset I’ve created an hg nlog alias, which looks like this:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
nlog = log --style=/full/path/to/map-cmdline.nlog

Short Graphlog

The graphlog command is wonderful for reviewing the history of repositories with branches, but we can make it more compact and easier to read with another template. The result looks like this:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
sglog = glog --style=/full/path/to/map-cmdline.sglog

===============================================================

I find a way no need to put /full/path/to/ the map-cmdline.xxx, just need to put the map-cmdline.xxx in C:\Program Files\TortoiseHg\templates, the set the alias as:
[alias]
slog  = log --style slog
nlog  = log --style nlog
sglog = log --style sglog

Then just try the following command:
hg slog -l10
hg slog -l10 -v
hg nlog -r tip
hg nlog -r tip -p

hg sglog -l8
hg sglog -l8 -v


Have fun :)

ANSI Escape sequences [Color]

<read [Console2 + Cygwin + bash + Mercurial + style template] to support ANSI escape code to setup the environment first>

ANSI escape sequence is a sequence of ASCII characters, the first two of which are the ASCII "Escape" character 27 (1Bh) and the left-bracket character " [ " (5Bh). The character or characters following the escape and left-bracket characters specify an alphanumeric code that controls a keyboard or display function.
ANSI escape sequences distinguish between uppercase and lowercase letters.


  Esc[Value;...;Value

Set Graphics Mode:
Calls the graphics functions specified by the following values. These specified functions remain active until the next occurrence of this escape sequence. Graphics mode changes the colors and attributes of text (such as bold and underline) displayed on the screen.

Text attributes
0All attributes off
1Bold on
4Underscore (on monochrome display adapter only)
5Blink on
7Reverse video on
8Concealed on
Foreground colors
30Black
31Red
32Green
33Yellow
34Blue
35Magenta
36Cyan
37White
Background colors
40Black
41Red
42Green
43Yellow
44Blue
45Magenta
46Cyan
47White

Parameters 30 through 47 meet the ISO 6429 standard.


For example, cat a file color_ansi.txt in cygwin with TERM=ansi will display like this:

2010年12月15日星期三

Console2+cmd+cygwin replace cmd.exe

Console2


Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles


Create new tabs

File -> New tab

Edit -> Setting -> Tabs

Add cmd tab

Title: cmd
Icon: <default>
Shell: C:\WINDOWS\system32\cmd.exe

Add cygwin tab

Title: cygwin
Icon: C:\cygwin\Cygwin.ico
Shell: C:\cygwin\bin\bash.exe --login –i

Save settings to user directory

Customize setting

Console

Shell: C:\WINDOWS\system32\cmd.exe
Appearance
Check:
Use tab titles
Show command
Show command in tabs
Trim tab titles to
Use tab icons

Behavior

Check:
         Copy on select
         Don’t wrap long lines
Clear selection on copy
Trim trailing spaces

Hotkeys

Paste: Ctrl+V

Mouse

Copy/clear selection: None
Select text: Left (uncheck shift)
Paste text: Middle


Add to Right click menu

Open cmd here

Add registry key:
HKEY_CLASSES_ROOT\Directory\shell\Open cmd here\command
Default: C:\Program Files\Console2\Console.exe -t cmd "%1"\

Open cygwin here

Run cygwin setup.exe, install chere package.

Add registry key:
HKEY_CLASSES_ROOT\Directory\shell\Open cygwin\command
C:\Program Files\Console2\Console.exe -t cygwin -r "/bin/xhere /bin/bash.exe '%L'"


Add to Right click context menu 

Create a .reg file, copy and paste below lines and run the .reg file:
 
Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Directory\shell\Open cmd here...]
[HKEY_CLASSES_ROOT\Directory\shell\Open cmd here...\command]
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cmd -r \"/bin/xhere /bin/bash.exe '%L'\""
 
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin here...]
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...\command]
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cygwin -r \"/bin/xhere /bin/bash.exe '%L'\""