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

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 :)

ANSICON provides ANSI escape sequences for Windows console programs

Project: adoxa/ansicon - GitHub



   ANSICON

Copyright 2005-2010 Jason Hood

   Version 1.32.  Freeware


    ===========
    Description
    ===========

    ANSICON provides ANSI escape sequences for Windows console programs.  It
    provides much the same functionality as `ANSI.SYS' does for MS-DOS.


    ============
    Requirements
    ============

    Windows 2000 Professional and later (it won't work with NT or 9X).


    ============
    Installation
    ============

    Add x86 (if your OS is 32-bit) or x64 (if 64-bit) to your PATH, or copy
    the relevant files to a directory already on the PATH.  Alternatively,
    use option `-i' (or `-I') to install it permanently, by adding an entry
    to CMD.EXE's AutoRun registry value (current user or local machine,
    respectively).  Uninstall simply involves closing any programs that are
    currently using it, running with `-u' (and again with `-U') to remove
    the AutoRun entry/ies, then removing the directory from PATH or deleting
    the files. No other changes are made.

    ---------
    Upgrading
    ---------

    Delete ANSI.dll, it has been replaced with ANSI32.dll.
    Delete ANSI-LLA.dll, it has been replaced with ANSI-LLW.dll.


    =====
    Usage
    =====

    Running ANSICON with no arguments will start a new instance of the com-
    mand processor (the program defined by the `ComSpec' environment var-
    iable, typically `CMD.EXE'), or display standard input if it is redir-
    ected.  Passing the option `-p' (case sensitive) will enable the parent
    process to recognise escapes (i.e. the command shell used to run ANSI-
    CON).  Use `-m' to set the current (and default) attribute to grey on
    black ("monochrome"), or the attribute following the `m' (please use
    `COLOR /?' for attribute values).  The option `-e' will echo the command
    line - the character after the `e' is ignored, the remainder is display-
    ed verbatim; use `-E' to prevent a newline being written.  The option
    `-t' will display each file (or standard input if none or it is "-"), as
    though they are a single file; `-T' will display the file name (in be-
    tween "==> " and " <=="), a blank line (or an error message), the file
    and another blank line.  Anything else will be treated as a program and
    its arguments.  Eg: `ansicon -m30 -t file.ans' will display `file.ans'
    using black on cyan as the default color.

    Once installed, the ANSICON environment variable will be created.  This
    variable is of the form "WxH (wxh)", where W & H are the width and
    height of the buffer and w & h are the width and height of the window.
    The variable is updated whenever a program reads it directly (i.e. as
    an individual request, not as part of the entire environment block).
    For example, "set an" will not update it, but "echo %ansicon%" will.

    The Windows API WriteFile and WriteConsoleA functions will set the num-
    ber of characters written, not the number of bytes.  When using a multi-
    byte character set, this results in a smaller number (since multiple
    bytes are used to represent a single character).  Some programs recog-
    nise this as a reduced write and will inadvertently repeat previous
    characters.  If you discover such a program, use the ANSICON_API envir-
    onment variable to record it and override the API, returning the origin-
    al byte count.  Ruby is an example of such a program (at least, up till
    1.9.2p0), so use "set ANSICON_API=ruby" to avoid the repitition.  The
    full syntax of the variable is:

ANSICON_API=[!]program;program;program...

    PROGRAM is the name of the program, with no path and extension.  The
    leading exclamation inverts the usage, meaning the API will always be
    overridden, unless the program is in the list.  The variable can be made
    permanent by going to System Properties, selecting the Advanced tab and
    clicking Environment Variables (using XP; Vista/7 may be different).


    =========
    Sequences
    =========

    The following escape sequences are recognised.

\e[#A    CUU: CUrsor Up
\e[#B    CUD: CUrsor Down
\e[#C    CUF: CUrsor Forward
\e[#D    CUB: CUrsor Backward
\e[#E    CNL: Cursor Next Line
\e[#F    CPL: Cursor Preceding Line
\e[#G    CHA: Cursor Horizontal Absolute
\e[#;#H     CUP: CUrsor Position
\e[#;#f     HVP: Horizontal and Vertical Position
\e[s    SCP: Save Cursor Position
\e[u    RCP: Restore Cursor Position
\e[#J    ED:  Erase Display
\e[#K    EL:  Erase Line
\e[#L    IL:  Insert Lines
\e[#M    DL:  Delete Lines
\e[#@    ICH: Insert CHaracter
\e[#P    DCH: Delete CHaracter
\e[#;#;#m   SGM: Set Graphics Mode
\e[#n    DSR: Device Status Report
\e[21t Report (xterm) window's title
\e]0;titleBEL Set (xterm) window's title (and icon)

    `\e' represents the escape character (ASCII 27); `#' represents a
    decimal number (optional, in most cases defaulting to 1).  Regarding
    SGM: bold will set the foreground intensity; underline and blink will
    set the background intensity; conceal uses background as foreground.

    I make a distinction between "\e[m" and "\e[0;...m".  Both will restore
    the original foreground/background colors (and so "0" should be the
    first parameter); the former will also restore the original bold and
    underline attributes, whilst the latter will explicitly reset them.


    ===========
    Limitations
    ===========

    The entire console buffer is used, not just the visible window.

    If running CMD.EXE, its own COLOR will be the initial color.

    The 64-bit version can inject into a 32-bit process, but the 32-bit
    version will not inject into a 64-bit process.