focus-editor / focus

A simple and fast text editor
GNU General Public License v3.0
1.82k stars 99 forks source link

[Bug] Output window does not handle certain escape codes #404

Open MrStevns opened 3 months ago

MrStevns commented 3 months ago

Describe the bug I have been using focus to work with odin projects which so far is a pleasant experience. Recently however, their test module got a major makeover which focus does not seem to be able to handle.

From the conversation with obiwanus on Discord, the issue stems from focus not expecting or being able to handle the escape codes being produced.

To Reproduce

  1. Create a odin project like so:
package rendering

import "core:log"
import "core:testing"

@test
example :: proc(t: ^testing.T)
{
    log.info("Debug test")
}
  1. Create a focus-config file so you can run the odin project and get the output like so: > odin test /path/to/project/
  2. Run the test project via the command modal in focus

Expected behavior

[INFO ] --- [2024-08-17 07:52:29] Starting test runner with 1 thread. Set with -define:ODIN_TEST_THREADS=n.
[INFO ] --- [2024-08-17 07:52:29] The random seed sent to every test is: 39114654177527. Set with -define:ODIN_TEST_RANDOM_SEED=n.
[INFO ] --- [2024-08-17 07:52:29] Memory tracking is enabled. Tests will log their memory usage if there's an issue.
[INFO ] --- [2024-08-17 07:52:29] < Final Mem/ Total Mem> <  Peak Mem> (#Free/Alloc) :: [package.test_name]
[INFO ] --- [2024-08-17 07:52:29] [rendering.odin:9:example()] Debug test
rendering  [|                       ]         1 :: [package done]

Finished 1 test in 270µs. The test was successful.

Actual behaviour

[?25l[?7lrendering  [|                       ]    0/   1 :: example
[?7h1 thread                                 0/   1 :: total
]2;Odin test runner (0/1)\[?7lrendering  [|                       ]    0/   1 :: example
[?7h1 thread                                 0/   1 :: total
]2;Odin test runner (1/1)\[?7lrendering  [|                       ]         1 :: [package done]
[?7h
[?25h[INFO ] --- [2024-08-17 07:53:51] Starting test runner with 1 thread. Set with -define:ODIN_TEST_THREADS=n.
[INFO ] --- [2024-08-17 07:53:51] The random seed sent to every test is: 39368671393172. Set with -define:ODIN_TEST_RANDOM_SEED=n.
[INFO ] --- [2024-08-17 07:53:51] Memory tracking is enabled. Tests will log their memory usage if there's an issue.
[INFO ] --- [2024-08-17 07:53:51] < Final Mem/ Total Mem> <  Peak Mem> (#Free/Alloc) :: [package.test_name]
[INFO ] --- [2024-08-17 07:53:51] [rendering.odin:9:example()] Debug test
Finished 1 test in 151µs. The test was successful.

Screenshots Expected: image

Actual: image

focus-editor commented 3 months ago

Thanks for logging the issue.

However since it's a recent addition to Odin maybe you could reach out to ginger Bill and tell him that escape codes should only be used when the output is being sent to a terminal?

Other programs are able to detect this and not send escape codes. E.g. Jai does this.

MrStevns commented 3 months ago

Good point, I've created an issue there too. For reference: https://github.com/odin-lang/Odin/issues/4100

Feoramund commented 3 months ago

Unless this program intends to parse ANSI SGR codes, both color and cursor motion, then this is strictly an issue with Odin's ability to detect the presence of a TTY.