Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion NetBash.Sample/NetBash.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -15,6 +16,15 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -163,8 +173,13 @@
<Name>NetBash</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 3 additions & 3 deletions NetBash.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetBash", "NetBash.\NetBash.csproj", "{AD552539-66F6-4FA2-8763-D76893A6DF69}"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetBash", "NetBash\NetBash.csproj", "{AD552539-66F6-4FA2-8763-D76893A6DF69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetBash.Sample", "NetBash.Sample\NetBash.Sample.csproj", "{774201D2-F1BA-4595-9828-204A5390395A}"
EndProject
Expand Down
22 changes: 22 additions & 0 deletions NetBash/NetBash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ private CommandResult renderHelp()
return new CommandResult { Result = sb.ToString(), IsHtml = false };
}

public string CommandList()
{
if (_commandTypes == null || !_commandTypes.Any())
LoadCommands();

var sb = new StringBuilder();

sb.Append("\"clear\"");

foreach (var t in _commandTypes)
{
var attr = (WebCommandAttribute)t.GetCustomAttributes(_attributeType, false).FirstOrDefault();

if (attr == null)
continue;

sb.Append(string.Format(",\"{0}\"", attr.Name.ToLower()));
}

return sb.ToString();
}

public static IHtmlString RenderIncludes()
{
return NetBashHandler.RenderIncludes();
Expand Down
5 changes: 3 additions & 2 deletions NetBash/UI/NetBashHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ internal static HtmlString RenderIncludes()
if(!window.key) document.write(unescape(""%3Cscript src='{0}netbash-keymaster-js' type='text/javascript'%3E%3C/script%3E""));
</script>
<script type=""text/javascript"" src=""{0}netbash-script-js?v={1}""></script>
<script type=""text/javascript"">var netbash = new NetBash(jQuery, window, {{ welcomeMessage: '{2}', version: '{3}', isHidden: {4}, routeBasePath: '{5}' }});</script>";
<script type=""text/javascript"">var netbash = new NetBash(jQuery, window, {{ welcomeMessage: '{2}', version: '{3}', isHidden: {4}, routeBasePath: '{5}', items: [{6}] }});</script>";

var result = "";
result = string.Format(format,
ensureTrailingSlash(VirtualPathUtility.ToAbsolute(NetBash.Settings.RouteBasePath)),
NetBash.Settings.Hash, NetBash.Settings.WelcomeMessage,
NetBash.Settings.Version,
NetBash.Settings.HiddenByDefault.ToString().ToLower(),
NetBash.Settings.RouteBasePath.Replace("~", ""));
NetBash.Settings.RouteBasePath.Replace("~", ""),
NetBash.Current.CommandList());

return new HtmlString(result);
}
Expand Down
58 changes: 57 additions & 1 deletion NetBash/UI/script-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,42 @@ function NetBash($, window, opt) {
});
};

this.getCurPos = function (inp) {
if (!inp) { return 0; }
if (document.selection) { inp.focus(); }
return 'selectionStart' in inp ? inp.selectionStart : '' || Math.abs(document.selection.createRange().moveStart('character', -inp.value.length));
};

this.setCursorPos = function(elem, cp) {
if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', cp);
range.select();
} else {
if (elem.selectionStart) {
elem.focus();
elem.setSelectionRange(cp, cp);
} else {
elem.focus();
}
}
};

this.searchRange = function(start, end, matchtxt) {
for (var i = start; i < end; i++) {
if (options.items[i].indexOf(matchtxt) == 0) {
return i;
}
}
return -1;
};

$(function () {
load();
self.initUI();

//enter press
$("#console-input input").keyup(function (event) {
$("#console-input input").keydown(function (event) {
if (event.which == 13) { //enter
event.preventDefault();

Expand All @@ -184,6 +214,32 @@ function NetBash($, window, opt) {
self.closeConsole();
self.toggleConsole();
$("#console-input input").val("");
} else if (event.which == 9) {
event.preventDefault();
// get the text behind the cursor
var cp = self.getCurPos(this);
var matchtxt = this.value.substr(0, cp);
var txt = this.value;
var start = 0;

if (txt != matchtxt) {
for (var i = 0; i < options.items.length; i++) {
if (options.items[i] == txt) {
start = i + 1;
break;
}
}
}

var ix = self.searchRange(start, options.items.length, matchtxt);
if (ix == -1 && start != 0) {
ix = self.searchRange(0, start, matchtxt);
}

if (ix != -1) {
this.value = options.items[ix];
self.setCursorPos(this, cp);
}
}
});

Expand Down