GithubHelp home page GithubHelp logo

command_terminal's Introduction

Unity Command Terminal

A simple and highly performant in-game drop down Console.

gif

Command Terminal is based on an implementation by Jonathan Blow done in the Jai programming language.

Usage

Copy the contents from CommandTerminal to your Assets folder. Attach a Terminal Component to a game object. The console window can be toggled with a hotkey (default is backtick), and another hotkey can be used to toggle the full size window (default is shift+backtick).

Enter help in the console to view all available commands, use the up and down arrow keys to traverse the command history, and the tab key to autocomplete commands.

Registering Commands

There are 3 options to register commands to be used in the Command Terminal.

1. Using the RegisterCommand attribute:

The command method must be static (public or non-public).

[RegisterCommand(Help = "Adds 2 numbers", MinArgCount = 2, MaxArgCount = 2)]
static void CommandAdd(CommandArg[] args) {
    int a = args[0].Int;
    int b = args[1].Int;

    if (Terminal.IssuedError) return; // Error will be handled by Terminal

    int result = a + b;
    Terminal.Log("{0} + {1} = {2}", a, b, result);
}

MinArgCount and MaxArgCount allows the Command Interpreter to issue an error if arguments have been passed incorrectly, this way you can index the CommandArg array, knowing the array will have the correct size.

In this case the command name (add) will be inferred from the method name, you can override this by setting Name in RegisterCommand.

[RegisterCommand(Name = "MyAdd", Help = "Adds 2 numbers", MinArgCount = 2, MaxArgCount = 2)]

2. Using a FrontCommand method:

Here you still use the RegisterCommand attribute, but the arguments are handled in a separate method, prefixed with FrontCommand. This way, MaxArgCount and MinArgCount are automatically inferred.

This also allows you to keep the argument handling FrontCommand methods in another file, or even generate them procedurally during a pre-build.

[RegisterCommand(Help = "Adds 2 numbers")]
static void CommandAdd(int a, int b) {
    int result = a + b;
    Terminal.Log("{0} + {1} = {2}", a, b, result);
}

static void FrontCommandAdd(CommandArg[] args) {
    int a = args[0].Int;
    int b = args[1].Int;

    if (Terminal.IssuedError) return;

    CommandAdd(a, b);
}

3. Manually adding Commands:

RegisterCommand only works for static methods. If you want to use a non-static method, you may add the command manually.

Terminal.Shell.AddCommand("add", CommandAdd, 2, 2, "Adds 2 numbers");

command_terminal's People

Contributors

aganm avatar bgr avatar stillwwater avatar tatelax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

command_terminal's Issues

Static methods not called if asset is in the /Plugins/ folder

Hello!

I'm having trouble having static methods appear in the help-command, or being able to run at all if I have Command Terminal-folder in the /Plugins/ folder. Command Terminal works if it is outside the /Plugins/ folder.

My code:

using CommandTerminal;

public static class DebugTestCommand {
  [RegisterCommand(Help = "Outputs message")]
  static void CommandHello (CommandArg[] args) {
    Terminal.Log("Hello world!");
  }
}

[Question] Running what kind of methods?

In README this is defined as "in-game Console for calling C# methods". I haven't try this, but from the gif as well as the examples, it seem what you mean is calling custom commands?
IMO "calling C# methods" would suggest you can run arbitrary methods, something like:
Debug.Log(GetComponent<Camera>().fieldOfView)

unclear

it is still unclear how this works to me, how do i set what the command does?

Can you updates to Input System supports?

I tried to do it, but it failed because I'm not a programmer. I think this should be done by you, the developer. At least from what I saw when I just tried it, leveraging the Input System allows you to specify keys in the inspector as well.

How to make command group?

In previous issue you showed screenshot of ED group of multiple commands,
but I couldn't find out how to implement group command help. every command has same prefixes shows by a help query.

never assigned to warnings

When loading up Command Terminal in Unity, these (harmless) warnings come up:
[Warning] [None] [CS0649] Field 'Terminal.InputContrast' is never assigned to, and will always have its default value 0

[Warning] [None] [CS0649] Field 'Terminal.ShowGUIButtons' is never assigned to, and will always have its default value false

[Warning] [None] [CS0649] Field 'Terminal.RightAlignButtons' is never assigned to, and will always have its default value false

move cursor at end not working when pressing UP key

If I open the console first time, pressing UP or DOWN key always moves the cursor at the end...that is expected.
Then if I reopen the console using toggle key and press UP key, the cursor stays at position 0 and I need to manually move the cursor at the end of line with END key.

Typing is not showing up

The console opens normally, perfect, but when you type, nothing appears and neither does the result when you press enter.

When you close the console and open it again, it shows the result, but even the typing is the opposite, "help" comes out "pleh".

BUG Background isn't rendered. (workaround)

The background isn't rendered at all and I found why.
In Terminal.cs you use SetupWindow in Start, where window sizes are not always calculated and return 0.
It may still work in some cases, depending on the order your scripts compile.

The dirty trick I used to "fix" this issue
IEnumerator LateStart() { yield return null; SetupWindow(); }

And start the coroutine at the end of Start()
StartCoroutine(LateStart());

Command groups idea

So I was asked to move this here:

•Can you add something like "command groups" so when I have bunch of objects with similar commands like "testcube.jump" they won't show in help menu?

Is there a way to avoid displaying the Debug.Log?

I will always use it.

I have a question, is there any way to not show the Debug.
It shows up when I start terminal even when an internal error occurs.
I don't want it to show up during the game, what should I do?

It would be helpful if you could only show the logs you added in Terminal.

Parameters usability

I find current 'CommandArg[]' approach quite daunting, 'cose I am generating commands out of some other code and it should support different types like Vector3, Сolor, enums, etc.

It would be cool to have something like ReflexCLI way of doing things. So we can provide custom types
http://reflex.richardmeredith.net/documentation/index.php?title=Parameter_Processors

And it's possible to have commands like this:

    [ConsoleCommand]
    static int MultiplyAndFloor(float a, float b)

Which is ideal for usability, no workarounds needed

Readme suggestions

Not really an issue but a suggestion for readme.
2 things you should mention to make it work:

  • You need to add using CommandTerminal; to be able to register commands
  • and you need to have CommandArg[] args as a parameter even if you don't have any parameters. This confused me as it wasn't showing up in commands and there were no errors.

And great stuff! Thanks a lot!

Terminal background is transparent

Sometimes the black background is transparent.
After I change scene the background is just blinking once in black and then will be transparent again. How to fix this?

Deleting commands?

Can you expose some function to delete command and it's autocompletion word? I need this for few things

CVARS feature?

Can we have some kind of cvar feature as Valve games have.

so let's the implementation would be something like, and executing cl_showfps 1 will change the bool value?

[Cvar("cl_showfps"]
public bool ShowFps;

Command usage tip?

Is there any workaround to add an suggestion how to use a command?
lets say we have command "rate". how to output the tip like: "usage rate 25000"
instead of the default error "'rate' requires exactly 1 argument? thanks.

Binding hotkey to F1-F12 doesn't register first letter in input

I have a Swedish QWERTY keyboard so "`" doesn't work for me as a hotkey ("§"-key doesn't work either, but I think that's a limitation from Unity itself. American "`" is positioned at "Ö" on the image I linked).

So I changed the hotkey to "f1" instead. The command terminal works but the first letter isn't registered when typing into the input.

Also: I changed the hotkey to "tab" and it enables the terminal but unable to close it again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.