diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/Documentation~/Image/UseMode1.png b/Documentation~/Image/UseMode1.png new file mode 100644 index 0000000..7aace38 Binary files /dev/null and b/Documentation~/Image/UseMode1.png differ diff --git a/Documentation~/Image/UseMode2.png b/Documentation~/Image/UseMode2.png new file mode 100644 index 0000000..7265452 Binary files /dev/null and b/Documentation~/Image/UseMode2.png differ diff --git a/Documentation~/Image/UseMode3.png b/Documentation~/Image/UseMode3.png new file mode 100644 index 0000000..849ece8 Binary files /dev/null and b/Documentation~/Image/UseMode3.png differ diff --git a/Documentation~/Image/install_github_NoWarng.png b/Documentation~/Image/install_github_NoWarng.png new file mode 100644 index 0000000..d42e43e Binary files /dev/null and b/Documentation~/Image/install_github_NoWarng.png differ diff --git a/Documentation~/Image/install_npm_NoWarng.png b/Documentation~/Image/install_npm_NoWarng.png new file mode 100644 index 0000000..97bbe6b Binary files /dev/null and b/Documentation~/Image/install_npm_NoWarng.png differ diff --git a/Editor/TextFile1.txt b/Editor/TextFile1.txt new file mode 100644 index 0000000..750103a --- /dev/null +++ b/Editor/TextFile1.txt @@ -0,0 +1,61 @@ +Para abrir terminais usando a classe `Process` em C#, +você pode especificar o executável do terminal desejado como o processo a ser iniciado. +Abaixo estão exemplos de como abrir terminais em diferentes sistemas operacionais usando C#: + +1. **Abrir o Prompt de Comando no Windows**: +```csharp +using System.Diagnostics; + +class Program +{ + static void Main() + { + Process.Start("cmd.exe"); + } +} +``` + +2. **Abrir o PowerShell no Windows**: +```csharp +using System.Diagnostics; + +class Program +{ + static void Main() + { + Process.Start("powershell.exe"); + } +} +``` + +3. **Abrir o Terminal no macOS**: +```csharp +using System.Diagnostics; + +class Program +{ + static void Main() + { + Process.Start("open", "-a Terminal"); + } +} +``` + +4. **Abrir o GNOME Terminal no Linux (Ubuntu)**: +```csharp +using System.Diagnostics; + +class Program +{ + static void Main() + { + Process.Start("gnome-terminal"); + } +} +``` + +Lembre-se de que, ao abrir um terminal dessa maneira, ele será iniciado como um processo separado e +independente do seu aplicativo C#. Você pode personalizar ainda mais a inicialização do terminal, +passando argumentos adicionais, se necessário, usando a sobrecarga de `Process.Start` que aceita uma string de argumentos. +Certifique-se de lidar com exceções ao trabalhar com a classe `Process`, pois pode haver erros de execução ou permissões +insuficientes, dependendo do sistema operacional e das configurações. \ No newline at end of file diff --git a/Editor/TextFile1.txt.meta b/Editor/TextFile1.txt.meta new file mode 100644 index 0000000..b9d0196 --- /dev/null +++ b/Editor/TextFile1.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 97fb1d1a70d26a047a07472c6261e1da +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/UnityEditorTerminal.cs b/Editor/UnityEditorTerminal.cs index e1683bc..e5b2a3a 100644 --- a/Editor/UnityEditorTerminal.cs +++ b/Editor/UnityEditorTerminal.cs @@ -2,28 +2,51 @@ using UnityEngine; using UnityEditor; using System.Diagnostics; +using System.Threading.Tasks; namespace Cobilas.Unity.Editor.Terminal { public class UnityEditorTerminal : EditorWindow { + private readonly static string[] terminals = { + "CMD", "PowerShell", "MacOS Terminal", "GNOME Terminal" + }; + [MenuItem("Window/UE-Terminal")] private static void Init() { UnityEditorTerminal window = GetWindow(); window.WorkingDirectory = Path.GetDirectoryName(Application.dataPath); + window.titleContent = new GUIContent("Unity Editor Terminal"); window.Show(); } - private TextEditor textEditor = new TextEditor(); + private Task myTask; private string saida; private string saida2; - [SerializeField] private bool setWorkingDirectory; + private GUIStyle style; + private Rect scrollViewRect; + [SerializeField] private float value; + [SerializeField] private int selectTerminal; + private Vector2 scrollPosition = Vector2.zero; + [SerializeField] private float terminal_Height; + private TextEditor textEditor = new TextEditor(); [SerializeField] private string WorkingDirectory; + private GUIContent contentTemp = new GUIContent(); + [SerializeField] private bool setWorkingDirectory; private void OnEnable() { + style = null; saida2 = (string)(saida = ">").Clone(); } private void OnGUI() { + Event @event = Event.current; + if (style is null) { + style = new GUIStyle(GUI.skin.box); + style.alignment = TextAnchor.UpperLeft; + } + + contentTemp.text = saida2; + EditorGUILayout.BeginHorizontal(); if (setWorkingDirectory = GUILayout.Toggle(setWorkingDirectory, "Set", GUI.skin.button, GUILayout.Width(50f))) { WorkingDirectory = EditorGUILayout.TextField("WorkingDirectory", WorkingDirectory); @@ -31,24 +54,51 @@ public class UnityEditorTerminal : EditorWindow { WorkingDirectory = Path.GetDirectoryName(Application.dataPath); } else EditorGUILayout.LabelField($"WorkingDirectory: {WorkingDirectory}", EditorStyles.boldLabel); EditorGUILayout.EndHorizontal(); + selectTerminal = EditorGUILayout.Popup("Terminals", selectTerminal, terminals); - Rect rect = EditorGUILayout.GetControlRect(true, GUILayout.ExpandHeight(true)); - Event @event = Event.current; + + scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); + Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(terminal_Height)); + + if (@event.type == EventType.Repaint) { + Vector2 textSize = style.CalcSize(contentTemp); + terminal_Height = textSize.y < scrollViewRect.height ? scrollViewRect.height -4f : textSize.y; + } if (@event.type == EventType.KeyDown) if (@event.keyCode == KeyCode.Return) { - CallCMD(saida2.Replace(saida, string.Empty)); + //CallCMD(saida2.Replace(saida, string.Empty), selectTerminal); + myTask = Task.Run(() => CallCMD(saida2.Replace(saida, string.Empty), selectTerminal)); @event.Use(); + Repaint(); } - - saida2 = DrawTextArea(rect, saida2, saida, @event, GUIUtility.GetControlID(FocusType.Keyboard)); + bool oldEnabled = GUI.enabled; + GUI.enabled = IsCompletedMyTask(); + saida2 = DrawTextArea(rect, saida2, saida, @event, textEditor, style, GUIUtility.GetControlID(FocusType.Keyboard)); + GUI.enabled = oldEnabled; + EditorGUILayout.EndScrollView(); + if (@event.type == EventType.Repaint) + scrollViewRect = GUILayoutUtility.GetLastRect(); } - private void CallCMD(string arg) { + private void CallCMD(string arg, int _selectTerminal) { if (string.IsNullOrEmpty(arg)) return; Process process = new Process(); - process.StartInfo = new ProcessStartInfo("cmd.exe", $"/c {arg}"); + switch (_selectTerminal) { + case 0: + process.StartInfo = new ProcessStartInfo("cmd.exe", $"/c {arg}"); + break; + case 1: + process.StartInfo = new ProcessStartInfo("powershell.exe", arg); + break; + case 2: + process.StartInfo = new ProcessStartInfo("open", $"-a Terminal {arg}"); + break; + case 3: + process.StartInfo = new ProcessStartInfo("gnome-terminal", arg); + break; + } process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = process.StartInfo.RedirectStandardError = @@ -61,14 +111,19 @@ public class UnityEditorTerminal : EditorWindow { process.WaitForExit(); // Aguarda o término do processo process.Close(); + myTask.Dispose(); + myTask = null; } - private string DrawTextArea(Rect rect, string text, string defaulttext, Event @event, int ID) { + private bool IsCompletedMyTask() + => myTask == null || myTask.IsCompleted; + + private string DrawTextArea(Rect rect, string text, string defaulttext, Event @event, TextEditor textEditor, GUIStyle style, int ID) { textEditor.text = text; textEditor.SaveBackup(); textEditor.controlID = ID; textEditor.position = rect; - textEditor.style = GUI.skin.textArea; + textEditor.style = style; textEditor.multiline = true; textEditor.isPasswordField = false; textEditor.DetectFocusChange(); @@ -209,16 +264,18 @@ public class UnityEditorTerminal : EditorWindow { else textEditor.DrawCursor(textEditor.text); break; } - if (textEditor.text.Length <= defaulttext.Length) { - textEditor.cursorIndex = - textEditor.selectIndex = - defaulttext.Length; - return defaulttext; + if (isHover) { + if (textEditor.text.Length <= defaulttext.Length) { + textEditor.cursorIndex = + textEditor.selectIndex = + defaulttext.Length; + return defaulttext; + } + if (textEditor.cursorIndex < defaulttext.Length) + textEditor.cursorIndex = defaulttext.Length; + if (textEditor.selectIndex < defaulttext.Length) + textEditor.selectIndex = defaulttext.Length; } - if (textEditor.cursorIndex < defaulttext.Length) - textEditor.cursorIndex = defaulttext.Length; - if (textEditor.selectIndex < defaulttext.Length) - textEditor.selectIndex = defaulttext.Length; textEditor.UpdateScrollOffsetIfNeeded(@event); return textEditor.text; diff --git a/README.md b/README.md new file mode 100644 index 0000000..bdd9a89 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Unity Editor Terminal +## EN-US +#### ⚠️ Attention +> The development of this package is done during my free time.
+> If you encounter any bugs and go through the ritual of opening an issue, depending on my available free time, I will act as justice, which may be slow but never fails.
+> And if you have feedback, just open an issue as well. +### Installation +
Installation using scoped registries.
+
![](Documentation~/Image/install_npm_NoWarng.png)
+
Installation using add package from git url.
+
![](Documentation~/Image/install_github_NoWarng.png)
+### Usage Mode +
The Set button is used to set the WorkingDirectory of the command prompt.
+
![](Documentation~/Image/UseMode1.png)
+
The Terminal popup defines which command prompt will be used.
+
![](Documentation~/Image/UseMode2.png)
+
Just use the terminal to enter any command, and it will take care of the rest.
+
![](Documentation~/Image/UseMode3.png)
+ +##### [If you'd like to help me](https://www.paypal.com/donate/?business=VN4RAWDSA2PBA&no_recurring=0¤cy_code=BRL) +## PT-BR +#### ⚠️ Atenção +> O desenvolvimento deste pacote é feito durante meu tempo liver.
+> Se econtrar algum bug e aquele ritual abrir uma issues, dependendo
+> tempo liver que eu tenha agirei que nem a justiça tarda mas não falha.
+> E se tiver um feedback e só abrir um issues também. +### Instalação +
Instalação usando scoped registries.
+
![](Documentation~/Image/install_npm_NoWarng.png)
+
Instalação usando add package from git url.
+
![](Documentation~/Image/install_github_NoWarng.png)
+### Modo de uso +
O botão Set é usado para definir o WorkingDirectory do prompt de comando.
+
![](Documentation~/Image/UseMode1.png)
+
O popup Terminal define qual prompt de comando vai ser usado.
+
![](Documentation~/Image/UseMode2.png)
+
Já terminal e só passar algum comando que ele se encarrega do resto.
+
![](Documentation~/Image/UseMode3.png)
+ +##### [Caso queira me ajudar](https://www.paypal.com/donate/?business=VN4RAWDSA2PBA&no_recurring=0¤cy_code=BRL) \ No newline at end of file diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..05aeccb --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2fffd451c2c063b4b94da3761729042f +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 21b7419..fe43d38 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "com.cobilas.unity.editorterminal", "version": "1.0.0", "description": "Pacote para unity3d que adiciona um terminal.", + "displayName": "Unity Editor Terminal", + "type": "tool", + "unity": "2017.4", "licensesUrl": "https://github.com/BelicusBr/com.cobilas.unity.editorterminal/blob/main/LICENSE.md", "changelogUrl": "https://github.com/BelicusBr/com.cobilas.unity.editorterminal/blob/main/CHANGELOG.md", "main": "index.js", @@ -25,8 +28,5 @@ "bugs": { "url": "https://github.com/BelicusBr/com.cobilas.unity.editorterminal/issues" }, - "homepage": "https://github.com/BelicusBr/com.cobilas.unity.editorterminal#readme", - "displayName": "Unity editor terminal", - "type": "tool", - "unity": "2017.4" + "homepage": "https://github.com/BelicusBr/com.cobilas.unity.editorterminal#readme" } \ No newline at end of file