public void Init()
{
if (inited)
{
return;
}
/* This should not happen any more, since it is checked for in Console */
if (!ConsoleDriver.IsConsole)
{
throw new IOException("Not a tty.");
}
inited = true;
ConsoleDriver.SetEcho(false);
string endString = null;
keypadXmit = reader.Get(TermInfoStrings.KeypadXmit);
keypadLocal = reader.Get(TermInfoStrings.KeypadLocal);
if (keypadXmit != null)
{
WriteConsole(keypadXmit); // Needed to get the arrows working
if (keypadLocal != null)
{
endString += keypadLocal;
}
}
origPair = reader.Get(TermInfoStrings.OrigPair);
origColors = reader.Get(TermInfoStrings.OrigColors);
setfgcolor = MangleParameters(reader.Get(TermInfoStrings.SetAForeground));
setbgcolor = MangleParameters(reader.Get(TermInfoStrings.SetABackground));
// lighter fg colours are 90 -> 97 rather than 30 -> 37
setlfgcolor = color16 ? setfgcolor.Replace("[3", "[9") : setfgcolor;
// lighter bg colours are 100 -> 107 rather than 40 -> 47
setlbgcolor = color16 ? setbgcolor.Replace("[4", "[10") : setbgcolor;
string resetColors = (origColors == null) ? origPair : origColors;
if (resetColors != null)
{
endString += resetColors;
}
if (!ConsoleDriver.TtySetup(endString, out verase, out vsusp, out intr))
{
throw new IOException("Error initializing terminal.");
}
stdin = new StreamReader(Console.OpenStandardInput(0), Console.InputEncoding);
clear = reader.Get(TermInfoStrings.ClearScreen);
bell = reader.Get(TermInfoStrings.Bell);
if (clear == null)
{
clear = reader.Get(TermInfoStrings.CursorHome);
clear += reader.Get(TermInfoStrings.ClrEos);
}
csrVisible = reader.Get(TermInfoStrings.CursorNormal);
if (csrVisible == null)
{
csrVisible = reader.Get(TermInfoStrings.CursorVisible);
}
csrInvisible = reader.Get(TermInfoStrings.CursorInvisible);
if (term == "cygwin" || term == "linux" || (term != null && term.StartsWith("xterm")) ||
term == "rxvt" || term == "dtterm")
{
titleFormat = "\x1b]0;{0}\x7"; // icon + window title
}
else if (term == "iris-ansi")
{
titleFormat = "\x1bP1.y{0}\x1b\\"; // not tested
}
else if (term == "sun-cmd")
{
titleFormat = "\x1b]l{0}\x1b\\"; // not tested
}
cursorAddress = reader.Get(TermInfoStrings.CursorAddress);
if (cursorAddress != null)
{
string result = cursorAddress.Replace("%i", String.Empty);
home_1_1 = (cursorAddress != result);
cursorAddress = MangleParameters(result);
}
GetCursorPosition();
#if DEBUG
logger.WriteLine("noGetPosition: {0} left: {1} top: {2}", noGetPosition, cursorLeft, cursorTop);
logger.Flush();
#endif
if (noGetPosition)
{
WriteConsole(clear);
cursorLeft = 0;
cursorTop = 0;
}
}