68 Commits
Author SHA1 Message Date
Andy Jordan 7b6f602405 Add accessible screen reader mode
This adds the `EnableScreenReaderMode` command-line switch which
defaults to true if an active screen reader is detected.

In screen reader mode, the existing `ForceRender()` function is replaced
by `RenderForScreenReader()` which uses a differential rendering
approach to minimize extraneous output to the terminal, allowing the use
of screen readers better than ever before.

The differential rendering relies on calculating the common prefix of
the `buffer` and `previousRender` strings. Nearly all necessary changes
are consolidated in the new rendering function.

Features known not to be supported:

* Colors: as this necessitates redrawing to insert color sequences after
  the input is received and the AST parsed.
* Inline predictions: as this by definition changes the suffix and thus
  requires endless redrawing.
* List view predictions: since the render implementation never calls
  into the prediction engine, this is not available either.
* Menu completion: well, it "works" since it's not disabled and does its
  own rendering, but no effort has been made to improve `DrawMenu()`, so
  it's not accessible (and I'm not sure it could be given our current
  constraints).

Features known to be partially supported:

* Text selection: mark and select commands work as intended, but provide
  no visual indication.
* Multiple lines: as in newlines work fine, but there is no continuation
  prompt.
* Visually wrapped lines: editing above a wrapped line redraws all
  subsequent lines and hence is noisy.
* Status prompt based commands: what-is-key, digit-argument, and most
  notably, forward/backward incremental history search all render a
  "status prompt" on the line below the user's input buffer. This _is_
  supported; however, it can be noisy since it necessarily has to render
  the whole buffer when the input buffer changes, including the status
  prompt (and search text). But what it's reading is almost always going
  to be relevant.

Everything else should generally work, even Vi mode, and the tests pass.
That said, this isn't perfect, and moreover the approach specifically
doesn't attempt to enable things from the ground up. There may be
features that are available but turn out not to be accessible (like
`MenuComplete`) and I believe they should be left as-is.

Specifically tested with NVDA on Windows and VoiceOver on macOS within
VS Code's integrated terminal, with shell integration loaded, and Code's
screen reader optimizations enabled.
2025-08-27 17:46:47 -07:00
Enan Ajmain 6808c18762 Add support for upcasing, downcasing, and capitalizing word (#3365) 2022-07-18 10:26:40 -07:00
Dongbo Wang f46f15d2d6 Improve RecomputeInitialCoords to be more robust and handle a couple special cases (#3074) 2022-01-03 16:40:25 -08:00
Maxime Labelle 1966609701 [vi-mode] Undo now leaves the cursor under the position at the start of the deletion (#2045) 2021-09-21 23:04:43 -07:00
Maxime Labelle 0de63689c4 Remove LineIsMultiline in favor of multi-line agnostic algorithms (#1125) (#2047) 2021-02-11 15:57:37 -08:00
Maxime Labelle 9d5b41f1f6 Refactor the usage of _clipboard (#2022) 2021-02-09 22:14:12 -08:00
Maxime Labelle 47fb95728c Make d0 to delete to the start of the current logical line in a multiline buffer in VI mode (#2002) 2021-02-09 21:45:37 -08:00
Dongbo Wang fd1265e385 Add the prediction ListView and also hook up with the CommandPrediction APIs introduced in PS 7.1 (#1909) 2020-11-03 14:17:37 -08:00
Dongbo Wang 67f09a4136 Refactor 'SelfInsert' to avoid duplicate logic (#1510) 2020-05-09 15:44:41 -07:00
Dongbo Wang 9e6c6b9481 Add basic support for inline predictive suggestion (#1496) 2020-05-09 15:44:04 -07:00
Dongbo Wang 958ce3aeb2 Fix a few VI edit mode issues (#1262) 2020-01-07 13:08:39 -08:00
Carl Morris 9bc2a6502a Set cursor via the public API SetCursorPosition in AcceptLineImpl for better buffer check (#1182)
Instead of _console.SetCursorPosition(), use public API SetCursorPosition so that existing end of buffer checks can be performed.
2019-11-14 10:42:23 -08:00
Maxime Labelle f25a089290 Supporting line wise yanks, including paste and undo. (#811) 2019-11-08 14:42:13 -08:00
Carl Morris 175d42e60b Correct cursor jumping from line 2 to line 1 due to line 1 being empty. (#1108)
- Reduce code duplication by reusing GetBeginningOfLinePos in InsertLineAbove.
- Correct newline search in GetBeginningOfLinePos (HOME) and InsertLineAbove to not ignore first character in the buffer which
might be a new line.
- Manifests as cursor jumps to line 1, because line 1 is blank, when triggered with cursor anywhere on line 2.
2019-10-29 16:10:14 -07:00
Jason Shirk a7af25aa37 Stop dispatching on ConsoleKeyInfo (#831)
There are likely issues introduced by this PR,
but I'm merging for a new Beta so this code gets more testing.

* Introduce PSKeyInfo type alias
* Explicit conversions b/w ConsoleKeyInfo and PSKeyInfo
* Change tests to use actual ConsoleKeyInfo data
* Add fr-FR keyboard layout tests
* Add KeyInfo-ru-RU-windows.json (#839)

All impossible without Shift shortcuts labeled as "Investigate: true"
Alt+Spacebar tracked by windows itself

* Add KeyInfo for Polish (Programmers) layout on Windows and Linux (#870)

On Windows *Alt+Spacebar* is hijacked by Windows
On Linux any *Alt+F1-12* combination was not detected
2019-03-20 16:14:05 -07:00
Jason Shirk bc40ae6f6b Remove uses of CSI # S / ScrollConsoleScreenBuffer (#790)
This fixes some weird issues in WSL and some Linux terminals.

This also works around a Windows 1809 Console bug for the Ctrl+l binding
to clear the screen by using the same escape sequence that bash uses.

Fix #724
2018-11-04 19:12:52 -08:00
Jason Shirk 46d232c22a s/PSReadline/PSReadLine/g
I was terribly inconsistent.

This is a breaking change, though unlikely to cause troubles.
The apis are mostly used in PowerShell scripts which is not
case sensitive.
The cmdlet name change is also mostly safe.

At any rate, this is version 2.0 and breaking changes should be OK.
2017-11-25 21:59:55 -08:00
Jason Shirk 9094f1246b Generate parts of the about topic
To keep the about topic up to date, the function descriptions and key
binding information is now generated after a build.
2017-11-24 22:11:13 -08:00
Jason Shirk 85c30fc238 Ignore negative count in backspace/delete
Fix #502
2017-11-04 09:42:12 -07:00
Jason Shirk bff16f4beb Correct resources namespace 2017-09-04 23:20:37 -07:00
Josh Soref f1208ccc0c add space to switch-case statement in CommandValidationVisitor.UnresolvedCommandCouldSucceed 2017-09-02 21:03:19 -07:00
Josh Soref ff80a13550 Spelling comments
* spelling: comments in src/Microsoft.PowerShell.PSReadLine
2017-09-02 21:03:11 -07:00
Jason Shirk 1a623b9327 Replace COORD with Point except in ScreenCapture 2017-09-02 14:43:03 -07:00
Jason Shirk e2fb174742 Fix rendering artifacts from shorter renders 2017-08-27 15:38:32 -07:00
Jason Shirk 691c6b10e2 Basic ANSI escapes working 2017-08-14 08:56:20 -07:00
Jason Shirk d8c368f79e Remove unused methods 2017-07-31 17:25:30 -07:00
Jason Shirk 4aba251bdb Remove unused using directives 2017-07-31 16:44:06 -07:00
Jason Shirk a7c0a907e1 Use null coalescing operator 2017-07-31 16:38:43 -07:00
Jason Shirk 012ec295e5 Use pattern matching w/ is/as 2017-07-31 16:33:03 -07:00
Jason Shirk fc55704f83 Inline out variable parameters 2017-07-31 16:24:57 -07:00
Jason Shirk b823045bb2 Remove unnecessary ref on parameter to PlaceCursor 2017-07-31 15:55:29 -07:00
Jason Shirk 6c7c3fd026 Remove Ding on delete backwards at start of line
We don't need to emulate GNU readline perfectly - and there are many
complaints about this particular ding, so I've removed it.

Fix #422
2017-07-25 14:21:30 -07:00
Jason Shirk (POWERSHELL) e0579e1a3d Merge branch 'master' of https://github.com/srdubya/PSReadLine into srdubya-master 2016-05-02 13:22:57 -07:00
srdubya 2a254e6325 Found a cleaner way to fix defect #380. 2016-04-30 14:58:57 -06:00
Jason Shirk (POWERSHELL) 04c7233b46 Globally suppress 'default args should not be used' 2016-04-27 16:36:50 -07:00
jason@truewheels.net 64ffb085e0 Merge branch 'master' of https://github.com/rkeithhill/PSReadLine into rkeithhill-master
Conflicts:
	PSReadLine/PSReadLine.csproj
	PSReadLine/PSReadLineResources.Designer.cs
	PSReadLine/PSReadLineResources.resx
	PSReadLine/ReadLine.cs
2015-12-16 09:41:00 -08:00
jason@truewheels.net 8691e88595 Initial refactor console api usage
To get the unit tests passing in VS2015, and to help w/ possible future hosts,
I've moved most of the console api usage to a class, which is then mocked
in the unit tests.
2015-12-06 09:05:37 -08:00
Keith Hill b0b441c080 Added InsertLineAbove and InsertLineBelow functions and set them up to key bind to Ctrl+Enter and Ctrl+Shift+Enter in Windows mode. Not being an emacs person, I'm not sure what key bindings these two functions would bind to. I also added unit tests for the two functions as well as a unit test for what I believe is a bug in the BeginningOfLine (home) function when in multiline mode. I also updated the project to have the appropriate default namespace so that the resource file gets re-generated with the correct resource name without having to resort to hacking the csproj file. There was also an issue with trying to run unit tests because the unit test setup of PSReadline sets engineInstrincs to null and that caused a null reference exception which I worked-around by testing for null first. 2015-07-20 19:54:33 -06:00
srdubya ab52d2b642 1st attempt at merge with #251. 2015-06-20 16:47:33 -06:00
Jason Shirk (POWERSHELL) f4ee589ec0 Right click w/ multiple lines pasted as a one line
This problem only happened in ValidateAndAcceptLine
It also only happened if validation failed for any reason.

The fix is to insert a newline even if validation failed if we still have pending input.
If there is no pending input, we don't want to insert the newline, as this is the common
case and people will not want to delete the blank line from the inserted newline.
2015-06-18 18:57:07 -07:00
Jason Shirk (POWERSHELL) 94a6ba40c9 Fix/suppress various FxCop errors 2015-06-18 18:24:23 -07:00
Jason Shirk (POWERSHELL) c986e0eae5 Rename namespace PSConsoleUtilities to Microsoft.PowerShell 2015-06-18 15:32:20 -07:00
Jason Shirk (POWERSHELL) 6408a4c96c Add copyright header 2015-06-18 15:04:49 -07:00
srdubya 6080c5fe13 Merged CJK language support from Jason's upstream (#243). 2015-06-06 05:33:55 -06:00
srdubya 39f37093ec Sync'd with upstream. 2015-03-08 07:58:49 -06:00
jason@truewheels.net c11dda5292 Recognize debugger pseudo-commands
ValidateAndAcceptLine was rejecting debugger commands like 's' or 'k'.
Now we check if we are debugging and accept these fake commands.

Fixes #199
2015-02-07 22:59:04 -08:00
jason@truewheels.net 17856e99a1 Remove demo mode
Demo mode doesn't work right now, and I found a better alternative
here:  https://github.com/Code52/carnac

Fixes #192
2015-01-26 19:45:41 -08:00
jason@truewheels.net d6fafe0327 Clear status message in CancelLine
Fixes #189
2015-01-21 09:19:26 -08:00
jason@truewheels.net e2311b0a99 Support Cancel/Abort DigitArgument
There was an exception with input like:

a Alt+1 Ctrl+C

CancelLine was clearing the buffer, but didn't reset _current.
That fixes the exception, but it still clears the input line
when called to terminate DigitArgument, so instead we do something
similar to how interactive history search is terminated.

Fixes #184
2015-01-16 09:10:41 -08:00
jason@truewheels.net 4dae28898c ValidateAndAcceptLine improvements
Script block arguments are now only validated as arguments to specific
cmdlets (which are in a user modifiable whitelist.)

A custom validation handler must now throw an exception to report an error,
returning an object is now ignored.

A sample custom validation handler was added to demonstrate typo correction.

Fixes #162
2015-01-15 09:19:09 -08:00