60 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
Dan Thompson 4d78ce153d Add the TerminateOrphanedConsoleApps option on Windows to kill orphaned console-attached process that may mess up reading from Console input (#3764) 2023-08-09 10:51:26 -07:00
Dongbo Wang 8df5b6ba08 Update PSReadLine corresponding to the prediction interface update (#2225) 2021-02-22 18:17:26 -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 9e6c6b9481 Add basic support for inline predictive suggestion (#1496) 2020-05-09 15:44:04 -07:00
Dongbo Wang d3eac095cc Update docs to reflect the new -Chord parameter to Get-PSReadLineKeyHandler (#1438) 2020-03-31 11:30:47 -07:00
theaquamarine fcb2c9dd48 Add a -Chord parameter to Get-PSReadLineKeyHandler (#1298) 2020-03-31 10:11:54 -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
Parker Snell c6dabcf9f9 Add script block vi mode indicator option 2018-09-12 10:23:59 -07:00
Jason Shirk e33dabb46c Replace -*Color parameters with single parameter
To make it a bit easier to create themes, the various parameters to
Set-PSReadLineOption to set colors has been replaced with a single
parameter accepting a Hashtable.

The valid keys are:

-- ContinuationPrompt: The color of the continuation prompt.
-- Emphasis: The emphasis color, e.g. the matching text when searching history.
-- Error: The error color, e.g. in the prompt.
-- Default: The default token color.
-- Comment: The comment token color.
-- Keyword: The keyword token color.
-- String: The string token color.
-- Operator: The operator token color.
-- Variable: The variable token color.
-- Command: The command token color.
-- Parameter: The parameter token color.
-- Type: The type token color.
-- Number: The number token color.
-- Member: The member name token color.
2017-11-26 10:51:41 -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
Parker Snell 5b283a947e Implement VT input on Windows (#564)
Fix #158.
2017-11-16 22:22:51 -08:00
Jason Shirk 3412b1a91b ShowKeyBindings and Get-PSReadlineKeyBinding improvements
Fix #114
2017-11-11 22:55:59 -08:00
Jason Shirk be27509fa9 Add a default description for ScriptBlock key binding
Fix #505
2017-11-04 08:40:38 -07:00
Jason Shirk 63d2dcf6da Portable custom key bindings
Rewrote the custom key binding code to be more portable.

Some runtime checks are necessary because of impossible to reconcile
differences.

Some Win32 P/Invoke calls are still needed due to lack of information in
the ConsoleKeyInfo.

Some keys are currently not available on Linux due to a CLR bug, others
aren't available ever because terminals don't unique character sequences
for a given key press that might differ in just the Shift or Ctrl state.
2017-10-15 22:03:56 -07:00
Jason Shirk a7efcd27ca XML comment cleanup 2017-09-03 00:06:41 -07:00
Andrew Schwartzmeyer c994e145b4 Set DefaultEditMode to Emacs on Linux / OS X 2017-09-02 21:24:07 -07:00
Jason Shirk 245000c3b7 Remove #region 2017-09-02 21:09:40 -07:00
Jason Shirk de5d7bd701 Merge Foreground/Background options
Fix selection to use escape sequence for invert - it doesn't look that
great when there are too many colors, but it will work with any
customization.

Also fix tests to work after previous commit.
2017-08-14 08:56:22 -07:00
Jason Shirk 138b226ea8 Add basic support for custom colors
Colors can now be customized using RGB (like #RRGGBB) or with escape
sequences.
2017-08-14 08:56:21 -07:00
Jason Shirk ef1bb9be17 Get red prompt working again
With no portable way to scrape, displaying red in the prompt is harder.

To start, there is a new option to specify the end of the prompt text so
you can specify exactly what should turn red.

Many folks won't use this, so there are some smarts added at startup to
analyze the prompt function - if it's "pure", as in, doesn't call any
methods or commands, we call it and infer the invariant part of the
prompt, basically the last non-whitespace character plus the trailing
whitespace.
2017-08-14 08:56:21 -07:00
Jason Shirk 72d1a31002 Use null propagation 2017-07-31 17:33:46 -07:00
Jason Shirk 2eb74eb0f4 Remove redundant qualifiers 2017-07-31 17:12:44 -07:00
Jason Shirk d5566e7a76 Avoid redundant default arguments 2017-07-31 17:04:42 -07:00
Jason Shirk a02554d25d Use expression body property/method 2017-07-31 16:51:25 -07:00
Jason Shirk fc55704f83 Inline out variable parameters 2017-07-31 16:24:57 -07:00
Jason Shirk (POWERSHELL) 04c7233b46 Globally suppress 'default args should not be used' 2016-04-27 16:36:50 -07:00
Jason Shirk (POWERSHELL) 9273a7ef46 Fix sample for strict mode+better custom handler error msg
Fixes #304
2016-01-17 09:39:59 -08:00
Jason Shirk (POWERSHELL) 618b4971ef Move some apis to be internal 2016-01-17 08:52:40 -08:00
jason@truewheels.net 6903f044db Fix indentation. 2015-11-29 10:40:37 -08:00
srdubya ab52d2b642 1st attempt at merge with #251. 2015-06-20 16:47:33 -06:00
Jason Shirk (POWERSHELL) 2788ce6832 Use full namespace 2015-06-18 19:43:03 -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 796e90bc60 Corrected a few uncessary file differences, mostly indentation issues. 2015-06-06 13:05:05 -06:00
srdubya c5820b938d Switched from -ChangeCursor to -ViModeIndicator[Cursor|StatusLine|None]. StatusLine does not work yet. 2015-03-21 06:34:20 -06:00
srdubya 8a2c8a988f Added the changing of the console cursor size when in command/insert mode. Use the -ChangeCursor option to control. 2015-03-15 13:56:48 -06:00
srdubya 39f37093ec Sync'd with upstream. 2015-03-08 07:58:49 -06: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
srdubya 554012d9c7 Surrounding Get-PSReadlineKeyHandler vi command mode keys in "<>". 2014-12-30 07:18:10 -07:00
srdubya 16f0ad9c5c Sync'd with Upstream. 2014-12-22 18:27:22 -07:00
srdubya 3a541d9db5 Removed mode, in preparation for merge with GitHub. 2014-12-19 10:57:18 -07:00
jason@truewheels.net 2082f1858b Add Remove-PSReadlineKeyHandler
Sometimes you just don't want a key binding for whatever reason, so now you can remove a binding.

Note that unbound keys won't fall back to what happens in "cooked" editing mode.
In raw editing mode (which is what PSReadline uses), conhost only handles a very small
set of key bindings and those bindings weren't available to PSReadline anyway.

Fixes #154
2014-10-14 09:43:42 -07:00
jason@truewheels.net eaffca3381 Add -ValidationHandler for ValidateAndAcceptLine
To support custom validation, for e.g. to allow someone
to reject command lines where arguments are not valid,
you can now specify a custom validation handler script block.
2014-09-11 09:13:09 -07:00
jason@truewheels.net 15fa3ac982 Add color support for an error status message 2014-09-11 09:13:04 -07:00
jason@truewheels.net 64ff1b8a35 Reset console mode for calls to external code
For an unknown reason - SetConsoleMode calls fail when setting certain
modes.  One such case is when PowerShell calls SetConsoleMode in it's
implementation of PSHostRawUserInterface.ReadKey.

PowerTab calls this method - and it's possible that other custom
key handlers might want to use that api, so I will reset the console
mode to what it was before calling PSReadline for the duration of
the external code (tab completion or custom handlers) and reset it
when the external code completes.

Fixes #125.
2014-07-17 08:51:43 -07:00
jason@truewheels.net 635207231e Remember script block for custom key bindings
For various reasons, we may need to know that a key binding
came from a script block so that is now saved in the key binding.
2014-07-16 08:28:27 -07:00
Jason Shirk a697c222f5 Fix tests for recent changes 2014-06-12 19:16:07 -07:00
Jason Shirk b3355eca5e Fix exception when setting history save path 2014-06-12 12:59:45 -07:00