Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF console app does not work #25

Open
AndrewBragdon opened this issue Nov 23, 2016 · 7 comments
Open

WPF console app does not work #25

AndrewBragdon opened this issue Nov 23, 2016 · 7 comments

Comments

@AndrewBragdon
Copy link

Great project! The WinForms version works fine, but the WPF version does not work (at least on Windows Server, which is where I am running it on). I am unable to type characters into the window / no input is accepted after starting the console connection.

Thoughts?

@gandalf1819
Copy link

WinForms is working perfectly fine but WPF version is not interacting with the shell. On giving any input, there is no output. Can you help?

@danielseis
Copy link

It gives the sensation that this project is abandoned.
in wpf you can not make any entry by keyboard. nor dir. nor launch any command.
If someone has solved it, I would appreciate the solution. Thank you

@adamecr
Copy link

adamecr commented Nov 5, 2018

I was looking for ideas how to "make" a WPF console for my project and ended up here - actually I do like the work Dave did, it's nice piece of code with good ideas behind. However I have had issues to make the WPF park working, so I have quite redesigned some parts to make it work.
If still somebody interesting in the WPF part, you can check the code within the project I use the console in. The important files for console WPF control are in
Console XAML part
ProcessWrapper (ProcessInterface here)
RichTextBox extensions used

@dwmkerr
Copy link
Owner

dwmkerr commented Nov 6, 2018

I will take a quick look when I get back home @adamecr! For some reasons I had notifications disabled for this project so I've not been keeping up to date with it. If I can get it working based on your input, are you OK for me to update the code in this repo then credit you as a contributor?

@adamecr
Copy link

adamecr commented Nov 9, 2018

Hello Dave @dwmkerr , I have found some issue with BackgroundWorker, I have a fix, but just finishing the release of other functionality of my VSIX, so I think, I'll upload the latest code during the weekend (I use the GitHub just as a public mirror of my release branches). Once it's done, I'll get back with more details what I have done to make the console working, so it will make the digging through the code easier.
Of course no problem with using my findings/code here.

@adamecr
Copy link

adamecr commented Nov 10, 2018

So I'm back to summarize the updates I have made to make the control working in WPF.
The key part was in ConsoleControl.xaml.cs:

  • RichTextbox's PreviewKeyDown event is to be used instead of KeyDown due to bubbling nature of WPF event routing.
  • I use the immutable inputStartPos to identify the end of read only zone. When it's assigned from Selection.Start, it just gets the reference and changes over the time. So I "measure" the position as integer ordinal from content start.

I think these two changes are crucial and the rest are just the improvements and/or adjustments:

  • StartProcess supports optional working directory definition (like request in issue #18)
  • I added the command history (Ctrl-Up, Ctrl-Down) to the console control.
  • Esc clears the current input.
  • I added the brushes for input, output, error and diagnostics as dependency properties of control, so they can be customized when using the control in XAML.
  • I handle IsInputEnabled in key handler rather then (re)setting the read only property on process start, so it can be changed dynamically when needed.
  • Console scrolls to the end when output is added. But be careful - this might be slow when there is a lot of content in the console (WPF version of issue #1).
  • I added handler disabling the selection drag-and-drop to protect the read only area.
  • I merged output and error processing/handler from backing process (see later). This is just simplification for me.

The updates to ProcessInterface (I call it ProcessWrapper) are not really game changers:

  • The StartProcess supports optional working directory definition.
  • The StartProcess doesn't start a new process when there is a process already running.
  • I don't split the output and error events as I do handle them the same way in control, so I rather use the IsError field in event data to signal type of the output.
  • I wanted to have the ability to restart (or start another) process in the process-exited handler, but this got me into the problems with asynchronous cancellation of the BackgroundWorkers processing the standard and error output - they have not been finished (cancelled) before the new process starts and I didn't want just to create a new instances of workers. So I have implemented BackgroundWorkerWithSyncCancel giving me better control over the workers. Not sure, but it might also help with issue #20

That's it, hope this helps... Should you have any questions, just raise the comment.

If you want to have a look into my version of code or use the console control itself, you need these files:
ConsoleControl.xaml
ConsoleControl.xaml.cs
RichTextBoxExtensions.cs
ProcessWrapper.cs
BackgroundWorkerWithSyncCancel.cs

@Buddha1996
Copy link

@danielseis found a solution, posted the fix in i a new Issue.. i know it has been a while since 2018..
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants