Created
October 15, 2009 08:08
-
-
Save mayuki/210770 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import clr | |
| import re | |
| import Misuzilla.Applications.TwitterIrcGateway | |
| import Misuzilla.Applications.TwitterIrcGateway.AddIns | |
| import Misuzilla.Applications.TwitterIrcGateway.AddIns.Console | |
| from System import * | |
| from System.Threading import Thread, ThreadStart | |
| from System.Diagnostics import * | |
| from System.Collections.Generic import * | |
| from Misuzilla.Applications.TwitterIrcGateway.AddIns.Console import ConsoleAddIn, Console, Context | |
| from Misuzilla.Applications.TwitterIrcGateway.AddIns.DLRIntegration import DLRIntegrationAddIn, DLRBasicConfiguration, DLRContextHelper | |
| class ShellContext(Context): | |
| def Initialize(self): | |
| self.shell = Shell.instance() | |
| pass | |
| def OnUninitialize(self): | |
| pass | |
| def OnCallMissingCommand(self, commandName, rawInputLine): | |
| if String.Compare(rawInputLine, "exit", True) == 0: | |
| return False | |
| else: | |
| self.shell.proc.StandardInput.WriteLine(rawInputLine) | |
| return True | |
| return False | |
| class Shell(Object): | |
| @classmethod | |
| def instance(klass): | |
| if not hasattr(klass, 'instance_'): | |
| klass.instance_ = Shell() | |
| return klass.instance_ | |
| def __init__(self): | |
| # コンソールチャンネルを追加する | |
| self.console = Misuzilla.Applications.TwitterIrcGateway.AddIns.Console.Console() | |
| CurrentSession.AddInManager.GetAddIn[DLRIntegrationAddIn]().BeforeUnload += self.onBeforeUnload | |
| psInfo = ProcessStartInfo(); | |
| psInfo.FileName = "/bin/sh" | |
| psInfo.RedirectStandardError = True | |
| psInfo.RedirectStandardInput = True | |
| psInfo.RedirectStandardOutput = True | |
| psInfo.UseShellExecute = False | |
| psInfo.CreateNoWindow = True | |
| psInfo.WindowStyle = ProcessWindowStyle.Normal | |
| p = Process.Start(psInfo) | |
| self.proc = p | |
| dataRecvEventHandler = lambda sender, e: self.console.NotifyMessage(e.Data) | |
| p.OutputDataReceived += dataRecvEventHandler | |
| p.ErrorDataReceived += dataRecvEventHandler | |
| p.BeginOutputReadLine() | |
| p.BeginErrorReadLine() | |
| def onBeforeUnload(self, sender, e): | |
| CurrentSession.AddInManager.GetAddIn[ConsoleAddIn]().UnregisterContext(DLRContextHelper.Wrap(CurrentSession, "ShellContext", ShellContext)) | |
| self.proc.Kill() | |
| self.console.Detach() | |
| shell = Shell.instance() | |
| shell.console.Attach("#Shell", Server, Session, DLRContextHelper.Wrap(CurrentSession, "Shell", ShellContext)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment