alda-lang / alda

A music programming language for musicians. :notes:
https://alda.io
Eclipse Public License 2.0
5.59k stars 286 forks source link

Terminal colors don't work on Windows #365

Closed severak closed 3 years ago

severak commented 3 years ago

Hi, I tested new version of Alda and noticed few minor inconveniences:

terminal color support is broken

I think this is because I use Windows 7 which does not support ANSI escapes by default.

This is just little annoying, solution is IMHO not use these escape codes on older Windows.

C:\severak\alda-js\examples>alda repl
nREPL server started on port 56227 on host localhost - nrepl://localhost:56227
←[34m █████╗ ██╗     ██████╗  █████╗
██╔══██╗██║     ██╔══██╗██╔══██╗
███████║██║     ██║  ██║███████║
██╔══██║██║     ██║  ██║██╔══██║
██║  ██║███████╗██████╔╝██║  ██║
╚═╝  ╚═╝╚══════╝╚═════╝ ╚═╝  ╚═╝←[0m

←[36m    Client version: 2.0.0
    Server version: 2.0.0←[0m

←[1mType :help for a list of available commands.←[0m

alda>

nothing happens without instrument

If I start alda repl and trying alda> a nothing happens. I need to write instrument name: alda> piano: a.

bad parsing of play parameters

play command without -f does nothing

C:\severak\alda-js\examples>alda play blade-runner.alda
Playing...

takes some time but actually no sound is produced while this works as expected:

C:\severak\alda-js\examples>alda play -f blade-runner.alda
Playing...
daveyarwood commented 3 years ago

Hi @severak , thanks for the heads up about these issues!

The last 2 I think we can consider to be working as intended. The correct command is alda play -f path-to-file.alda, and Alda will accept notes without an instrument as valid -- you just won't hear anything unless an instrument is specified.

As for the lack of color support, it looks like I chose a terminal color library for Go that doesn't support Windows. Whoops! :grimacing:

I'll keep this issue open and look into using a different library with Windows support.

In the meantime, could you try setting the environment variable NO_COLOR to true? That should disable colors altogether and remove those weird looking ANSI escape codes.

daveyarwood commented 3 years ago

I found this, which confirms that the Aurora library doesn't support Windows: https://github.com/logrusorgru/aurora/issues/2

daveyarwood commented 3 years ago

As a short term band-aid, I can make it so that colors are disabled automatically if you're running Windows. I'll look into doing that first, then look into using a cross-platform terminal color library.

severak commented 3 years ago

In the meantime, could you try setting the environment variable NO_COLOR to true?

works for me

As a short term band-aid, I can make it so that colors are disabled automatically if you're running Windows. I'll look into doing that first, then look into using a cross-platform terminal color library.

I think newer Windows supports these ANSI escapes. See https://en.wikipedia.org/wiki/ANSI_escape_code#DOS,_OS/2,_and_Windows

So this is issue only for older versions (pre Windows 10).

The troubles with alda play without -f and notes without instruments is that there is no error message. If you try alda export somefile.alda -o somefile.mid you will get error message about missing parameters.

daveyarwood commented 3 years ago

Ah, good to know that this only affects older versions of Windows!

Good point about the lack of error message when running alda play without options. I'll see if I can improve that.

daveyarwood commented 3 years ago

@severak I've made an experimental change that will attempt to detect when your terminal can't interpret ANSI color codes, and if so, it won't include them.

I've uploaded a build here: https://daveyarwood.keybase.pub/alda/builds/alda-20210630205132.zip?dl=1 (The zip file contains the client and player for all platforms, but the only file you need in this case is client/windows-$ARCH/alda.exe, where $ARCH is either 386 or amd64 depending on if your system is 32 or 64 bit.)

Would you mind giving this build a try and confirming that the output looks good (i.e. no color, no weird escape sequences) without having to set NO_COLOR?

severak commented 3 years ago

@daveyarwood this does not work.

Also - it seems after replacing alda.exe, I can't use alda repl command. Probably some Windows Firewall glitch. This can be fixed by running alda doctor.

alda> piano: a
ERROR: dial tcp 127.0.0.1:49743: connectex: No connection could be made because
the target machine actively refused it.
Jul  2 16:32:43 WRN repl/player_management.go:177 > Player process unreachable.
error="dial tcp 127.0.0.1:49743: connectex: No connection could be made because
the target machine actively refused it." player={"Expiry":1625124292903,"ID":"ae
u","Port":49743,"ReadError":null,"State":"ready"}
Jul  2 16:32:48 WRN repl/player_management.go:177 > Player process unreachable.
error="dial tcp 127.0.0.1:49743: connectex: No connection could be made because
the target machine actively refused it." player={"Expiry":1625124292903,"ID":"ae
u","Port":49743,"ReadError":null,"State":"ready"}
daveyarwood commented 3 years ago

Hmm, interesting. This might be some kind of Windows security feature?

Try running alda shutdown to kill all player processes. Then, try alda repl again.

daveyarwood commented 3 years ago

I think the original issue (weird characters being printed in terminal environments that don't support ANSI escape codes) is fixed now in Alda 2.0.1, so closing this issue.

I'm happy to continue troubleshooting the other issue if needed, either on Slack or as a separate issue :)