Skip to content

Commit

Permalink
Add env object to detect os/os_version/cpu.
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 16, 2023
1 parent cb2adaa commit 22d6eea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion site/.lunet/js/prism-kalk.generated.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions site/doc/api/general.generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ out = 3
out = 3
```

## env

`env`

Return an environment object that provides access to os (windows, linux, macos), os_version and cpu.

### Returns

An object with the properties `os`, `os_version`, and `cpu`.

## eval

`eval(text,output?)`
Expand Down
26 changes: 26 additions & 0 deletions src/Kalk.Core/KalkEngine.Functions.General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ public partial class KalkEngine
return moduleT;
}

/// <summary>
/// Return an environment object that provides access to os (windows, linux, macos), os_version and cpu.
/// </summary>
/// <returns>An object with the properties `os`, `os_version`, and `cpu`.</returns>
[KalkExport("env", CategoryGeneral)]
public ScriptObject Env
{
get
{
string os = OperatingSystem.IsWindows() ? "windows"
: OperatingSystem.IsLinux() ? "linux"
: OperatingSystem.IsMacOS() ? "macos" : "unknown";

var env = new ScriptObject
{
["os"] = os,
["os_version"] = System.Runtime.InteropServices.RuntimeInformation.OSDescription,
["cpu"] = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()
};
env.SetReadOnly("os", true);
env.SetReadOnly("os_version", true);
env.SetReadOnly("cpu", true);
return env;
}
}

/// <summary>
/// Creates an action for the command line editor experience related to
/// cursor/text manipulation. This action can then be used by the `shortcut` command.
Expand Down
8 changes: 8 additions & 0 deletions src/Kalk.Core/KalkEngine.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26153,6 +26153,7 @@ protected void RegisterFunctionsAuto()
RegisterConstant("config", Config);
RegisterConstant("aliases", Aliases);
RegisterConstant("shortcuts", Shortcuts);
RegisterConstant("env", Env);
RegisterFunction("action", (Func<string, Kalk.Core.KalkActionObject>)Action);
RegisterAction("license", (Action)License);
RegisterFunction("clipboard", (Func<object, object>)Clipboard);
Expand Down Expand Up @@ -26243,6 +26244,13 @@ private void RegisterDocumentationAuto()
shortcut(tester, ""ctrl+d"", '""' + date + '""') # ctrl+d => '""' + date + '""'
";
}
{
var descriptor = Descriptors["env"];
descriptor.Category = "General";
descriptor.Description = @"Return an environment object that provides access to os (windows, linux, macos), os_version and cpu.";
descriptor.IsCommand = false;
descriptor.Returns = @"An object with the properties `os`, `os_version`, and `cpu`.";
}
{
var descriptor = Descriptors["action"];
descriptor.Category = "General";
Expand Down

0 comments on commit 22d6eea

Please sign in to comment.