C# Class ConEmu.WinForms.ConEmuSession

A single session of the console emulator running a console process. Each console process execution in the control spawns a new console emulator and a new session.

When the console emulator starts, a console view appears in the control. The console process starts running in it immediately. When the console process terminates, the console emulator might or might not be closed, depending on the settings. After the console emulator closes, the control stops viewing the console, and this session ends.

Afficher le fichier Open project: Maximus5/conemu-inside Class Usage Examples

Private Properties

Свойство Type Description
BeginGuiMacro GuiMacroBuilder
Init_AnsiLog AnsiLog
Init_ConsoleProcessMonitoring void
Init_MakeConEmuCommandLine Microsoft.Build.Utilities.CommandLineBuilder
Init_MakeConEmuCommandLine_EmitConfigFile string
Init_MakeConEmuCommandLine_EmitConfigFile_EscapeEchoText string
Init_PayloadProcessMonitoring_WaitForExitCodeAsync Task
Init_StartConEmu System.Diagnostics.Process
Init_TempWorkingFolder System.IO.DirectoryInfo
Init_WireEvents void
KillConsoleProcessAsync Task
TerminateLifetime void
TryFireConsoleProcessExited void
WaitForConsoleEmulatorCloseAsync Task
WaitForConsoleProcessExitAsync Task

Méthodes publiques

Méthode Description
Close ( ) : void

An alias for CloseConsoleEmulator.

CloseConsoleEmulator ( ) : void

Closes the console emulator window, and kills the console process if it's still running.

This also closes the running session, the control goes blank and ready for running a new session.

To just kill the console process, use KillConsoleProcessAsync. If ConEmuStartInfo.WhenConsoleProcessExits allows, the console emulator window might stay open after that.

ConEmuSession ( [ startinfo, [ hostcontext ) : System

Starts the session. Opens the emulator view in the control (HWND given in hostcontext) by starting the ConEmu child process and giving it that HWND; ConEmu then starts the child Console Process for the commandline given in startinfo and makes it run in the console emulator window.

ExecuteGuiMacroTextAsync ( [ macrotext ) : Task

Executes a ConEmu GUI Macro on the active console, see http://conemu.github.io/en/GuiMacro.html .

This function takes for formatted text of a GUI Macro; to format parameters correctly, better use the BeginGuiMacro and the macro builder.

ExecuteGuiMacroTextSync ( [ macrotext ) : GuiMacroResult

Executes a ConEmu GUI Macro on the active console, see http://conemu.github.io/en/GuiMacro.html , synchronously.

This function takes for formatted text of a GUI Macro; to format parameters correctly, better use the BeginGuiMacro and the macro builder.

GetConsoleProcessExitCode ( ) : int

Gets the exit code of the console process, if it has already exited. Throws an exception if it has not.

This state only changes on the main thread.

SendControlBreakAsync ( ) : Task

Sends the Control+Break signal to the console process, which will most likely abort it.

Unlike KillConsoleProcessAsync, this is a soft signal which might be processed by the console process for a graceful shutdown, or ignored altogether.

SendControlCAsync ( ) : Task

Sends the Control+C signal to the payload console process, which will most likely abort it.

Unlike KillConsoleProcessAsync, this is a soft signal which might be processed by the console process for a graceful shutdown, or ignored altogether.

WriteInputText ( [ text ) : Task

Writes text to the console input, as if it's been typed by user on the keyboard.

Whether this will be visible (=echoed) on screen is up to the running console process.

WriteOutputText ( [ text ) : Task

Writes text to the console output, as if the current running console process has written it to stdout.

Use with caution, as this might interfere with console process output in an unpredictable manner.

Private Methods

Méthode Description
BeginGuiMacro ( [ sMacroName ) : GuiMacroBuilder
Init_AnsiLog ( [ startinfo ) : AnsiLog
Init_ConsoleProcessMonitoring ( ) : void

Watches for the status of the payload console process to fetch its exitcode when done and notify user of that.

Init_MakeConEmuCommandLine ( [ startinfo, [ hostcontext, [ ansilog, [ dirLocalTempRoot ) : CommandLineBuilder
Init_MakeConEmuCommandLine_EmitConfigFile ( [ dirForConfigFile, [ startinfo, [ hostcontext ) : string
Init_MakeConEmuCommandLine_EmitConfigFile_EscapeEchoText ( [ text ) : string

Applies escaping so that (1) it went as a single argument into the ConEmu's NextArg function; (2) its special chars were escaped according to the ConEmu's DoOutput function which implements this echo.

Init_PayloadProcessMonitoring_WaitForExitCodeAsync ( ) : Task

Async-loop retries for getting the root payload process to await its exit.

Init_StartConEmu ( [ startinfo, [ cmdl ) : Process
Init_TempWorkingFolder ( ) : DirectoryInfo
Init_WireEvents ( [ startinfo ) : void
KillConsoleProcessAsync ( ) : Task
TerminateLifetime ( ) : void
TryFireConsoleProcessExited ( int nConsoleProcessExitCode ) : void

Fires the payload exited event if it has not been fired yet.

WaitForConsoleEmulatorCloseAsync ( ) : Task
WaitForConsoleProcessExitAsync ( ) : Task

Method Details

Close() public méthode

An alias for CloseConsoleEmulator.
public Close ( ) : void
Résultat void

CloseConsoleEmulator() public méthode

Closes the console emulator window, and kills the console process if it's still running.

This also closes the running session, the control goes blank and ready for running a new session.

To just kill the console process, use KillConsoleProcessAsync. If ConEmuStartInfo.WhenConsoleProcessExits allows, the console emulator window might stay open after that.

public CloseConsoleEmulator ( ) : void
Résultat void

ConEmuSession() public méthode

Starts the session. Opens the emulator view in the control (HWND given in hostcontext) by starting the ConEmu child process and giving it that HWND; ConEmu then starts the child Console Process for the commandline given in startinfo and makes it run in the console emulator window.
public ConEmuSession ( [ startinfo, [ hostcontext ) : System
startinfo [ User-defined startup parameters for the console process.
hostcontext [ Control-related parameters.
Résultat System

ExecuteGuiMacroTextAsync() public méthode

Executes a ConEmu GUI Macro on the active console, see http://conemu.github.io/en/GuiMacro.html .

This function takes for formatted text of a GUI Macro; to format parameters correctly, better use the BeginGuiMacro and the macro builder.

public ExecuteGuiMacroTextAsync ( [ macrotext ) : Task
macrotext [ The full macro command, see http://conemu.github.io/en/GuiMacro.html .
Résultat Task

ExecuteGuiMacroTextSync() public méthode

Executes a ConEmu GUI Macro on the active console, see http://conemu.github.io/en/GuiMacro.html , synchronously.

This function takes for formatted text of a GUI Macro; to format parameters correctly, better use the BeginGuiMacro and the macro builder.

public ExecuteGuiMacroTextSync ( [ macrotext ) : GuiMacroResult
macrotext [ The full macro command, see http://conemu.github.io/en/GuiMacro.html .
Résultat GuiMacroResult

GetConsoleProcessExitCode() public méthode

Gets the exit code of the console process, if it has already exited. Throws an exception if it has not.

This state only changes on the main thread.

public GetConsoleProcessExitCode ( ) : int
Résultat int

SendControlBreakAsync() public méthode

Sends the Control+Break signal to the console process, which will most likely abort it.

Unlike KillConsoleProcessAsync, this is a soft signal which might be processed by the console process for a graceful shutdown, or ignored altogether.

public SendControlBreakAsync ( ) : Task
Résultat Task

SendControlCAsync() public méthode

Sends the Control+C signal to the payload console process, which will most likely abort it.

Unlike KillConsoleProcessAsync, this is a soft signal which might be processed by the console process for a graceful shutdown, or ignored altogether.

public SendControlCAsync ( ) : Task
Résultat Task

WriteInputText() public méthode

Writes text to the console input, as if it's been typed by user on the keyboard.

Whether this will be visible (=echoed) on screen is up to the running console process.

public WriteInputText ( [ text ) : Task
text [
Résultat Task

WriteOutputText() public méthode

Writes text to the console output, as if the current running console process has written it to stdout.

Use with caution, as this might interfere with console process output in an unpredictable manner.

public WriteOutputText ( [ text ) : Task
text [
Résultat Task