Skip to content

Commit

Permalink
#Update-vs1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BelicusBr committed Sep 8, 2023
1 parent 4fefdce commit fbdb993
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

Binary file added Documentation~/Image/UseMode1.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~/Image/UseMode2.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~/Image/UseMode3.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~/Image/install_github_NoWarng.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~/Image/install_npm_NoWarng.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions Editor/TextFile1.txt
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions Editor/TextFile1.txt.meta

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

97 changes: 77 additions & 20 deletions Editor/UnityEditorTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,103 @@
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<UnityEditorTerminal>();
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);
if (string.IsNullOrEmpty(WorkingDirectory))
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 =
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Unity Editor Terminal
## EN-US
#### ⚠️ Attention
> The development of this package is done during my free time.</br>
> 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.</br>
> And if you have feedback, just open an issue as well.
### Installation
<br>Installation using scoped registries.</br>
<br>![](Documentation~/Image/install_npm_NoWarng.png)</br>
<br>Installation using add package from git url.</br>
<br>![](Documentation~/Image/install_github_NoWarng.png)</br>
### Usage Mode
<br>The <kbd>Set</kbd> button is used to set the <kbd>WorkingDirectory</kbd> of the command prompt.</br>
<br>![](Documentation~/Image/UseMode1.png)</br>
<br>The <kbd>Terminal</kbd> popup defines which command prompt will be used.</br>
<br>![](Documentation~/Image/UseMode2.png)</br>
<br>Just use the terminal to enter any command, and it will take care of the rest.</br>
<br>![](Documentation~/Image/UseMode3.png)</br>

##### [If you'd like to help me](https://www.paypal.com/donate/?business=VN4RAWDSA2PBA&no_recurring=0&currency_code=BRL)
## PT-BR
#### ⚠️ Atenção
> O desenvolvimento deste pacote é feito durante meu tempo liver.</br>
> Se econtrar algum bug e aquele ritual abrir uma issues, dependendo</br>
> tempo liver que eu tenha agirei que nem a justiça tarda mas não falha.</br>
> E se tiver um feedback e só abrir um issues também.
### Instalação
<br>Instalação usando scoped registries.</br>
<br>![](Documentation~/Image/install_npm_NoWarng.png)</br>
<br>Instalação usando add package from git url.</br>
<br>![](Documentation~/Image/install_github_NoWarng.png)</br>
### Modo de uso
<br>O botão <kbd>Set</kbd> é usado para definir o <kbd>WorkingDirectory</kbd> do prompt de comando.</br>
<br>![](Documentation~/Image/UseMode1.png)</br>
<br>O popup <kbd>Terminal</kbd> define qual prompt de comando vai ser usado.</br>
<br>![](Documentation~/Image/UseMode2.png)</br>
<br>Já terminal e só passar algum comando que ele se encarrega do resto.</br>
<br>![](Documentation~/Image/UseMode3.png)</br>

##### [Caso queira me ajudar](https://www.paypal.com/donate/?business=VN4RAWDSA2PBA&no_recurring=0&currency_code=BRL)
7 changes: 7 additions & 0 deletions README.md.meta

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}

0 comments on commit fbdb993

Please sign in to comment.