Repository: microsoft/terminal (language: cpp)

Issue:
Incoming text is periodically not read by screen readers
### Windows Terminal version (or Windows build number)

1.9.1942.0

### Other Software

Screen readers tested: Narrator, NVDA alpha-23553,3c29f9ad, observed while running in WSL2 Ubuntu in case that is somehow relevant

### Steps to reproduce

/CC @codeofdusk per our previous discussion about this, @carlos-zamora 

This appears to happen Intermittently, but for me I can fairly reliably reproduce this when I'm using Docker to run the postgres cli tool to interact with a Postgres database.

```sh
docker run -it postgres:13.3 psql -h db_host -U db_user
```

I would execute the following commands:

1. `\c <database>` to use a database
2. \d <table> to describe a table

### Expected Behavior

Incoming text continues to be reliably read by both NVDA and Narrator

### Actual Behavior

Even though new text would be written on-screen, both NVDA and Narrator would fail to read it. I am able to use object navigation to manually go upwards in NVDA to read the newly written text, but that's not a practical solution.

The fact that Narrator is also vulnerable to this makes me suspect a bug in Terminal itself.

Restarting either screen reader does not fix it.


Discussion / hints:
I'm not sure this isn't already tracked somewhere (probably in https://github.com/microsoft/terminal/issues?q=is%3Aopen+is%3Aissue+label%3AArea-Accessibility), but I'll tag it up assuming it isn't. Thanks!
Nope, this looks like a new bug (I asked him to file here).
Curious, does this repro in conhost?
I believe not from memory but let me test this and I'll double confirm by the end of the week.
Confirmed that its only affecting terminal, and I was able to reproduce it 100% of the time.

1. Set up an instance of postgres (I did it via docker on my development machine)
2. Connect to Postgres:

```
docker run -it --rm postgres:13.3 psql -h db -U postgres
Password for user postgres:                                                                                                          
psql (13.3 (Debian 13.3-1.pgdg100+1), server 12.6 (Debian 12.6-1.pgdg100+1))                                                         
Type "help" for help.                                                                                                                
                                                                                                                                     
postgres=# \l                                                                                                                        
                                  List of databases                                                                                  
     Name     |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges                                                  
--------------+----------+----------+------------+------------+-----------------------                                               
 applications | postgres | UTF8     | en_US.utf8 | en_US.utf8 |                                                                      
 postgres     | postgres | UTF8     | en_US.utf8 | en_US.utf8 |                                                                      
 template0    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +                                               
              |          |          |            |            | postgres=CTc/postgres                                                
 template1    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +                                               
              |          |          |            |            | postgres=CTc/postgres                                                
(4 rows)                                                                                                                             
                                                                                                                                     
postgres=# \c applications                                                                                                           
psql (13.3 (Debian 13.3-1.pgdg100+1), server 12.6 (Debian 12.6-1.pgdg100+1))                                                         
You are now connected to database "applications" as user "postgres".                                                                 
```

All output just before the command `\c applications` to connect to the applications database reads fine. All new incoming text after that refuses to read, even if I exit the docker container.
Any news on this?

This is something that I run into every day, and can reproduce easily.
Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
![image](https://user-images.githubusercontent.com/18356694/91237459-5cbb0c80-e700-11ea-9347-b9b1ec2813b1.png)
That way you'll be notified of any updates to this thread.
Received another report of this as nvaccess/nvda#13075, but I personally can't repro. Cc @carlos-zamora.
Wondering if there's anything I can do to help with reproduction of this bug? As I am able to reproduce this daily and it is a massive pain when output stops being read.
If you'd like to take a look at the code yourself and investigate, we'd love a PR ☺️ Otherwise at this point it's just waiting for us to have time to come back to this and actually look into it ourselves. Hopefully sometime in the next 6 mos? 
I suspect that the impending switch to UIA notifications will help with this. CC @carlos-zamora @DHowett 
I'm tossing this to @carlos-zamora if he gets a free moment to confirm that this is actually fixed by #12358. 
We believe that this should be fixed by #12358 (which should ship in the next hotfix version of the Terminal soon<sup>tm</sup>). We have _not_ been able to confirm however. 
> We believe that this should be fixed by #12358

In theory yes, but in practice no. NVDA doesn't yet leverage UIA notifications (see PR nvaccess/nvda#13261) because I want to think carefully about how that should work, and I haven't yet had the cycles to work further on it.
Okay thanks for the clarification. Is there an upstream issue on NVDA that we can close this as a duplicate of? (for housekeeping purposes)
/dup https://github.com/nvaccess/nvda/pull/13261
Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!
I've seen this bug with Narrator, so I believe this is actually a Terminal issue, not NVDA specific.
@Neurrone Have you seen this issue with Narrator and Windows Terminal 1.12.10730 or higher? That is the first version that shipped with #12358, which specifically addresses this issue for Narrator.
@codeofdusk told me there's been a lot of reports for this one and he has a consistent repro. Reopening it and assigning it to the current milestone.
I discussed this with @simon818. We're both able to consistently repro this by outputting enough text to fill the screen:

1. Start `wt`.
2. Echo 10,000 "a" characters.
3. Then, `echo hello`.

Expected: a `textChange` event is received, NVDA diffs the screen and says "hello".

Actual: After the screen is filled, `textChange` (and consequently autoread) stops.

UIA notifications are unaffected (or at least not as severely affected).
Hi I experiment this bug all the days as I work a lot with terminal. I had to switch back to the old and stupid cmd to not being bothered by this severe issue.
My question is the following: beside this tracker which is opened since 1 and half year, is there some schedule to take care of the problem. Is there enough data gathered to study for a solution plan? Can I allow myself to hope to see it fixed and in how much time?
Thanks.
PS: I don't want to complain,it's just to ask.
Well, now that we've got a consistent repro, we'll try and get this in for 1.17, due out sometime in January. This thread has a lot of back and forth on the root cause. 

I reckon, based on the last post, that this is due to the notifications not being sent when the buffer circles (the viewport's not changing in this case, but it _seems_ like it is, and it _should_ send a notification).
Closing as no repro. @codeofdusk and I chatted about this. Funny enough, the repro steps he provided were posted the day before an update, so there's a chance that the update fixed it.

If we get more reports of this, we'll open it up again.
I can confirm that the issue still persists as of the Windows Terminal preview version 1.16.3464.0. When the viewport of the terminal is fully filled (I do this by running the "dir" command in a large folder multiple times), the subsequent command that has an output (such as "echo a") will not produce the UIA_textchange event, and therefore cannot be detected and autoread by the screen reader. Interestingly, when I type individual characters such as "e", "c", "h", "o", "space", "quote", "a", and "quote", all of them produce the correct textchange event. However, once I press enter, there is no textchange event emitted from the TermControl, only a UIA_notification is produced, which the NVDA screen reader currently ignores. My environment is as follows: NVDA 2022.4 fresh install, and Windows 11 Pro version 22H2 (OS Build 22621.1105).
@carlos-zamora  I'm not sure if this counts as a partial reproduction, but I've attached the debug log of NVDA in case it might be useful. 
The first log shows the behavior when typing `echo "a"` on a freshly opened terminal, i.e. a blank viewport (expected behavior).
[first_case.txt](https://github.com/microsoft/terminal/files/10470392/first_case.txt)
The second log shows the behavior when typing `echo "a"` on a full viewport (typing `dir` a bunch of times) (actual behavior).
[second_case.txt](https://github.com/microsoft/terminal/files/10470393/second_case.txt)
Observe that in the second case, the textchange event is not emitted after pressing enter.

Fix patch:
diff --git a/src/renderer/uia/UiaRenderer.cpp b/src/renderer/uia/UiaRenderer.cpp
index 4eb5abccd5f..206f2193a86 100644
--- a/src/renderer/uia/UiaRenderer.cpp
+++ b/src/renderer/uia/UiaRenderer.cpp
@@ -175,6 +175,7 @@ try
     {
         _newOutput.append(newText);
         _newOutput.push_back(L'\n');
+        _textBufferChanged = true;
     }
     return S_OK;
 }


Test patch: