Skip to content

Commit

Permalink
intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
labbbirder committed Feb 5, 2024
1 parent dab36c0 commit 4f355f0
Show file tree
Hide file tree
Showing 23 changed files with 821 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Create Tag

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Klemensas/action-autotag@stable
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
8 changes: 8 additions & 0 deletions Documentation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Documentation/color-log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions Documentation/color-log.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Documentation/config_sys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/config_unity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/one-by-one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/unicode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions Editor/ConsoleUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace com.bbbirder.unityeditor
{
public static class ConsoleUtils
{
public const char PATH_SPLITTER =
#if UNITY_EDITOR_WIN
';'
#elif UNITY_EDITOR_OSX
':'
#endif
;
static Dictionary<int, string> foreColor = new(){
{30, "#000000"}, //black
{31, "#FF0000"}, //red
{32, "#00FF00"}, //green
{33, "#FFFF00"}, //yellow
{34, "#0000FF"}, //blue
{35, "#FF00FF"}, //magenta
{36, "#00FFFF"}, //cyan
{37, "#FFFFFF"}, //white
};

/// <summary>
/// Parse standard color log to unity color log
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string NormalizeColor(string input)
{
var pattern = "\x1b" + @"\[(\d+;)?(\d+;)?(\d+)m";
return Regex.Replace(input, pattern, m =>
{
foreach (Capture g in m.Groups)
{
if (int.TryParse(g.Value, out var c))
{
if (c is 0 or 39) return "</color>";
if (foreColor.TryGetValue(c, out var col)) return $"<color={col}>";
}
}
return m.Value;
});
}

/// <summary>
/// When standard output encoding is not normalized, use this to guess the encoding on the fly.
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public unsafe static bool IsUTF8InsteadOf16(byte[] bytes)
{
if (bytes.Length % 2 != 0) return true; // distinguish from utf-16 only
if (!bytes.Any(b => b == 0))
{
_ = 0;
}
var c = 0;
foreach (var b in bytes)
{
if (c != 0)
{
c--;
if ((b & 0xc0) != 0x80)
return false;
}
else
{
if (b == 0)
return false;
float f = 0xff ^ b;
int zcnt = (int)((*(uint*)&f << 1 >> 24) - 127);
c = stackalloc[]{
-1,-1,-1,3,2,1,-1,0,
}[zcnt];
if (c == -1)
return false;
}
}

return c == 0;
}
}

}
11 changes: 11 additions & 0 deletions Editor/ConsoleUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f355f0

Please sign in to comment.